public void TestParser(string input) { var parser = new InputParser(input.Split(",")); parser.Parse(); Assert.Single(parser.Roots); InputParser.Dump(parser.Roots.First(), console.WriteLine); }
public void TestGetPathToRoot(string input, string from, string expectedResult) { var parser = new InputParser(input.Split(",")); parser.Parse(); InputParser.Dump(parser.Roots.First(), console.WriteLine); var r = string.Join(",", InputParser.GetPathToRootSpatialObject(parser.AllObjects[from]).Select(x => x.Name)); Assert.Equal(expectedResult, r); }
public void TestCalcTransferCount(string input, string from, string to, int expectedResult) { var parser = new InputParser(input.Split(",")); parser.Parse(); InputParser.Dump(parser.Roots.First(), console.WriteLine); console.WriteLine(string.Join(",", InputParser.GetPathToRootSpatialObject(parser.AllObjects[from]).Select(x => x.Name))); console.WriteLine(string.Join(",", InputParser.GetPathToRootSpatialObject(parser.AllObjects[to]).Select(x => x.Name))); var(degenerative, n) = parser.CalculateOrbitalTransfersCount(parser.AllObjects[from], parser.AllObjects[to], console.WriteLine); if (degenerative) { console.WriteLine("Degenerative case"); } Assert.Equal(expectedResult, n); }
public void TestCalculateOrbits() { string input = @"COM)B,B)C,C)D,D)E,E)F,B)G,G)H,D)I,E)J,J)K,K)L"; var parser = new InputParser(input.Split(",")); parser.Parse(); Assert.Single(parser.Roots); InputParser.Dump(parser.Roots.First(), console.WriteLine); Assert.Equal(3, InputParser.CalculateDirectAndIndirectOrbits(parser.AllObjects["D"])); Assert.Equal(7, InputParser.CalculateDirectAndIndirectOrbits(parser.AllObjects["L"])); Assert.Equal(0, InputParser.CalculateDirectAndIndirectOrbits(parser.AllObjects["COM"])); var result = parser.AllObjects.Values.Sum(InputParser.CalculateDirectAndIndirectOrbits); Assert.Equal(42, result); }