public void Test_GetShortestPath() { var cells = new Cell[,] { { new Cell("a"), new Cell("b"), new Cell("c") }, { new Cell("z"), new Cell("z"), new Cell("d") }, { new Cell("z"), new Cell("z"), new Cell("e") } }; var path = ShortestPath.GetShortestPath(cells, new Position(0, 0), new Position(2, 2)); var correct = new List<Position> { new Position(0,0), new Position(0,1), new Position(1,2), new Position(2,2), }; Assert.IsTrue(path.Select(o => o.x).SequenceEqual(correct.Select(o => o.x))); Assert.IsTrue(path.Select(o => o.y).SequenceEqual(correct.Select(o => o.y))); }
public void Test_Dijkstra() { var cells = new Cell[,] { { new Cell("a"), new Cell("b"), new Cell("c") }, { new Cell("z"), new Cell("z"), new Cell("d") }, { new Cell("z"), new Cell("z"), new Cell("e") } }; var path = ShortestPath.Dijkstra(cells, new Position(0, 0), new Position(2, 2)); var correct = new int[] { 0, 2, 4 , 26, 26, 5, int.MaxValue, 28, 7 }; var l1 = path.Cast<int>().ToList(); var l2 = correct.ToList(); Assert.IsTrue(l1.SequenceEqual(l2)); }
public void Test_Cell_Creation() { Cell a = new Cell("Test"); Assert.AreEqual(a.Value, (int)'t'); Assert.AreEqual(a.Text, "Test"); Cell b = new Cell("test"); Assert.AreEqual(b.Value, (int)'t'); Assert.AreEqual(b.Text, "test"); }
public void Test_Cell_Movecost() { Cell a = new Cell("Test"); Cell b = new Cell("test"); Assert.AreEqual(a.MoveCost(b), 0); a.Text = "bca"; b.Text = "abc"; Assert.AreEqual(a.MoveCost(b), 1); a.Text = "cab"; b.Text = "abc"; Assert.AreEqual(a.MoveCost(b), 2); a.Text = "aaa"; b.Text = "Zzz"; Assert.AreEqual(a.MoveCost(b), 25); }
/// <summary> /// Get a 2D array of the cell table, padded with 0-value cells /// </summary> /// <returns></returns> public Cell[,] GetTable() { Cell[,] table = new Cell[Width, Height]; for (int h = 0; h < Height; h++) for (int w = 0; w < Width; w++) { int i = w + h * Width; if (i >= _cells.Length) table[w, h] = new Cell(); else table[w, h] = _cells[i]; } return table; }
/// <summary> /// Splits text into cells /// </summary> /// <param name="Text">Text</param> /// <returns></returns> public static Cell[] GetCellArray(string Text) { string[] items = Text.Split(DELIMITER); Cell[] cells = new Cell[ items.Length ]; for (int i = 0; i < items.Length; i++) cells[i] = new Cell(items[i]); return cells; }