public void Strike_Bonus_Calculation_Provided_Next_Mixed_Frames() { var nextRoll = 10; var nextToNextRoll = GetRandomPins(0, 10); var strikeFrame = new StrikeFrame(); var calculatedBonus = strikeFrame.CalculateBonus(nextRoll, nextToNextRoll); var actualBonus = nextRoll + nextToNextRoll; Assert.AreEqual(actualBonus, calculatedBonus); }
public void NextNextThrowScore_NoNextThrow_Returns0() { // Arrange var frame = new StrikeFrame(new List <int>()); // Act var result = frame.NextNextThrowScore(); // Assert Assert.Equal(0, result); }
public void ShouldReturnTrueIfStrike() { //arrange IFrame frame = new StrikeFrame(); //act bool isSpare = frame.IsStrike(); //assert isSpare.Should().BeTrue(); }
public void When_InFirstRollOfFrameKnockDownAllPins_then_SumScoreFromNextFrame() { var strikeFrame = new StrikeFrame(); var nextFrame = new DefaultFrame(3, 4); _theGame.Roll(strikeFrame); _theGame.Roll(nextFrame); int score = _theGame.Score(); Assert.That(score, Is.EqualTo(24)); }
public void ShouldGetAdditionAllBallScoreForStrikeIn10ThFrame() { //arrange IFrame frame1 = new StrikeFrame(); frame1.AddBonusBalls(new BonusBall(10), new BonusBall(5)); Score expectedScore = new Score(25); //act Score actualScore = frame1.TotalScore(); //assert actualScore.Should().Be(expectedScore); }
public void ShouldGetAdditionAllBallScoreForStrike() { //arrange IFrame frame1 = new StrikeFrame(); IFrame frame2 = new RegularFrame(new Ball(4), new Ball(3)); Score expectedScore = new Score(17); frame1.AddNextFrame(frame2); //act Score actualScore = frame1.TotalScore(); //assert actualScore.Should().Be(expectedScore); }
public void NextNextThrowScore_HasNextThrow_ReturnsScore() { // Arrange var allThrows = new List <int>(); var frame = new StrikeFrame(allThrows); allThrows.Add(1); allThrows.Add(2); // Act var result = frame.NextNextThrowScore(); // Assert Assert.Equal(2, result); }
public void ShouldnotGetBonusBallScoreForStrikeNotIn10ThFrame() { //arrange IFrame frame1 = new StrikeFrame(); IFrame frame3 = new RegularFrame(new Ball(3), new Ball(3)); frame1.AddNextFrame(frame3); frame1.AddBonusBalls(new BonusBall(10), new BonusBall(5)); Score expectedScore = new Score(16); //act Score actualScore = frame1.TotalScore(); //assert actualScore.Should().Be(expectedScore); }
public void ShouldScoreStrikeAtTheEnd() { Game game = new Game(); AddFramesWithScore(game, 9, 1); IFrame strikeFrame = new StrikeFrame(); strikeFrame.AddBonusBalls(new BonusBall(3), new BonusBall(6)); game.AddFrame(strikeFrame); Score expectedScore = new Score(37); //act Score actualScore = game.ScoreGame(); //assert actualScore.Should().Be(expectedScore); }
public void ShouldScoreGameWithStrike() { //arrange Game game = new Game(); IFrame strikeFrame = new StrikeFrame(); IFrame frame2 = new RegularFrame(new Ball(3), new Ball(4)); game.AddFrame(strikeFrame); game.AddFrame(frame2); AddFramesWithScore(game, 8); Score expectedScore = new Score(24); //act Score actualScore = game.ScoreGame(); //assert actualScore.Should().Be(expectedScore); }
/// <inheritdoc /> public List <Frame> GetFrames(int[] rolls) { int currentFrameIndex = 0; int currentFrameRollsCount = 0; var frames = new List <Frame>(); for (int i = 0; i < rolls.Length && currentFrameIndex <= FrameConstants.MAX_NUMBER_OF_FRAMES;) { currentFrameIndex++; Frame currentFrame; if (IsStrike(rolls[i])) { currentFrame = new StrikeFrame(); currentFrameRollsCount = 1; } else if (IsSpare(rolls[i], rolls[i + 1])) { currentFrame = new SpareFrame(rolls[i], rolls[i + 1]); currentFrameRollsCount = FrameConstants.MAX_ROLLS_PER_NORMAL_FRAME; } else { currentFrame = new Frame(rolls[i], rolls[i + 1]); currentFrameRollsCount = FrameConstants.MAX_ROLLS_PER_NORMAL_FRAME; } if (IsLastFrame(currentFrameIndex) && IsBonusTypeFrame(currentFrame.FrameType)) { // Case when 10th frame is strike frame. if (currentFrame.Roll2 == null) { currentFrame.Roll2 = rolls[i + 1]; } currentFrame.Roll3 = rolls[i + 2]; currentFrameRollsCount = FrameConstants.MAX_ROLLS_FOR_LAST_FRAME; } i += currentFrameRollsCount; currentFrame.Id = currentFrameIndex; currentFrame.Bonus = currentFrame.CalculateBonus(GetRollPointsAt(rolls, i), GetRollPointsAt(rolls, i + 1)); frames.Add(currentFrame); } return(frames); }
internal static Frame Create(string singleFrameToParse, Roll[] frameRolls, Roll nextRoll, Roll secondNextRollForStrike) { var frame = new Frame(frameRolls); if (Parser.IsSpare(singleFrameToParse)) { frame = new SpareFrame(nextRoll, frameRolls); } if (Parser.IsStrike(singleFrameToParse)) { frame = new StrikeFrame(nextRoll, secondNextRollForStrike, frameRolls); } return(frame); }
public Frame CreateFrame(int pindowns) { Frame frame = null; // Handling last frame which would be spare or strike if (isSpecialFrame && frameCount == 10) { if (isSprareSpecial) { frame = new SpecialFrame(prevRoll, currentRoll, pindowns); } else if (isStrikeSpecial && roll == 1) { currentRoll = pindowns; roll++; } else { frame = new SpecialFrame(prevRoll, currentRoll, pindowns); } } else if (pindowns == 10) { frameCount++; if (frameCount == 10) { // pindown is 10 and it is first roll of last frame isSpecialFrame = true; prevRoll = pindowns; isStrikeSpecial = true; roll++; } else { frame = new StrikeFrame(10, 0); // if pindown is 10 and it is not last frame } if (frameCount != 10) { prevRoll = 0; } } else if (firstRoll) { prevRoll = pindowns; firstRoll = false; } else { if (prevRoll + pindowns == 10) { firstRoll = true; frameCount++; if (frameCount == 10) { // last frame and it is second roll, eligble for special frame isSpecialFrame = true; currentRoll = pindowns; isSprareSpecial = true; } else { frame = new SpareFrame(prevRoll, pindowns); } } else { firstRoll = true; frameCount++; frame = new NormalFrame(prevRoll, pindowns); } if (frameCount != 10) { prevRoll = 0; } } return(frame);; }
public void GenerateFrame(int pins) { var currentFrame = _framesList.LastOrDefault(); //initialise first frame if (currentFrame == null) { var frame = new Frame() { FrameID = 1, Rolls = new List <int>() { pins } }; _framesList.Add(frame); return; } var isStrikeAchieved = (currentFrame.Rolls.Count == 1 && currentFrame.Rolls[0] == _maxPins); var isSpareAchieved = (currentFrame.Rolls.Count == 2 && currentFrame.Rolls.Sum(x => x) == _maxPins); var isLastFrame = currentFrame.FrameID == _maxFrames; //generate strike frame if (isStrikeAchieved && !isLastFrame) { var strikeFrame = new StrikeFrame() { FrameID = currentFrame.FrameID, Rolls = new List <int>() { currentFrame.Rolls[0] } }; _framesList[currentFrame.FrameID - 1] = strikeFrame; } //generate spare frame else if (isSpareAchieved && !isLastFrame) { var spareFrame = new SpareFrame() { FrameID = currentFrame.FrameID, Rolls = new List <int>() { currentFrame.Rolls[0], currentFrame.Rolls[1] } }; _framesList[currentFrame.FrameID - 1] = spareFrame; } //generate default frame else if (isLastFrame || currentFrame.Rolls.Count < 2) { if (currentFrame.Rolls.Count != 3) { currentFrame.Rolls.Add(pins); } return; } //if nothing above matches, then for current roll make another frame var newFrame = new Frame() { FrameID = currentFrame.FrameID + 1, Rolls = new List <int>() { pins } }; _framesList.Add(newFrame); return; }
public StrikeFrameTests() { _frameUnderTest = new StrikeFrame(); _other1 = new OpenFrame(new Roll(1), new Roll(1)); _other2 = new OpenFrame(new Roll(1), new Roll(1)); }