public void PlayerLosesAfter20Tries() { Mastermind mastermind = new Mastermind(); mastermind.SetColorSelection(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple); Response[] response = new Response[5]; Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION }; bool gameWon = false; int roundCount = 0; for (int i = 0; i < 20 && !gameWon; i++) { roundCount = i + 1; response = mastermind.Guess(Colors.Orange, Colors.Gray, Colors.White, Colors.Yellow, Colors.Black); if (response == expected) { gameWon = true; } } Assert.True(!gameWon && (roundCount == 20)); }
public void Should_not_return_any_matches_when_there_is_no_matches() { var mastermind = new Mastermind("r r r r"); var result = mastermind.Guess("b b b b"); result.ShouldEqual(string.Empty); }
public void Should_not_match_pegs_more_than_once() { var mastermind = new Mastermind("r y y y"); var result = mastermind.Guess("g r r r"); result.ShouldEqual("m"); }
public void Should_not_include_partial_matches_if_the_color_is_already_matched_in_spesific_position() { var mastermind = new Mastermind("r r r y"); var result = mastermind.Guess("b b y y"); result.ShouldEqual("p"); }
public void Should_return_a_specific_match_if_a_match_is_in_correct_location() { var mastermind = new Mastermind("r r r y"); var result = mastermind.Guess("b b b y"); result.ShouldEqual("p"); }
public void Should_return_only_p_when_guess_is_correct() { var mastermind = new Mastermind("r r r y"); var result = mastermind.Guess("r r r y"); result.ShouldEqual("pppp"); }
public void Should_return_several_matches_if_there_are_sevral_matches_in_wrong_location() { var mastermind = new Mastermind("r r y y"); var result = mastermind.Guess("b b r r"); result.ShouldEqual("mm"); }
public void Should_return_a_match_if_there_is_a_match_in_wrong_location() { var mastermind = new Mastermind("r y y y"); var result = mastermind.Guess("b r b b"); result.ShouldEqual("m"); }
public void ShouldNotMatchAnyPlayerGuesses() { Mastermind mastermind = new Mastermind(); mastermind.SetColorSelection(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple); Response[] response = mastermind.Guess(Colors.Orange, Colors.Gray, Colors.White, Colors.Yellow, Colors.Black); Assert.False(response.All <Response>(r => r == Response.MATCH_POSITION)); }
public void Guess_ThrowsIfAttemptedAfterGameWon() { // Arrange var underTest = new Mastermind(new int[] { 1, 2, 3, 4 }); underTest.Guess("1234"); // Act/Assert underTest.Invoking(x => x.Guess("1234")).Should().Throw <InvalidOperationException>(); }
public void PlayerWinsAfter5Tries() { Mastermind mastermind = new Mastermind(); mastermind.SetColorSelection(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple); Response[] response = new Response[5]; Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION }; bool gameWon = false; int roundCount = 0; for (int i = 0; i < 20 && !gameWon; i++) { roundCount = i + 1; if (roundCount == 5) { response = mastermind.Guess(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple); } else { response = mastermind.Guess(Colors.Orange, Colors.Gray, Colors.White, Colors.Yellow, Colors.Black); } bool allMatch = true; for (int j = 0; j < 5 && allMatch; j++) { if (response[j] != expected[j]) { allMatch = false; } } if (allMatch) { gameWon = true; } } Assert.True(gameWon && (roundCount == 5)); }
public void Guess_WithCorrectSolution_EndsGame() { // Arrange var underTest = new Mastermind(new int[] { 1, 2, 3, 4 }); // Act underTest.Guess("1234"); // Assert underTest.IsComplete.Should().BeTrue(); }
public void MatchesGuessCorrectly([Range(1, 6)] int first, [Range(1, 6)] int second, [Range(1, 6)] int third, [Range(1, 6)] int fourth) { // Arrange var underTest = new Mastermind(new int[] { first, second, third, fourth }); // Act var result = underTest.Guess($"{first}{second}{third}{fourth}"); // Assert result.Result.Should().BeTrue(); }
public void Guess_DecrementsGuessesRemaining() { // Arrange var underTest = new Mastermind(new int[] { 1, 2, 3, 4 }); // Act underTest.Guess("1231"); // Assert underTest.GuessesRemaining.Should().Be(9); }
private void HintTestBody(int[] solution, string guess, string expectedHint, bool expectedResult = false) { // Arrange var underTest = new Mastermind(solution); // Act var(result, hint) = underTest.Guess(guess); // Assert result.Should().Be(expectedResult); hint.Should().Be(expectedHint); }
public void Guess_ThrowsIfAttemptedAfterGameLost() { // Arrange var underTest = new Mastermind(new int[] { 1, 2, 3, 4 }); for (int i = 0; i < 10; i++) { underTest.Guess("1111"); } // Act/Assert underTest.Invoking(x => x.Guess("1111")).Should().Throw <InvalidOperationException>(); }
public void OnlyFourGuesses() { Mastermind mastermind = new Mastermind(); Colors[] selectedColors = new Colors[5] { Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Red }; mastermind.SetColorSelection(selectedColors); Response[] response = mastermind.Guess(Colors.Red, Colors.Gray, Colors.Yellow, Colors.Orange); Response[] expected = new Response[] { Response.MATCH_POSITION, Response.NO_MATCH, Response.NO_MATCH, Response.NO_MATCH, Response.NO_MATCH }; Assert.AreEqual(expected, response); }
public void ShouldMatchPlayerFiveGuesses() { Mastermind mastermind = new Mastermind(); Colors[] selectedColors = new Colors[5] { Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple }; mastermind.SetColorSelection(selectedColors); Response[] response = mastermind.Guess(selectedColors); Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION }; Assert.AreEqual(expected, response); }
public void Guess_DoesNotEndGameUntilTenthIncorrectAttempt() { // Arrange Mastermind underTest1 = new Mastermind(new int[] { 1, 2, 3, 4 }), underTest2 = new Mastermind(new int[] { 2, 3, 4, 5 }); for (int i = 0; i < 9; i++) { underTest1.Guess("1111"); } // Act for (int i = 0; i < 9; i++) { underTest2.Guess("1111"); } underTest1.Guess("1111"); // Assert underTest1.IsComplete.Should().BeTrue(); underTest2.IsComplete.Should().BeFalse(); }
public void MatchAllColorsWrongPositions() { Mastermind mastermind = new Mastermind(); Colors[] selectedColors = new Colors[5] { Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple }; mastermind.SetColorSelection(selectedColors); Response[] response = mastermind.Guess(Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple, Colors.Red); Response[] expected = new Response[] { Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR }; Assert.AreEqual(expected, response); }
public void Match2Positions2Colors() { Mastermind mastermind = new Mastermind(); Colors[] selectedColors = new Colors[5] { Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple }; mastermind.SetColorSelection(selectedColors); Response[] response = mastermind.Guess(Colors.Red, Colors.Green, Colors.Pink, Colors.Black, Colors.Purple); Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.NO_MATCH, Response.MATCH_POSITION }; Assert.AreEqual(expected, response); }
public void SameColorTwiceOnePositionIsCorrectBothColorsCorrect() { Mastermind mastermind = new Mastermind(); Colors[] selectedColors = new Colors[5] { Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Red }; mastermind.SetColorSelection(selectedColors); Response[] response = mastermind.Guess(Colors.Gray, Colors.Red, Colors.Yellow, Colors.Orange, Colors.Red); Response[] expected = new Response[] { Response.NO_MATCH, Response.MATCH_COLOR, Response.NO_MATCH, Response.NO_MATCH, Response.MATCH_POSITION }; Assert.AreEqual(expected, response); }