我不确定为什么我的代码没有返回正确的路径顶点。它返回[a b c]而不是[a c f],我不知道为什么。我在这里是否遗漏了什么或在我的算法中做错了什么?注: getNeighbors(字符串顶点)在其参数中返回顶点的连接边。
这是测试:我的代码停止在“断言等式(”c“,route.next())”,因为它返回“b”而不是“c”。我的代码的当前输出是 [a b c],预期的是 [a c f]
public class PathingTest {
@Test
public void testPathing(){
Graph cycle = new Graph("graphs/cycle.json");
Iterator<String> route = cycle.getRoute("d", "b").iterator();
assertEquals("d",route.next());
assertEquals("b",route.next());
assertFalse(route.hasNext());
Graph tree = new Graph("graphs/tree.json");
route = tree.getRoute("a", "f").iterator();
assertEquals("a",route.next());
assertEquals("c", route.next());
assertEquals("f", route.next());
assertFalse(route.hasNext());
Graph disconnected = new Graph("graphs/disconnected.json");
assertEquals(null, disconnected.getRoute("a", "f"));
}
}
牧羊人nacy
相关分类