package search.fitnessfunctions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import primitives.cluster.ClusterHead;
import primitives.cluster.ClusterNode;
import primitives.cluster.ClusterUtils;
import primitives.graph.Graph;
import primitives.graph.Node;
/**
*
* @author mat
*/
public class BunchTurboMQFitnessFunctionTest {
ClusterHead goodTree, badTree;
Graph g;
BunchTurboMQFitnessFunction goodInstance, badInstance;
public BunchTurboMQFitnessFunctionTest() {
}
@Before
public void setUp() {
Graph g = new Graph();
g.addNode(new Node("node 1"));
g.addNode(new Node("node 2"));
g.addNode(new Node("node 3"));
for(Node n : g.getNodes()){
for(Node n2 : g.getNodes()){
if(n != n2)
n.connect(n2, "");
}
}
goodTree = new ClusterHead();
for(Node n: g.getNodes()){
ClusterNode cn = new ClusterNode();
cn.addNode(n);
goodTree.addChild(cn);
}
badTree = new ClusterHead();
for(Node n: g.getNodes()){
ClusterNode cn = new ClusterNode();
cn.addNode(n);
badTree.addChild(cn);
}
ClusterNode dummy = new ClusterNode();
badTree.addChild(dummy);
goodInstance = new BunchTurboMQFitnessFunction();
badInstance = new BunchTurboMQFitnessFunction();
goodInstance.setTree(goodTree);
badInstance.setTree(badTree);
ClusterUtils.prettyPrintTree(badTree);
}
@After
public void tearDown() {
}
/**
* Test of setTree method, of class BunchTurboMQFitnessFunction.
*/
@Test
public void testSetTree() {
assertTrue("Good tree returns a fitness value", goodInstance.evaluate(goodTree) >= 0);
assertTrue("Bad tree returns a fitness value", badInstance.evaluate(badTree) >= 0);
assertEquals("Good tree and bad tree have same fitness value", goodInstance.evaluate(goodTree), badInstance.evaluate(badTree),0.000001);
}
}