Beispiel #1
0
 private static void FindMax()
 {
     string[] lines = SelectFileAndReadLines();
     if (lines?.Length > 0)
     {
         var matrix = _parser.Build(lines);
         var route  = _solver.FindMax(matrix);
         if (route != null)
         {
             Output.WriteLine(ConsoleColor.Green, "Got MAX route");
             Output.WriteLine("{0} ({1})", String.Join(" -> ", route.Path), route.Sum);
         }
         else
         {
             Output.WriteLine(ConsoleColor.Red, "No route found.");
         }
     }
 }
Beispiel #2
0
        public void FindMax_CheckSum()
        {
            var tree = _parser.Build(new string[]
            {
                "1",
                "8 9",
                "1 5 9",
                "4 5 2 3",
            });

            var r = _solver.FindMax(tree);

            // Expecting: 1 -> 8 -> 5 -> 2 = 16
            r.Sum.Should().Be(16);
        }
Beispiel #3
0
        public void Build_Root()
        {
            var r = _parser.Build(new string[] { "1" });

            r.Data.Should().Be(1);
        }