Package primitiveTests

Source Code of primitiveTests.ClusterUtilsTest

package primitiveTests;

import static org.junit.Assert.*;

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

import primitives.cluster.ClusterLeaf;
import primitives.cluster.ClusterHead;
import primitives.cluster.IClusterLevel;
import primitives.cluster.ClusterNode;
import primitives.cluster.ClusterUtils;
import primitives.graph.Graph;
import primitives.graph.Node;

public class ClusterUtilsTest {
  ClusterNode c;
  Node outsideIn;
  Node outsideOut;
  Node a,b;
  IClusterLevel leaf1,leaf2,leaf3;
  ClusterNode body;
  ClusterHead head;
  Graph g;
  @Before
  public void setUp() throws Exception {
    c = new ClusterNode();
    a = new Node("a");
    b = new Node("b");
    g = new Graph();
    g.addNode(a);
    g.addNode(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 ");
    g.addNode(outsideIn);
    g.addNode(outsideOut);
   
    leaf1 = new ClusterLeaf();
    leaf2 = new ClusterLeaf();
    leaf3 = new ClusterLeaf();
    head = new ClusterHead(g);
    body = new ClusterNode();
   
    leaf1.addNode(b);

    leaf2.addNode(a);

    //head.addChild(body);
    //head.addChild(leaf1);
    body.addChild(leaf2);

    leaf3.addNode(outsideIn);
    body.addChild(leaf3);
    /*
     *     head
     *       body
     *         leaf1
     *         leaf2
     *         leaf3
     */
  }

  @Test
  public void testFindParent() {
   
   
    assertEquals(ClusterUtils.findParent(body, head),head);
    assertEquals(ClusterUtils.findParent(leaf3, head),body);
    assertEquals(ClusterUtils.findParent(head,leaf2), null);

  }

  @Test
  public void testMove() {
    assertFalse(body.getChildren().contains(leaf1));
  }
 
  @Test
  public void testNumbering(){
    ClusterUtils.prettyPrintTree(head);
    try{
      ClusterUtils.merge((ClusterNode) ClusterUtils.lookupIndexInTree(2, head), ClusterUtils.lookupIndexInTree(1, head), head);
     
    }catch(Exception e){
      e.printStackTrace();
    }
    ClusterUtils.prettyPrintTree(head);
    try{
      ClusterUtils.merge((ClusterNode) ClusterUtils.lookupIndexInTree(2, head), ClusterUtils.lookupIndexInTree(3, head), head);
     
    }catch(Exception e){
      e.printStackTrace();
    }
    ClusterUtils.prettyPrintTree(head);
  }

  @Test
  public void testValidTree() {
    fail("Not yet implemented");
  }

  @Test
  public void testLookup() {
    fail("Not yet implemented");
  }

  @Test
  public void testMerge() {
    fail("Not yet implemented");
  }

  @Test
  public void testSplit() {
    fail("Not yet implemented");
  }
 
  @Test
  public void testGetIDs(){
    System.out.println(ClusterUtils.getIDs(head));
  }
       
        @Test
        public void testIsCyclic(){
           
            ClusterNode a = new ClusterNode();
            ClusterNode b = new ClusterNode();
            ClusterNode c = new ClusterNode();
           
            a.addChild(b);
            b.addChild(c);
            c.addChild(b);
           
            assertTrue(ClusterUtils.isCyclic(a));
            assertTrue(ClusterUtils.isCyclic(b));
            assertTrue(ClusterUtils.isCyclic(c));
           
            assertFalse(ClusterUtils.isCyclic(new ClusterNode()));
           
        }
       

}
TOP

Related Classes of primitiveTests.ClusterUtilsTest

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.