public void TestCompleteMethodScore() { this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => score[0] == 10); IConsistsOf frame = this.frame; Assert.IsFalse(frame.IsComplete()); frame.Ball(0, 9); Assert.IsFalse(frame.IsComplete()); frame.Ball(0, 1); Assert.IsTrue(frame.IsComplete()); }
public void TestCompleteMethodPlays() { this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => nPlays == 2); IConsistsOf frame = this.frame; // make a new reference to the frame under test with the type of the interface Assert.IsFalse(frame.IsComplete()); frame.Ball(0, 8); Assert.IsFalse(frame.IsComplete()); frame.Ball(0, 1); Assert.IsTrue(frame.IsComplete()); }
public void TestGetnPlays() { this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => nPlays == 3); IConsistsOf frame = this.frame; Assert.AreEqual(0, frame.GetnPlays()); frame.Ball(0, 3); Assert.AreEqual(1, frame.GetnPlays()); frame.Ball(0, 2); Assert.AreEqual(2, frame.GetnPlays()); frame.Ball(1, 6); Assert.AreEqual(3, frame.GetnPlays()); frame.Ball(1, 6); Assert.AreEqual(3, frame.GetnPlays()); }
public void TestGetSubFrames() { this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => nPlays == 2); IConsistsOf frame = this.frame; List <IConsistsOf> L = frame.GetSubFrames(); Assert.AreEqual(1, L.Count); frame.Ball(0, 3); L = frame.GetSubFrames(); Assert.AreEqual(2, L.Count); }
// This method is provided by an extension method in the project 'Wiring'. // The extension method uses reflection to do the same thing // The method returns the object it is called on to support fluent coding style /* * public WinnerTakesPoint WireTo(IConsistsOf c) * { * downStreamFrame = c; * return this; * } */ public void Ball(int player, int score) { // This is where all the logic for the abstraction is // 1. Nothing if the downstrean frame has already completed // 2. Pass the ball to the downstream frame if (IsComplete()) { return; } if (downStreamFrame != null) { downStreamFrame.Ball(player, score); } }
public void TestCompleteMethodframeNumber() { // This test also tests GetCopy // set the completion lambda function for the frame object under test to complete only if it is the 2nd frame of its parent this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => frameNumber == 1); IConsistsOf frame = this.frame; frame.Ball(0, 1); Assert.IsFalse(frame.IsComplete()); frame = frame.GetCopy(1); // makes a Copy of the Frame with the passed in frameNumber Assert.IsFalse(frame.IsComplete()); frame.Ball(0, 1); // The child (SinglePlay) must be complete as well as the lambda expression Assert.IsTrue(frame.IsComplete()); }
// This method is provided by an extension method in the project 'Wiring'. // The extension method uses reflection to do the same thing // The method returns the object it is called on to support fluent coding style /* * public Switch WireTo(IConsistsOf c) * { * if (downStreamFrame1 == null) * { * downStreamFrame1 = c; * } * else * { * downStreamFrame2 = c; * } * return this; * } */ public void Ball(int player, int score) { if (IsSwitched()) { if (downStreamFrame2 != null) { downStreamFrame2.Ball(player, score); } } else { if (downStreamFrame1 != null) { downStreamFrame1.Ball(player, score); } } }
// Following function implement the IConsistsOf interface /// <summary> /// Drives the game forward by one play. Use one of the parameters to indicate the result of the play. /// </summary> /// <param name="player">Which player won the play e.g. in tennis 0 or 1</param> /// <param name="score">Or the score on the play e.g. in Bowling the number of pins downed</param> public void Ball(int player, int score) { // This is where all the logic for the abstraction is // We have three things to do // 1. Check if we are finished and if so do nothing // 2. After the downstream frame completes, add further throws to our local score. Stop when the lambda function says we are complete // 3. As uaual pass through the Ball scores downstream if (IsBonusScoringComplete()) { return; } if (IsComplete() && !IsBonusScoringComplete()) { bonusScore += score; bonusBalls++; } if (downStreamFrame != null) { downStreamFrame.Ball(player, score); } }
void ITestBowling.Play(int result) { // A play is a throw, result is the number of pins scorerEngine.Ball(0, result); // scoring one player, so the player index is always 0. // (if two players you need a second instance of the application, because the tree structure of Frames is different for each.) }
void ITestTennis.Play(int result) { match.Ball(result, 1); }