Exemplo n.º 1
0
        public void Day02P01()
        {
            var expected = 474;
            var lines    = File.ReadLines("input.txt").ToArray();
            var actual   = 0;

            foreach (var line in lines)
            {
                var    passValueObject = PasswordValueObject.For(line);
                ushort counter         = 0;
                foreach (var c in passValueObject.PasswordValue)
                {
                    if (c == passValueObject.Character)
                    {
                        counter++;
                    }
                    if (counter > passValueObject.SecondPosition)
                    {
                        break;
                    }
                }

                if (counter <= passValueObject.SecondPosition && counter >= passValueObject.FirstPosition)
                {
                    actual++;
                }
            }

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void ImplicitConversionToStringResultsInCorrectString()
        {
            const string expected = "16-20 h: hhhjthhhtphchpkhmhhh";

            var actual = PasswordValueObject.For(expected);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void ToStringReturnsCorrectFormat()
        {
            const string expected = "16-20 h: hhhjthhhtphchpkhmhhh";

            var actual = PasswordValueObject.For(expected);

            Assert.Equal(expected, actual.ToString());
        }
Exemplo n.º 4
0
        public void ShouldHaveCorrectAddressParts()
        {
            var passValueObject = PasswordValueObject.For("16-20 h: hhhjthhhtphchpkhmhhh");

            Assert.Equal(expected: 16, actual: passValueObject.FirstPosition);
            Assert.Equal(20, passValueObject.SecondPosition);
            Assert.Equal('h', passValueObject.Character);
            Assert.Equal("hhhjthhhtphchpkhmhhh", passValueObject.PasswordValue);
        }
Exemplo n.º 5
0
        public void Day02P02()
        {
            var expected = 745;
            var lines    = File.ReadLines("input.txt").ToArray();
            var actual   = 0;

            foreach (var line in lines)
            {
                var passValueObject = PasswordValueObject.For(line);
                if ((passValueObject.Character == passValueObject.PasswordValue[passValueObject.FirstPosition - 1] &&
                     passValueObject.Character != passValueObject.PasswordValue[passValueObject.SecondPosition - 1]) ||
                    (passValueObject.Character != passValueObject.PasswordValue[passValueObject.FirstPosition - 1] &&
                     passValueObject.Character == passValueObject.PasswordValue[passValueObject.SecondPosition - 1]))
                {
                    actual++;
                }
            }

            Assert.Equal(expected, actual);
        }