Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. /* Copyright (c) 2015-2017 MIT 6.005/6.031 course staff, all rights reserved.
  2. * Redistribution of original or derived work requires permission of course staff.
  3. */
  4. package graph;
  5.  
  6. import static org.junit.Assert.*;
  7.  
  8. import org.junit.Test;
  9.  
  10. /**
  11. * Tests for ConcreteEdgesGraph.
  12. *
  13. * This class runs the GraphInstanceTest tests against ConcreteEdgesGraph, as
  14. * well as tests for that particular implementation.
  15. *
  16. * Tests against the Graph spec should be in GraphInstanceTest.
  17. */
  18. public class ConcreteEdgesGraphTest extends GraphInstanceTest {
  19.  
  20. /*
  21. * Provide a ConcreteEdgesGraph for tests in GraphInstanceTest.
  22. */
  23. @Override public Graph<String> emptyInstance() {
  24. return new ConcreteEdgesGraph<String>();
  25. }
  26.  
  27. /*
  28. * Testing ConcreteEdgesGraph...
  29. */
  30.  
  31. // Testing strategy for ConcreteEdgesGraph.toString()
  32. // vertices = empty, non-empty
  33. // edges = empty, non-empty
  34.  
  35. @Test
  36. public void testConcreteEdgesGraphToStringEmpty(){
  37. String expected = "vertices: [], edges: []";
  38. Graph<String> thisGraph = emptyInstance();
  39. assertEquals("no vertices or edges expected",expected, thisGraph.toString());
  40. }
  41.  
  42. @Test
  43. public void testConcreteEdgesGraphToStringSingleVertex(){
  44. String expected = "vertices: [a], edges: []";
  45.  
  46. Graph<String> thisGraph = emptyInstance();
  47. thisGraph.add("a");
  48. assertEquals("wrong string representation",expected, thisGraph.toString());
  49. }
  50.  
  51. @Test
  52. public void testConcreteEdgesGraphToStringTwoVerticesOneEdge(){
  53. String expected = "vertices: [a, b], edges: [(a,b,10)]";
  54.  
  55. Graph<String> thisGraph = emptyInstance();
  56. thisGraph.set("a","b",10);
  57. assertEquals("wrong string representation",expected, thisGraph.toString());
  58. }
  59.  
  60. @Test
  61. public void testConcreteEdgesGraphToStringTwoVerticesNoEdge(){
  62. String expected = "vertices: [a, b], edges: []";
  63.  
  64. Graph<String> thisGraph = emptyInstance();
  65. thisGraph.add("a");
  66. thisGraph.add("b");
  67. assertEquals("wrong string representation",expected, thisGraph.toString());
  68. }
  69.  
  70. @Test
  71. public void testConcreteEdgesGraphToStringFullGraph(){
  72. String expected = "vertices: [a, b, c, d], edges: [(a,b,10), (a,c,5), (d,c,12), (b,d,1)]";
  73. Graph<String> thisGraph = emptyInstance();
  74. thisGraph.set("a","b",10);
  75. thisGraph.set("a","c",5);
  76. thisGraph.set("d","c",12);
  77. thisGraph.set("b","d",1);
  78. assertEquals("wrong string representation",expected, thisGraph.toString());
  79. }
  80.  
  81.  
  82. /*
  83. * Testing Edge...
  84. */
  85.  
  86. // Testing strategy for Edge
  87. // toString():
  88. // - any edge covers all partitions
  89.  
  90. @Test
  91. public void testEdgeToString(){
  92. Edge<String> edge = new Edge<>("a","b",10);
  93. assertEquals("incorrect string", "(a,b,10)", edge.toString());
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement