-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from ProgrammingLife2016/test/test-model-classes
Add tests for the model classes
- Loading branch information
Showing
9 changed files
with
793 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
PL2/PL2-shared/src/test/java/nl/tudelft/pl2016gr2/model/AbstractNodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package nl.tudelft.pl2016gr2.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import nl.tudelft.pl2016gr2.thirdparty.testing.utility.AccessPrivate; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Tests the {@link AbstractNode} class. | ||
* | ||
* @author Wouter Smit | ||
*/ | ||
public class AbstractNodeTest { | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
||
private AbstractNode instance; | ||
|
||
/** | ||
* Sets up the abstract spied class. | ||
*/ | ||
@Before | ||
public void setUp() { | ||
instance = mock(AbstractNode.class); | ||
Mockito.when(instance.getId()).thenCallRealMethod(); | ||
Mockito.when(instance.hasChildren()).thenCallRealMethod(); | ||
Mockito.when(instance.getChildren()).thenCallRealMethod(); | ||
Mockito.when(instance.size()).thenCallRealMethod(); | ||
Mockito.when(instance.toString()).thenCallRealMethod(); | ||
Mockito.when(instance.getGenomesOverEdge(any())).thenCallRealMethod(); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
AbstractNode extendedNode = new SequenceNode(5); | ||
assertEquals(5, extendedNode.getId()); | ||
} | ||
|
||
@Test | ||
public void getId() { | ||
AccessPrivate.setFieldValue("id_field", AbstractNode.class, instance, 5); | ||
assertEquals(5, instance.getId()); | ||
} | ||
|
||
@Test | ||
public void hasChildren() { | ||
assertFalse(instance.hasChildren()); | ||
} | ||
|
||
@Test | ||
public void getChildren() { | ||
assertNull(instance.getChildren()); | ||
} | ||
|
||
@Test | ||
public void size() { | ||
Mockito.when(instance.getSequence()).thenReturn("ACTG"); | ||
assertEquals(4, instance.size()); | ||
} | ||
|
||
@Test | ||
public void getGenomesOverEdge() { | ||
GraphNode otherNode = mock(GraphNode.class); | ||
|
||
Mockito.when(otherNode.getId()).thenReturn(2); | ||
AccessPrivate.setFieldValue("id_field", AbstractNode.class, instance, 5); | ||
|
||
Mockito.when(instance.getGenomes()).thenReturn(Arrays.asList("equal", "gen0")); | ||
Mockito.when(otherNode.getGenomes()).thenReturn(Arrays.asList("equal", "gen1")); | ||
|
||
Mockito.when(otherNode.getInEdges()).thenReturn(Arrays.asList(1, 5, 8)); | ||
Mockito.when(instance.getOutEdges()).thenReturn(Arrays.asList(2, 10, 15)); | ||
|
||
assertTrue(instance.getGenomesOverEdge(otherNode).contains("equal")); | ||
assertEquals(1, instance.getGenomesOverEdge(otherNode).size()); | ||
} | ||
|
||
@Test | ||
public void getGenomesOverEdgeThrowsAssertionWhenNotSuccessor() { | ||
GraphNode otherNode = mock(GraphNode.class); | ||
|
||
Mockito.when(otherNode.getId()).thenReturn(2); | ||
AccessPrivate.setFieldValue("id_field", AbstractNode.class, instance, 5); | ||
|
||
Mockito.when(otherNode.getInEdges()).thenReturn(Arrays.asList(1, 8)); | ||
Mockito.when(instance.getOutEdges()).thenReturn(Arrays.asList(10, 15)); | ||
|
||
exception.expect(AssertionError.class); | ||
instance.getGenomesOverEdge(otherNode); | ||
} | ||
|
||
@Test | ||
public void testToString() { | ||
AccessPrivate.setFieldValue("id_field", AbstractNode.class, instance, 5); | ||
assertEquals("id: 5", instance.toString()); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
PL2/PL2-shared/src/test/java/nl/tudelft/pl2016gr2/model/HashGraphTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package nl.tudelft.pl2016gr2.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Tests the {@link HashGraph} class. | ||
* | ||
* @author Wouter Smit | ||
*/ | ||
public class HashGraphTest { | ||
private Map<Integer, GraphNode> nodes = new HashMap<>(); | ||
private Collection<String> genomes = new ArrayList<>(); | ||
|
||
/** | ||
* Sets up the graph structure with mocked nodes. | ||
*/ | ||
@Before | ||
public void setUp() { | ||
for (int i = 0; i < 5; i++) { | ||
nodes.put(i, SequenceGraphTest.mockNode(i, false)); | ||
} | ||
int rootId = 5; | ||
nodes.put(rootId, SequenceGraphTest.mockNode(rootId, true)); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
genomes.add("genome" + i); | ||
} | ||
} | ||
|
||
@Test | ||
public void testHashGraphConstructorForNodesAndGenomes() { | ||
HashGraph graph = new HashGraph(nodes, genomes); | ||
|
||
nodes.forEach((id, node) -> assertTrue(graph.contains(id))); | ||
assertTrue(graph.getGenomes().containsAll(genomes)); | ||
} | ||
|
||
@Test | ||
public void testHashGraphConstructorIncludingRootNodes() { | ||
Collection<Integer> rootNodes = new ArrayList<>(Arrays.asList(5, 10, 25)); | ||
HashGraph graph = new HashGraph(nodes, rootNodes, genomes); | ||
|
||
nodes.forEach((id, node) -> assertTrue(graph.contains(id))); | ||
assertTrue(graph.getGenomes().containsAll(genomes)); | ||
assertTrue(graph.getRootNodes().containsAll(rootNodes)); | ||
} | ||
|
||
@Test | ||
public void testToString() throws Exception { | ||
HashGraph graph = new HashGraph(); | ||
assertEquals("", graph.toString()); | ||
graph.add(SequenceGraphTest.mockNode(0, false)); | ||
assertNotNull(graph.toString()); | ||
} | ||
|
||
} |
93 changes: 47 additions & 46 deletions
93
PL2/PL2-shared/src/test/java/nl/tudelft/pl2016gr2/model/NodePositionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
//package nl.tudelft.pl2016gr2.model; | ||
// | ||
//import static org.junit.Assert.assertEquals; | ||
//import static org.junit.Assert.assertTrue; | ||
// | ||
//import org.junit.Before; | ||
//import org.junit.Test; | ||
// | ||
//import java.util.ArrayList; | ||
// | ||
//public class NodePositionTest { | ||
// | ||
// private NodePosition nodePosition; | ||
// private AbstractNode node; | ||
// | ||
// @Before | ||
// public void setup() { | ||
// this.node = new Node(5, 3, new ArrayList<String>(), 2); | ||
// this.nodePosition = new NodePosition(node, 6); | ||
// } | ||
// | ||
// @Test | ||
// public void offsetTest() { | ||
// nodePosition.addPositionOffset(4); | ||
// assertEquals(10, nodePosition.getLevel()); | ||
// } | ||
// | ||
// @Test | ||
// public void getNodeTest() { | ||
// assertEquals(node, nodePosition.getNode()); | ||
// } | ||
// | ||
// @Test | ||
// public void overlapTest() { | ||
// nodePosition.setOverlapping(true); | ||
// assertTrue(nodePosition.isOverlapping()); | ||
// } | ||
// | ||
// @Test | ||
// public void compareTest() { | ||
// AbstractNode other = new Node(5, 3, new ArrayList<String>(), 2); | ||
// NodePosition otherPosition = new NodePosition(other, 2); | ||
// assertEquals(4, nodePosition.compareTo(otherPosition)); | ||
// } | ||
// | ||
//} | ||
package nl.tudelft.pl2016gr2.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class NodePositionTest { | ||
|
||
private NodePosition nodePosition; | ||
private GraphNode node; | ||
|
||
@Before | ||
public void setup() { | ||
this.node = mock(GraphNode.class); | ||
this.nodePosition = new NodePosition(node, 6); | ||
} | ||
|
||
@Test | ||
public void offsetTest() { | ||
nodePosition.addPositionOffset(4); | ||
assertEquals(10, nodePosition.getLevel()); | ||
} | ||
|
||
@Test | ||
public void getNodeTest() { | ||
assertEquals(node, nodePosition.getNode()); | ||
} | ||
|
||
@Test | ||
public void overlapTest() { | ||
nodePosition.setOverlapping(true); | ||
assertTrue(nodePosition.isOverlapping()); | ||
} | ||
|
||
@Test | ||
public void compareTest() { | ||
GraphNode other = mock(GraphNode.class); | ||
NodePosition otherPosition = new NodePosition(other, 2); | ||
assertEquals(4, nodePosition.compareTo(otherPosition)); | ||
} | ||
|
||
} |
Oops, something went wrong.