static void Main(string[] args) { ShortestJumpRouteFinder generater1 = new ShortestJumpRouteFinder(GetJumpTable()); var routes = generater1.FindShortestJumpRoute(new Cell(0, 0)); foreach (var route in routes) { Console.WriteLine(route.ToString()); } }
public void TestFindShortestJumpRoute() { ShortestJumpRouteFinder generater1 = new ShortestJumpRouteFinder(GetTestTable1()); List <JumpRoute> routes1 = generater1.FindShortestJumpRoute(new Cell(0, 0)).ToList(); Assert.AreEqual(1, routes1.Count); Assert.AreEqual("0,0 2,1 0,2 1,4 3,3 4,1 2,0 1,2 0,4", routes1[0].ToString()); // 2×2 ShortestJumpRouteFinder generater2 = new ShortestJumpRouteFinder(GetTestTable2()); List <JumpRoute> routes2 = generater2.FindShortestJumpRoute(new Cell(0, 0)).ToList(); Assert.AreEqual(0, routes2.Count); Assert.AreEqual(1, generater2.GetRouteEnumerator.Count()); Assert.AreEqual("0,0", generater2.GetRouteEnumerator.ToList()[0].ToString()); // 2x3 ShortestJumpRouteFinder generater3 = new ShortestJumpRouteFinder(GetTestTable3()); List <JumpRoute> routes3 = generater3.FindShortestJumpRoute(new Cell(0, 0)).ToList(); Assert.AreEqual(1, routes3.Count); Assert.AreEqual("0,0 1,2", routes3[0].ToString()); // 3x4 ShortestJumpRouteFinder generater4 = new ShortestJumpRouteFinder(GetTestTable4()); List <JumpRoute> routes4 = generater4.FindShortestJumpRoute(new Cell(1, 0)).ToList(); Assert.AreEqual(1, routes4.Count); Assert.AreEqual("1,0 2,2 0,3 1,1 2,3 0,2 2,1 1,3 0,1 2,0", routes4[0].ToString()); // 2x2例外 ShortestJumpRouteFinder generater5 = new ShortestJumpRouteFinder(GetTestTable2()); bool hasException = false; try { generater5.FindShortestJumpRoute(new Cell(-1, 0)); } catch (JumpException ex) { Assert.AreEqual("有効なスタート場所ではありません。", ex.Message); hasException = true; } Assert.AreEqual(true, hasException); }