Ejemplo n.º 1
0
        public override void Run()
        {
            Console.WriteLine("Day 4");
            var input = GetInput();

            var passphrases = input.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            Console.WriteLine("Part 1");
            var validator = new PassphraseValidator(new IValidationRule[] { new NoDuplicateWords() });
            var count     = 0;

            foreach (var passphrase in passphrases)
            {
                if (validator.IsValid(passphrase))
                {
                    count++;
                }
            }

            Console.WriteLine(count);

            Console.WriteLine("Part 2");
            validator = new PassphraseValidator(new IValidationRule[] { new NoAnagrams() });
            count     = 0;
            foreach (var passphrase in passphrases)
            {
                if (validator.IsValid(passphrase))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
        public void CheckInvalidPassphrases(string input)
        {
            // Act
            var result = PassphraseValidator.IsValid(input);

            // Assert
            Assert.IsFalse(result);
        }
        public void CheckValidPassphrasesUsingLegacy(string input)
        {
            // Act
            var result = PassphraseValidator.IsValid(input, true);

            // Assert
            Assert.IsTrue(result);
        }