public void CalculateScoreForFrameTest_PerfectGameOfOnlyStrikes() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>(); for (int i = 0; i < 9; i++) { playedFrames.Add(BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 })); } playedFrames.Add(BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 10, 10 })); int totalScore = 0; int[] expectedResults = new[] { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 }; for (int i = 0; i < playedFrames.Count; i++) { // act int frameScore = scoreCalculator.CalculateScoreForSingleFrame(i + 1, playedFrames); totalScore += frameScore; // assert Assert.AreEqual(frameScore, expectedResults[i]); } Assert.AreEqual(totalScore, 300); }
public void CalculateScoreForFrameTest_SpecificGame() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 7 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 1 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 4 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 5, 5 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 2, 5 }) }; int totalScore = 0; int[] expectedResults = new[] { 20, 20, 18, 9, 17, 7, 7, 13, 5, 7 }; for (int i = 0; i < playedFrames.Count; i++) { // act int frameScore = scoreCalculator.CalculateScoreForSingleFrame(i + 1, playedFrames); totalScore += frameScore; // assert Assert.AreEqual(frameScore, expectedResults[i]); } Assert.AreEqual(totalScore, 123); }
public void BowlingFrame_IsValid_Test() { int firstTry = 4; BowlingFrame frame = new BowlingFrame(firstTry, BowlingGameExtenstions.NUM_OF_PINS - firstTry + 2, FrameTypeEnum.Normal); Assert.IsFalse(frame.IsValid()); }
public void TestCanConstructCalculatedScoreObjectTest() { // arrange TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator = new TraditionalBowlingScoringCalculator(); TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator = new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 7 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 1 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 4 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 5, 5 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 2, 5 }) }; // act CalculatedBowlingScoresDto calculatedBowlingScoresDto = traditionalBowlingScoreCalculatorValidator.ConstructScoresToValidate(playedFrames, traditionalBowlingScoringCalculator); // assert Assert.AreEqual(calculatedBowlingScoresDto.points.Length, 10); Assert.AreEqual(calculatedBowlingScoresDto.points.First(), 20); Assert.AreEqual(calculatedBowlingScoresDto.points.Last(), 123); }
public void BowlingFrameState_SpareTest() { int firstTry = 4; BowlingFrame frame = new BowlingFrame(firstTry, BowlingGameExtenstions.NUM_OF_PINS - firstTry, FrameTypeEnum.Spare); Assert.AreEqual(FrameTypeEnum.Spare, frame.FrameType); }
public void CalculateScoreForFrameTest_summationsForFinishedGame_variant() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 1 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 0, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 0, 10 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 6, 4 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }) }; int[] pointsSummationsAfterGame = new[] { 8, 10, 26, 46, 66, 76 }; for (int i = 0; i < playedFrames.Count; i++) { scoreCalculator.AddPlayedBowlingFrame(playedFrames[i]); } int totalPoints = 0; for (int j = 1; j <= playedFrames.Count; j++) { totalPoints += scoreCalculator.CalculateScoreForSingleFrame(j, playedFrames); Assert.AreEqual(totalPoints, pointsSummationsAfterGame[j - 1]); } }
public static BowlingFrame[] GenerateFrames(params Tuple <int, int>[] tuples) { BowlingFrame[] frames = new BowlingFrame[tuples.Length]; int counter = 0; foreach (Tuple <int, int> t in tuples) { frames[counter++] = new BowlingFrame(t.Item1, t.Item2, GetFrameType(t.Item1, t.Item2, counter)); } FrameTypeEnum GetFrameType(int item1, int item2, int count) { if (count == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS + BowlingGameExtenstions.EXTRA_ROUNDS) { return(FrameTypeEnum.BonusFrame); } if ((item1) == BowlingGameExtenstions.NUM_OF_PINS) { return(FrameTypeEnum.Strike); } if ((item1 + item2) == BowlingGameExtenstions.NUM_OF_PINS) { return(FrameTypeEnum.Spare); } return(FrameTypeEnum.Normal); } return(frames); }
public void CalculateScoreForFrameTest_summationsForOngoingPlay() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 7 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 1 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 4 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 5, 5 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 2 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 2, 5 }) }; int[] pointsSummationsDuringPlay = new[] { 10, 30, 50, 67, 77, 91, 98, 108, 116, 123 }; for (int i = 0; i < playedFrames.Count; i++) { scoreCalculator.AddPlayedBowlingFrame(playedFrames[i]); // assert int summarizedGameScore = scoreCalculator.CalculateTotalScoreForGame(); Assert.AreEqual(summarizedGameScore, pointsSummationsDuringPlay[i]); } }
private void Then(BowlingFrame expected) { _test.Inspect_score(); _test.Current_frame().Should().Be(expected.Frame); _test.Current_score().Should().Be(expected.StartingScore); _test.Current_ball().Should().Be(expected.Ball); }
public void FirstRollString_Strike_SecondRollDash() { var frame = new BowlingFrame() { FirstRollString = "x" }; Assert.IsTrue(frame.SecondRollString.Equals("-")); }
public void BowlingFrameTest_superfluousZerosRemoved() { // arrange/act BowlingFrame bowlingFrame = BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }); // assert Assert.IsTrue(bowlingFrame.Points.Length == 1); // unnecessary 0 removed Assert.AreEqual(bowlingFrame.Points[0], 10); }
public void NewFrame() { _FrameBall = 0; _Frame = Frames.Count; DownPins.Clear(); Debug.Log("Starting frame " + _Frame.ToString()); gameObject.SendMessage("ResetFrame", SendMessageOptions.RequireReceiver); _Score = BowlingFrame.Score(Frames); }
public void FirstRollString_Strike_FirstRollScore10() { var frame = new BowlingFrame() { FirstRollString = "x" }; Assert.AreEqual(STRIKE_VALUE, frame.FirstRollScore); }
public void FirstRollString_Spare_FirstRollScore0() { var frame = new BowlingFrame() { FirstRollString = "/" }; Assert.AreEqual(0, frame.FirstRollScore); }
public void SecondRollString_Spare_FirstSecondTotal10() { var frame = new BowlingFrame() { FirstRollString = "1", SecondRollString = "/" }; Assert.AreEqual(STRIKE_VALUE, frame.FirstRollScore + frame.SecondRollScore); }
public void FirstRoll2_SecondRollScratch_FirstSecondTotal2() { var frame = new BowlingFrame() { FirstRollString = "2", SecondRollString = "-" }; Assert.AreEqual(2, frame.FirstRollScore + frame.SecondRollScore); }
public FrameViewModel() { _frames = new BowlingFrame[10]; for (int i = 0; i < 10; i++) { var bowlingFrame = new BowlingFrame(); bowlingFrame.RollScoreEntered += BowlingFrame_RollScoreEntered; _frames[i] = bowlingFrame; } FrameTen.IsTenthFrame = true; }
public void FrameScore_Called_ReturnsScore() { // Arrange var frame = new BowlingFrame(new List <int>(), 1, 2); // Act var result = frame.FrameScore(); // Assert Assert.Equal(3, result); }
public void ScoreFrame_Roll3And6_FrameTotalEquals9() { var frame = new BowlingFrame() { FirstRollScore = 3, SecondRollScore = 6, FinishedEnteringRolls = true }; _scoreKeeper.ScoreGame(new BowlingFrame[] { frame }); Assert.AreEqual(9, frame.TotalFrameScore); }
public void CalculateScoreForFrameTest_frameNumberOutOfBounds() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 3 }) }; // act/assert scoreCalculator.CalculateScoreForSingleFrame(2, playedFrames); }
public void ScoreGame_TenthFrame_Score30() { var game = new BowlingFrame[] { new BowlingFrame { FirstRollScore = STRIKE_VALUE, SecondRollScore = STRIKE_VALUE, BonusRollScore = STRIKE_VALUE, IsTenthFrame = true } }; _scoreKeeper.ScoreGame(game); Assert.AreEqual(30, game[0].TotalFrameScore); }
public void ScoreGame_TenthFrameOpen_HasTenthFrameBonusFalse() { var frame = new BowlingFrame() { FirstRollScore = 2, SecondRollScore = 2 }; _scoreKeeper.ScoreGame(new[] { frame }); Assert.IsFalse(frame.HasTenthFrameBonus); }
public void UpdateScore(object ball) { _Down = getDownPins(); //shows the returned value BowlingFrame bf = Frames[Frames.Count - 1].AddScore(_FrameBall, _Down); _FrameBall += 1; //Indicates which frame if (bf != null) { Frames.Add(bf); NewFrame(); } }
public void UpdateScore(object ball) { _Down = getDownPins(); BowlingFrame bf = Frames[Frames.Count - 1].AddScore(_FrameBall, _Down); _FrameBall += 1; if (bf != null) { Frames.Add(bf); NewFrame(); } }
public void ScoreGame_TenthFrameSpare_HasTenthFrameBonus() { var frame = new BowlingFrame() { FirstRollScore = 2, SecondRollScore = 8, IsTenthFrame = true }; _scoreKeeper.ScoreGame(new[] { frame }); Assert.IsTrue(frame.HasTenthFrameBonus); }
private void LinkNewFrame() { if (_currentFrame.IsFinalFrame == false) { var newFrame = new BowlingFrame(_currentFrame.Index + 1); _currentFrame.TryLinkNextFrame(newFrame); _currentFrame = _currentFrame.NextFrame; } else { _currentFrame = null; } }
public void CalculateScoreForFrameTest_TooManyFramePoints() { // arrange TraditionalBowlingScoringCalculator scoreCalculator = new TraditionalBowlingScoringCalculator(); IList <BowlingFrame> playedFrames = new List <BowlingFrame>() { BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }), BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 5, 4, 3 }) }; // act/assert int frameScore = scoreCalculator.CalculateScoreForSingleFrame(2, playedFrames); }
public void ScoreFrame_StrikeRolled_FirstFrameTotalEquals17() { var frame = new BowlingFrame() { FirstRollScore = STRIKE_VALUE }; var secondFrame = new BowlingFrame() { FirstRollScore = 4, SecondRollScore = 3 }; _scoreKeeper.ScoreGame(new BowlingFrame[] { frame, secondFrame }); Assert.AreEqual(17, frame.TotalFrameScore); }
public void FrameScore_ThrowsAddedAfterFrame_ReturnsFrameScore() { // Arrange var throws = new List <int>(); var frame = new BowlingFrame(throws, 1, 2); throws.Add(5); // Act var result = frame.FrameScore(); // Assert Assert.Equal(3, result); }
internal static IRule GetRuleToApply(BowlingFrame frame) { if (frame.IsStrike) { return(new StrikeRule()); } else if (frame.IsSpare) { return(new SpareRule()); } return(new BasicRule()); }