Package primitiveTests

Source Code of primitiveTests.ClusterNodeTest

package primitiveTests;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;


import primitives.cluster.ClusterLeaf;
import primitives.cluster.IClusterLevel;
import primitives.cluster.ClusterNode;
import primitives.graph.Node;

public class ClusterNodeTest {

  ClusterNode c;
  Node outsideIn;
  Node outsideOut;
  Node a,b;
  @Before
  public void setUp() throws Exception {
    c = new ClusterNode();
    a = new Node("a");
    b = new Node("b");
    outsideIn = new Node("outside -> in ");
    outsideOut = new Node("cluster -> outside");
    c.addNode(a);
    c.addNode(b);
    outsideIn.connect(a," a ");
    b.connect(outsideOut, " b ");
  }
  @Test
  public void testGetNodes() {
    Set<Node> n = c.getNodes();
    for(Node node: n){
      assertFalse(node != a && node != b);
    }
    n.remove(a);
    assertTrue(c.contains(a));
  }


  @Test
  public void testClusterSetOfNode() {
    HashSet<Node> hs = new HashSet<Node>();
    hs.add(a); hs.add(b);
    c = new ClusterNode(hs);
    assertTrue(c.getNodes().contains(a));
    assertTrue(c.contains(a));
    hs.remove(a);
    hs.remove(b);
    assertFalse(c.getNodes().isEmpty());
  }

  @Test
  public void testEncapsulates() {
    assertTrue(c.encapsulates());
  }

  @Test
  public void testAddNode() {
    Node n = new Node("c");
    c.addNode(n);
    assertTrue(c.contains(n));
  }

  @Test
  public void testRemoveNode() {
    Node n = new Node("c");
    c.addNode(n);
    assertTrue(c.contains(n));

  }

  @Test
  public void testContains() {
    Node n = new Node ("c");
    assertFalse(c.contains(n));
    assertTrue(c.contains(a));
    assertTrue(c.contains(b));
    c.addNode(n);
    assertTrue(c.contains(n));
  }

  @Test
  public void testConnectivityTo() {
    assertTrue(c.connectivityTo(outsideOut));
  }

  @Test
  public void testConnectivityFrom() {
    assertTrue(c.connectivityFrom(outsideIn));
  }

  @Test
  public void testConnectivityBidir() {
    assertTrue(c.connectivityBidir(outsideIn));
    assertTrue(c.connectivityBidir(outsideOut));
  }

  @Test
  public void testGetCluster() {
    assertTrue(c.getNodes().contains(a));
    assertTrue(c.getNodes().contains(b));
  }

  @Test
  public void testTree(){
    IClusterLevel leaf1 = new ClusterLeaf();
    leaf1.addNode(b);
    ClusterLeaf leaf2 = new ClusterLeaf();
    leaf2.addNode(a);
    ClusterNode head = new ClusterNode();
    ClusterNode body = new ClusterNode();
    head.addChild(body);
    head.addChild(leaf1);
    body.addChild(leaf2);
    IClusterLevel leaf3 = new ClusterLeaf();
    leaf3.addNode(outsideIn);
    body.addChild(leaf3);
    assertTrue(head.contains(a));
    assertTrue(head.contains(b));
    assertTrue(head.contains(outsideIn));
    head.addNode(outsideOut);
    assertTrue(head.contains(outsideOut));
   
   
       
  }
 
  @Test
  public void testGetChildren(){
    assertFalse(c.getNodes().isEmpty());
    assertFalse(c.getChildren().isEmpty());
 
  }
 
}
TOP

Related Classes of primitiveTests.ClusterNodeTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.