public void GamesFromDB_Test() { string gameInput; int expectedValue; bool causesException; gameInput = TestContext.DataRow["GameInput"].ToString(); expectedValue = Convert.ToInt32(TestContext.DataRow["ExpectedValue"]); causesException = Convert.ToBoolean(TestContext.DataRow["CausesException"]); TenPinsGame game = new TenPinsGame(); try { var actualValue = game.ShowScore(gameInput); Assert.AreEqual(expectedValue, actualValue, $"The Game: '{gameInput}', has following Actual Score: {actualValue}"); } catch (AssertFailedException ex) { throw ex; } catch (ArgumentNullException) { Assert.IsTrue(causesException); } }
public void TestsGameWithSpareOnTheFinalFrameAndOneBonusThrows() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|2/||8"; int expectedScore = 150; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameWithoutAnyBonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|2-||"; int expectedScore = 126; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameWhenEveryFrameHasOneMiss() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "9-|9-|9-|9-|9-|9-|9-|9-|9-|9-||"; int expectedScore = 90; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameInputWithWhiteSpaceBeforeFinalFrameDivider() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X ||81"; int expectedScore = 167; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameInputWithLeadingAndTrailingWhiteSpaces() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = " X|7/|9-|x|-8|8/|-6|x|X|X||81 "; int expectedScore = 167; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameZeroInsteadOfMissChar() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "90|9-|9-|9-|9-|9-|9-|9-|9-|90||"; int expectedScore = 90; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameWhenEveryFrameHasSpare() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "5/|5/|5/|5/|5/|5/|5/|5/|5/|5/||5"; int expectedScore = 150; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void TestsGameWhenEveryThrowIsStrike() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|X|x|x|x|x|x|x|X|X||xx"; int expectedScore = 300; //-- Act int actualScore = game.ShowScore(gameInput); //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public static void ScoreCommand(string gameInput) { try { TenPinsGame game = new TenPinsGame(); Console.WriteLine("Game: {0}", gameInput); Console.WriteLine("Score: " + game.ShowScore(gameInput)); Console.WriteLine("#=====#"); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } }
public void TestsFailedToShowScoreWhenInputIsEmpty() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = string.Empty; try { game.ShowScore(gameInput); } catch (ArgumentNullException) { return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithSpareOnTheFirstThrowOfTheFrame() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|//|9-|x|-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentOutOfRangeException ex) { return; } Assert.Fail("Call did NOT throw the ArgumentOutOfRangeException"); }
public void TestsFailedOnGameWithTooManyFrames() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|71|3-|9-|x|-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("You specified 11 frames, which is more than allowed # of 10. Please check your input.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedWithSpareOnTheFinalFrameAndTwoBonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9/||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("The number of bonus throws 2, is over allowed for the Last Spare. Please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWhenSpareSetOnBonusThrow() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||8/"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("The 'Spare' cannot be set on the Bonus Throws, please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithNoFrameDividersAtAll() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X;7/;9-;x;-8;8/;-6;x;X;X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("Your input does not have any frames devider '|'. Pls check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedWithSpareOnTheFinalFrameAndNoBonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9/||"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("You're missing the bonus points. Pls check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithAnEmptyFrame() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-||-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("The '||' divider can be only one per the input. Please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithFrameDividerInsteadOfFinalFrameDividerWithBonus() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X|81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("The frames data has to end with '||' (divider between frames and bonus throws). Please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithKnowckedDownPinsHigherThanStartingPins() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|92|x|-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("Your Knocked down Pins count of 11 is out of range for StartingPinsNumber of '10'. Please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedWithoutStrikeOrSpareOnTheFinalFrameButWithBonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9-||8"; try { game.ShowScore(gameInput); } catch (InvalidOperationException ex) { Assert.AreEqual("You're trying to add a Bonus, while it's not allowed based on your last throw. Pls. check.", ex.Message); return; } Assert.Fail("Call did NOT throw the InvalidOperationException"); }
public void TestsFailedOnGameWithTooLittleFrames() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|xX|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("You played 9 turns, which is less than required # of 10. Please check your input.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithTooLittleTrowsOnTheFrameAndFollowedByStrike() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9|x|-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("It looks you're missing a throw for the frame.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithTooManyThrowsForTheFrame() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|713|9-|x|-8|8/|-6|x|X|X||81"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("You have too many throws (3) for one (non-final) Frame. Pls check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedOnGameWithSpecialCharForTheThrow() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||8!"; try { game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("Invalid character '!' was detected in the provided input, please check.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailedWhenStartingPinsNumberIsZero() { //-- Arrange TenPinsGame game = new TenPinsGame(); string gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||81"; CommonGameData data; try { data = new CommonGameData(10, 0); game.ShowScore(gameInput); } catch (ArgumentException ex) { Assert.AreEqual("MaxFrameNumber and StartingPinsNumber has to be higher than 0.", ex.Message); return; } Assert.Fail("Call did NOT throw the Argument Exception"); }