public void Test_Game_With_Three_Throws_Spare() { //-- Arrange TenPinsGame game = new TenPinsGame(); var intInputList = new [] { 1, 9, 5 }; int expectedScore = 15; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_Single_Miss_On_Every_Frame_NoBonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("9, 0, 9,0, 9,0,9, 0, 9, 0, 9, 0, 9,0 , 9,0, 9,0, 9,0"); int expectedScore = 90; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Almost_Perfect_Game_Complete_With_Spare_On_Every_Frame() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5"); int expectedScore = 150; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_Only_Strike_On_Last_Frame_And_Two_Single_Bonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10, 1, 1"); int expectedScore = 12; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Perfect_Game_Complete() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("10,10,10,10,10,10,10,10,10,10,10,10"); int expectedScore = 300; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_All_Misses_But_With_Last_FivePins() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,5 "); int expectedScore = 5; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_Factorial_Increments_On_Every_Frame() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,8, 0,9, 0,10, 0 "); int expectedScore = 55; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_With_Four_Throws_Three_Strike_And_Miss() { //-- Arrange TenPinsGame game = new TenPinsGame(); var intInputList = new [] { 10, 10, 10, 0 }; int expectedScore = 50; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_All_Misses_But_With_Last_FivePins() { //-- Arrange TenPinsGame game = new TenPinsGame(); var intInputList = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5 }; int expectedScore = 5; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_Complete_With_Just_One_Spare_And_Single_One() { //-- Arrange TenPinsGame game = new TenPinsGame(); var intInputList = new [] { 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int expectedScore = 12; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Game_With_Two_Throws_Spare() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("1, 9"); int expectedScore = 0; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
public void Test_Regular_Game_Complete_With_Bonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1"); int expectedScore = 167; int actualScore = 0; //-- Act foreach (var input in intInputList) { actualScore = game.Bowl(input); } //-- Assert Assert.AreEqual(expectedScore, actualScore); }
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"); }
public void Test_Intermittent_Score_Till_RegularGameComplete_With_Bonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1"); List <int> expectedScoresList = new List <int> { 0, 0, 20, 39, 48, 48, 48, 74, 74, 74, 84, 90, 90, 90, 120, 148, 167 }; var inputValuesAndExpectedScores = intInputList.Zip(expectedScoresList, (kickedPins, correspondingExpectedScore) => (kickedPins, correspondingExpectedScore)); int actualScore = 0; //-- Act foreach (var input in inputValuesAndExpectedScores) { actualScore = game.Bowl(input.kickedPins); //-- Assert Assert.AreEqual(input.correspondingExpectedScore, actualScore); } }
public void TestsFailed_OnGame_With_Letter_Instead_Of_Integer() { //-- Arrange TenPinsGame game = new TenPinsGame(); //-- Act try { var input = "O"; game.Bowl(Convert.ToInt32(input)); } catch (FormatException ex) { Assert.AreEqual("Input string was not in a correct format.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestFailed_OnGame_KickedPinsInput_OutOfRange_AboveMax() { //-- Arrange TenPinsGame game = new TenPinsGame(); var kickedPinsCount = 11; var startingPinsNumber = ConstTenPinsGameData.StartingPinsNumber; //-- Act try { game.Bowl(kickedPinsCount); } catch (ArgumentException ex) { Assert.AreEqual($"The kicked pins count is '{kickedPinsCount}', but has to be between 0 and {startingPinsNumber}. Pls check.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestFailed_OnGame_With_Empty_Value() { //-- Arrange //-- Act try { TenPinsGame game = new TenPinsGame("0,"); foreach (var input in game.ListOfKickedPins) { game.Bowl(input); } } catch (FormatException ex) { return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestFailed_OnGame_Complete_With_Last_Spare_And_Excessive_Bonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); for (int i = 0; i < 9; i++) { //bowl 1 for each ball in a frame game.Bowl(1); game.Bowl(1); } //10th frame spare and bonus game.Bowl(1); game.Bowl(9); game.Bowl(2); //extra bonus Action action = () => game.Bowl(1); action.Should().Throw <Exception>(); }
public void TestFailed_OnGame_With_Negative_Value() { //-- Arrange TenPinsGame game = new TenPinsGame("0,-1, 0"); //-- Act try { foreach (var input in game.ListOfKickedPins) { game.Bowl(input); } } catch (ArgumentException ex) { Assert.AreEqual("The kicked pins count is '-1', but has to be between 0 and 10. Pls check.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestFailed_OnGame_Complete_With_No_Misses_But_OutOfRange_Throws_Sum() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6"); //-- Act try { foreach (var input in intInputList) { game.Bowl(input); } } catch (ArgumentException ex) { Assert.AreEqual("The 2nd throw pins of 6 is higher than allowed for this frame. Pls check.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestFailed_OnGame_Complete_With_No_Misses_And_Two_Bonuses() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1, 2"); //-- Act try { foreach (var input in intInputList) { game.Bowl(input); } } catch (ArgumentException ex) { Assert.AreEqual("Sorry, you have played All available bowl-throws for this game. Pls start a new game.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public void TestsFailed_OnGame_With_Strike_And_Next_Two_Throws_Higher_Than_StartingPins() { //-- Arrange TenPinsGame game = new TenPinsGame(); GameParser gameParser = new GameParser(); List <int> intInputList = gameParser.ParseGameInputString("10, 9, 5"); //-- Act try { foreach (var input in intInputList) { game.Bowl(input); } } catch (ArgumentException ex) { Assert.AreEqual("The 2nd throw pins of 5 is higher than allowed for this frame. Pls check.", ex.Message); return; } //-- Assert Assert.Fail("Call did NOT throw the Argument Exception"); }
public static void Main() { Console.WriteLine("-- Option 1: The whole game input as one (using built-in parser). --"); int[] bowledBalls = new[] { 10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1 }; int count = 1; var tenPinsGame = new TenPinsGame(); int score; foreach (var input in bowledBalls) { score = tenPinsGame.Bowl(input); Console.WriteLine($"Total Score till current Throw (#{count}) is: {score}"); count++; } // ======= Console.WriteLine("-- Option 2: The whole game input as one (can use 3rd party parcer). --"); var intInputList = new[] { 10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1 }; int count2 = 1; TenPinsGame tenPinsGame2 = new TenPinsGame(); foreach (var input in intInputList) { int score2 = tenPinsGame2.Bowl(input); Console.WriteLine($"Total Score till current Throw (#{count2}) is: {score2}"); count2++; } // ======= Console.WriteLine("-- Option 3: New game to enter input one-by-one. --"); TenPinsGame game = new TenPinsGame(); string consoleInput; do { Console.WriteLine("Please Enter Kicked Pins count for the current Bowl or 'q' to quit:"); consoleInput = Console.ReadLine(); if (consoleInput == "q" || consoleInput == "Q") { break; } try { score = game.Bowl(Convert.ToInt32(consoleInput)); if (score != 0) { Console.WriteLine($"Your current score is: {score}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } while (consoleInput != "q"); Console.WriteLine("Hit any key to Quit."); Console.ReadKey(); }