コード例 #1
0
ファイル: CrabCombat.cs プロジェクト: Courtland9777/AoC_2020
        private static IList <Deck> GetDay22Input()
        {
            var path = $"{SD.Path}22{SD.Ext}";

            if (!File.Exists(path))
            {
                throw new Exception($"Cannot locate file {path}");
            }

            var inputLines = File.ReadAllLines(path);

            return(DeckHelper.ParseInputLines(inputLines));
        }
コード例 #2
0
        public void ParseInputLinesTest()
        {
            var testData = new List <Tuple <IList <string>, IList <IList <int> > > >()
            {
                new Tuple <IList <string>, IList <IList <int> > >(
                    new List <string>()
                {
                    "Player 1:",
                    "9",
                    "2",
                    "6",
                    "3",
                    "1",
                    "",
                    "Player 2:",
                    "5",
                    "8",
                    "4",
                    "7",
                    "10"
                },
                    new List <IList <int> >()
                {
                    new List <int>()
                    {
                        9, 2, 6, 3, 1
                    },
                    new List <int>()
                    {
                        5, 8, 4, 7, 10
                    }
                })
            };

            foreach (var testExample in testData)
            {
                var actual   = DeckHelper.ParseInputLines(testExample.Item1);
                var areEqual = (actual.Count == testExample.Item2.Count) &&
                               !actual.Where(actualDeck => !testExample.Item2
                                             .Where(expectedDeck =>
                                                    actualDeck.SpaceCards.Count == expectedDeck.Count &&
                                                    actualDeck.SpaceCards.ToList().All(
                                                        actualCard => expectedDeck.Contains(actualCard)))
                                             .Any())
                               .Any();
                Assert.True(areEqual);
            }
        }
コード例 #3
0
        public void TryPlayGameTest()
        {
            var testData = new List <Tuple <IList <string>, bool, bool, Deck> >()
            {
                new Tuple <IList <string>, bool, bool, Deck>(
                    new List <string>()
                {
                    "Player 1:",
                    "9",
                    "2",
                    "6",
                    "3",
                    "1",
                    "",
                    "Player 2:",
                    "5",
                    "8",
                    "4",
                    "7",
                    "10"
                },
                    false,
                    true,
                    new Deck("Player 2", new List <int>()
                {
                    3, 2, 10, 6, 8, 5, 9, 4, 7, 1
                })),
                new Tuple <IList <string>, bool, bool, Deck>(
                    new List <string>()
                {
                    "Player 1:",
                    "9",
                    "2",
                    "6",
                    "3",
                    "1",
                    "",
                    "Player 2:",
                    "5",
                    "8",
                    "4",
                    "7",
                    "10"
                },
                    true,
                    true,
                    new Deck("Player 2", new List <int>()
                {
                    7, 5, 6, 2, 4, 1, 10, 8, 9, 3
                }))
            };

            foreach (var testExample in testData)
            {
                var decks        = DeckHelper.ParseInputLines(testExample.Item1);
                var isSuccessful = CombatHelper.TryPlayGame(decks, testExample.Item2, out Deck winner);
                Assert.Equal(testExample.Item3, isSuccessful);
                Assert.NotNull(winner);
                Assert.Equal(testExample.Item4.PlayerName, winner.PlayerName);
                Assert.Equal(testExample.Item4.SpaceCards, winner.SpaceCards);
            }
        }