예제 #1
0
        private bool IsValidOne(string input)
        {
            var pwl   = new PasswordLine(input);
            var count = pwl.Password.Where(c => c == pwl.Letter).Count();

            return(count >= pwl.FirstNumber && count <= pwl.SecondNumber);
        }
예제 #2
0
        public bool IsValid(PasswordLine line)
        {
            var requiredCharCount = line.Password.Count(c => c == line.RequiredChar);

            // Lower and Upper bound are both inclusive.
            return(requiredCharCount >= line.LowerBound && requiredCharCount <= line.UpperBound);
        }
예제 #3
0
        public bool IsValid(PasswordLine line)
        {
            // Bounds are the positions, and are one-based indexes.
            var isAt1 = line.Password[line.LowerBound - 1] == line.RequiredChar;
            var isAt2 = line.Password[line.UpperBound - 1] == line.RequiredChar;

            return(isAt1 ^ isAt2);
        }
예제 #4
0
            public void ThrowsForInvalidInputs(string inputLine)
            {
                Action action = () => PasswordLine.Parse(inputLine);

                // ACT & ASSERT
                action.Should().Throw <InvalidOperationException>()
                .WithMessage("Invalid password line: " + inputLine);
            }
예제 #5
0
            public void ParsesValidInputs(
                string inputLine,
                int expectedLowerBound,
                int expectedUpperBound,
                char expectedRequiredChar,
                string expectedPassword)
            {
                // ACT
                var result = PasswordLine.Parse(inputLine);

                // ASSERT
                result.Should().BeEquivalentTo(
                    new PasswordLine(expectedLowerBound, expectedUpperBound, expectedRequiredChar, expectedPassword));
            }
예제 #6
0
        private bool IsValidTwo(string input)
        {
            var pwl = new PasswordLine(input);

            return(pwl.Password[pwl.FirstNumber - 1] == pwl.Letter ^ pwl.Password[pwl.SecondNumber - 1] == pwl.Letter);
        }