Browse Source

Fix Path.size() and add test for Path.size().

Mikaël Capelle 6 years ago
parent
commit
e2d1d47beb
2 changed files with 11 additions and 1 deletions
  1. 1
    1
      src/main/org/insa/graph/Path.java
  2. 10
    0
      src/test/org/insa/graph/PathTest.java

+ 1
- 1
src/main/org/insa/graph/Path.java View File

@@ -176,7 +176,7 @@ public class Path {
176 176
      * @return Number of nodes in this path.
177 177
      */
178 178
     public int size() {
179
-        return 1 + this.arcs.size();
179
+        return isEmpty() ? 0 : 1 + this.arcs.size();
180 180
     }
181 181
 
182 182
     /**

+ 10
- 0
src/test/org/insa/graph/PathTest.java View File

@@ -93,6 +93,16 @@ public class PathTest {
93 93
         assertFalse(longLoopPath.isEmpty());
94 94
         assertFalse(invalidPath.isEmpty());
95 95
     }
96
+    
97
+    @Test
98
+    public void testSize() {
99
+        assertEquals(emptyPath.size(), 0);
100
+        assertEquals(singleNodePath.size(), 1);
101
+        assertEquals(shortPath.size(), 4);
102
+        assertEquals(longPath.size(), 5);
103
+        assertEquals(loopPath.size(), 5);
104
+        assertEquals(longLoopPath.size(), 10);
105
+    }
96 106
 
97 107
     @Test
98 108
     public void testIsValid() {

Loading…
Cancel
Save