private static void RandomTestA(Random rand) { int lines = 2; int nodeCount = rand.Next(1, 20); int min = 1; int max = 100000; long[] enter = new long[lines]; long[] exit = new long[lines]; long[,] stationCost = new long[lines, nodeCount]; long[,] switchCost = new long[lines, nodeCount - 1]; for (int i = 0; i < lines; i++) { enter[i] = rand.Next(min, max); exit[i] = rand.Next(min, max); for (int j = 0; j < nodeCount; j++) { stationCost[i, j] = rand.Next(min, max); if (j < nodeCount - 1) { switchCost[i, j] = rand.Next(min, max); } } } AssemblyLineProblem target = new AssemblyLineProblem(); target.Enter = enter; target.Exit = exit; target.StationCost = stationCost; target.SwitchCost = switchCost; WriteInput(target); target.Solve(true); long expectedTime = target.MinTime; WritePath(target); target.Solve(false); long actualTime = target.MinTime; WritePath(target); Console.WriteLine("Expected = " + expectedTime.ToString()); Console.WriteLine("Actual = " + actualTime.ToString()); Assert.AreEqual(expectedTime, actualTime); }
private static void WritePath(AssemblyLineProblem target) { StringBuilder sb = new StringBuilder(); target.Path.Aggregate <int, StringBuilder>(sb, (s, i) => { s.Append(","); s.Append(i.ToString()); return(s); }); Console.WriteLine(sb.ToString()); }
private static void Solve(long[] enter, long[] exit, long[,] stationCost, long[,] switchCost, long expectedTime, int[] expectedPath) { AssemblyLineProblem target = new AssemblyLineProblem(); target.Enter = enter; target.Exit = exit; target.StationCost = stationCost; target.SwitchCost = switchCost; target.Solve(false); Assert.AreEqual(expectedTime, target.MinTime); //CollectionAssert.AreEqual(expectedPath, target.Path); }
private static void WriteInput(AssemblyLineProblem target) { StringBuilder sb = new StringBuilder(); sb.Append("Enter"); target.Enter.Aggregate <long, StringBuilder>(sb, (s, i) => { s.Append(","); s.Append(i.ToString()); return(s); }); sb.AppendLine(); sb.Append("Exit"); target.Exit.Aggregate <long, StringBuilder>(sb, (s, i) => { s.Append(","); s.Append(i.ToString()); return(s); }); sb.AppendLine(); Console.WriteLine(sb.ToString()); Console.Write("StationCost"); for (int i = 0; i < target.StationCost.GetLength(0); i++) { for (int j = 0; j < target.StationCost.GetLength(1); j++) { Console.Write(target.StationCost[i, j].ToString() + ","); } Console.WriteLine(); } Console.Write("switchCost"); for (int i = 0; i < target.SwitchCost.GetLength(0); i++) { for (int j = 0; j < target.SwitchCost.GetLength(1); j++) { Console.Write(target.SwitchCost[i, j].ToString() + ","); } Console.WriteLine(); } }
public void RandomTestFailed() { long[] enter = new long[] { 10, 20 }; long[] exit = new long[] { 24, 5 }; long[,] stationCost = new long[, ] { { 10, 20, 7, 38, 8, 9 }, { 11, 2, 34, 52, 9, 10 } }; long[,] switchCost = new long[, ] { { 2, 5, 100, 2, 88 }, { 89, 23, 1, 23, 94 }, }; AssemblyLineProblem target = new AssemblyLineProblem(); target.Enter = enter; target.Exit = exit; target.StationCost = stationCost; target.SwitchCost = switchCost; target.Solve(true); long expectedTime = target.MinTime; WritePath(target); target.Solve(false); long actualTime = target.MinTime; WritePath(target); Assert.AreEqual(expectedTime, actualTime); }