Пример #1
0
        public void GetTotalNumberOfOrbitsTest()
        {
            // Test examples taken from https://adventofcode.com/2019/day/6
            // COM)B
            // B)C
            // C)D
            // D)E
            // E)F
            // B)G
            // G)H
            // D)I
            // E)J
            // J)K
            // K)L
            // The total number of direct and indirect orbits in this example is 42.
            var testData = new List <Tuple <string[], int> >(new Tuple <string[], int>[] {
                new Tuple <string[], int>(new string[] { "COM)B", "B)C", "C)D", "D)E", "E)F", "B)G", "G)H", "D)I", "E)J", "J)K", "K)L" }, 42)
            });

            foreach (var testExample in testData)
            {
                var orbitalMap     = Day06.ConstructOrbitMap(testExample.Item1);
                var numberOfOrbits = Day06.GetTotalNumberOfOrbits(orbitalMap);
                Assert.Equal(testExample.Item2, numberOfOrbits);
            }
        }
Пример #2
0
        public void GetNumberOfOrbitalTransfersTest()
        {
            // Test examples found here:
            // https://adventofcode.com/2019/day/6#part2
            // COM)B
            // B)C
            // C)D
            // D)E
            // E)F
            // B)G
            // G)H
            // D)I
            // E)J
            // J)K
            // K)L
            // K)YOU
            // I)SAN
            // In this example, YOU are in orbit around K, and SAN is in orbit
            // around I. To move from K to I, a minimum of 4 orbital transfers
            // are required:
            // K to J
            // J to E
            //E to D
            //D to I
            var testData = new List <Tuple <string[], int> >(new Tuple <string[], int>[] {
                new Tuple <string[], int>(new string[] {
                    "COM)B",
                    "B)C",
                    "C)D",
                    "D)E",
                    "E)F",
                    "B)G",
                    "G)H",
                    "D)I",
                    "E)J",
                    "J)K",
                    "K)L",
                    "K)YOU",
                    "I)SAN"
                }, 4)
            });

            foreach (var testExample in testData)
            {
                var orbitalMap     = Day06.ConstructOrbitMap(testExample.Item1);
                var numberOfOrbits = Day06.GetNumberOfOrbitalTransfers("YOU", "SAN", orbitalMap);
                Assert.Equal(testExample.Item2, numberOfOrbits);
            }
        }