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); }
public void ImplicitConversionToStringResultsInCorrectString() { const string expected = "16-20 h: hhhjthhhtphchpkhmhhh"; var actual = PasswordValueObject.For(expected); Assert.Equal(expected, actual); }
public void ToStringReturnsCorrectFormat() { const string expected = "16-20 h: hhhjthhhtphchpkhmhhh"; var actual = PasswordValueObject.For(expected); Assert.Equal(expected, actual.ToString()); }
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); }
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); }