public void AddRole_1() { // Arrange var sut = new Game(); // Act sut.AddRoll(1); // Assert AssertGame(sut, "([1],1)", 1, false); }
public void AddRole_1_4() { // Arrange var sut = new Game(); // Act sut.AddRoll(1); sut.AddRoll(4); // Assert AssertGame(sut, "([1,4],5)", 5, false); }
public void Game_InitialValues() { // Arrange // Act var sut = new Game(); // Assert Assert.AreEqual(0, sut.TotalScore(), "TotalScore should be 0"); Assert.IsFalse(sut.Over()); Assert.AreEqual(10, sut.Frames().Length, "There should be 10 Frames"); }
public void AddRole_1_4_4_5() { // Arrange var sut = new Game(); // Act sut.AddRoll(1); sut.AddRoll(4); sut.AddRoll(4); sut.AddRoll(5); // Assert AssertGame(sut, "([1,4],5), ([4,5],9)", 14, false); }
private void AssertGame(Game actualGame, string expectedGame, int expectedTotalScore, bool expectedOver) { var frames = Regex.Matches(expectedGame, @"\(([^)]*)\)"); for (var frameIdx = 0; frameIdx < frames.Count; frameIdx++) { var frame = frames[frameIdx].Groups[0].Value; var pinsAndScore = Regex.Matches(frame, @"\d+"); for (int pinIdx = 0; pinIdx < pinsAndScore.Count - 1; pinIdx++) { Assert.AreEqual(pinsAndScore[pinIdx].Value, actualGame.Frames()[frameIdx].PinsRolled[pinIdx].ToString(), $"Frame: {frameIdx} PinsRolled: {pinIdx}"); } Assert.AreEqual(pinsAndScore[pinsAndScore.Count - 1].Value, actualGame.Frames()[frameIdx].Score.ToString(), $"Score in Frame: {frameIdx}"); } Assert.AreEqual(expectedTotalScore, actualGame.TotalScore(), "TotalScore"); Assert.AreEqual(expectedOver, actualGame.Over(), "Over"); }