Example #1
0
            public void Should_parse_example_policies(
                string policyString,
                int expectedPos1,
                int expectedPos2,
                char expectedChar)
            {
                var policy = PasswordPolicy2.Parse(policyString);

                Assert.Equal(expectedPos1, policy.Pos1);
                Assert.Equal(expectedPos2, policy.Pos2);
                Assert.Equal(expectedChar, policy.Char);
            }
Example #2
0
            public void Puzzle_2B()
            {
                var inputs = PuzzleInputs.Puzzle2;

                var okPasswords = new ConcurrentBag <int>();

                Parallel.ForEach(inputs, input =>
                {
                    var parts  = input.Split(':');
                    var policy = PasswordPolicy2.Parse(parts[0]);
                    if (policy.Evaluate(parts[1].Trim()))
                    {
                        okPasswords.Add(1);
                    }
                });

                Assert.Equal(0, okPasswords.Sum());
            }