Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Copyright (c) 2015-2017 MIT 6.005/6.031 course staff, all rights reserved.
- * Redistribution of original or derived work requires permission of course staff.
- */
- package graph;
- import static org.junit.Assert.*;
- import org.junit.Test;
- /**
- * Tests for ConcreteEdgesGraph.
- *
- * This class runs the GraphInstanceTest tests against ConcreteEdgesGraph, as
- * well as tests for that particular implementation.
- *
- * Tests against the Graph spec should be in GraphInstanceTest.
- */
- public class ConcreteEdgesGraphTest extends GraphInstanceTest {
- /*
- * Provide a ConcreteEdgesGraph for tests in GraphInstanceTest.
- */
- @Override public Graph<String> emptyInstance() {
- return new ConcreteEdgesGraph<String>();
- }
- /*
- * Testing ConcreteEdgesGraph...
- */
- // Testing strategy for ConcreteEdgesGraph.toString()
- // vertices = empty, non-empty
- // edges = empty, non-empty
- @Test
- public void testConcreteEdgesGraphToStringEmpty(){
- String expected = "vertices: [], edges: []";
- Graph<String> thisGraph = emptyInstance();
- assertEquals("no vertices or edges expected",expected, thisGraph.toString());
- }
- @Test
- public void testConcreteEdgesGraphToStringSingleVertex(){
- String expected = "vertices: [a], edges: []";
- Graph<String> thisGraph = emptyInstance();
- thisGraph.add("a");
- assertEquals("wrong string representation",expected, thisGraph.toString());
- }
- @Test
- public void testConcreteEdgesGraphToStringTwoVerticesOneEdge(){
- String expected = "vertices: [a, b], edges: [(a,b,10)]";
- Graph<String> thisGraph = emptyInstance();
- thisGraph.set("a","b",10);
- assertEquals("wrong string representation",expected, thisGraph.toString());
- }
- @Test
- public void testConcreteEdgesGraphToStringTwoVerticesNoEdge(){
- String expected = "vertices: [a, b], edges: []";
- Graph<String> thisGraph = emptyInstance();
- thisGraph.add("a");
- thisGraph.add("b");
- assertEquals("wrong string representation",expected, thisGraph.toString());
- }
- @Test
- public void testConcreteEdgesGraphToStringFullGraph(){
- String expected = "vertices: [a, b, c, d], edges: [(a,b,10), (a,c,5), (d,c,12), (b,d,1)]";
- Graph<String> thisGraph = emptyInstance();
- thisGraph.set("a","b",10);
- thisGraph.set("a","c",5);
- thisGraph.set("d","c",12);
- thisGraph.set("b","d",1);
- assertEquals("wrong string representation",expected, thisGraph.toString());
- }
- /*
- * Testing Edge...
- */
- // Testing strategy for Edge
- // toString():
- // - any edge covers all partitions
- @Test
- public void testEdgeToString(){
- Edge<String> edge = new Edge<>("a","b",10);
- assertEquals("incorrect string", "(a,b,10)", edge.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement