public void test_a_valid_event_is_returned() { MockRandomNumberGenerator mock = new MockRandomNumberGenerator(2); Ball ball = new Ball(mock); outcomes outcome = ball.Bowl(); Assert.Equal(2, (int)outcome); }
public void test_no_run() { MockRandomNumberGenerator mock = new MockRandomNumberGenerator(1); Game thisGame = new Game(mock); outcomes outcomeFinal = thisGame.Play(); Assert.Equal(ONE_RUN, outcomeFinal); }
public virtual outcomes Play() { // Play outcomes outcome = _bowler.Bowl(_ball); outcomes outcomeFinal = _batsman.Play(outcome); return(outcomeFinal); }
void test_score_combinations(outcomes outcome, int runs, int wickets, int balls, int maidens, int score1, int score2) { _keeper.SubmitTeam(0, new string[] { "Ian Botham", "David Gower" }); event_sequence(outcome); assert_score(runs, wickets, balls, maidens); Assert.Equal(score1, _keeper.GetBatsmanScore(0, "Ian Botham")); Assert.Equal(score2, _keeper.GetBatsmanScore(0, "David Gower")); }
public outcomes Play(outcomes outcome) { int flipCoin = _rand.GetRandomNumber(0, 2); if (flipCoin == 1) { return(outcome); } return(outcomes.NO_RUNS); }
public void test_bowling_a_ball_returns_an_outcome() { Mock <Ball> mockBall; Bowler bowler = new Bowler(); mockBall = new Mock <Ball>(); mockBall.Setup(m => m.Bowl()).Returns(() => BOWLED); outcomes outcome = bowler.Bowl((Ball)mockBall.Object); Assert.Equal(BOWLED, outcome); }
public virtual bool HandleEvent(outcomes gameEvent) { int newRuns = 0; if (ScoreMap.runs.ContainsKey(gameEvent)) { newRuns = ScoreMap.runs[gameEvent]; _card.MatchCard[_currentInnings].runs += (int)newRuns; _card.MatchCard[_currentInnings].batsmenList[_striker].runs += (int)newRuns; _card.MatchCard[_currentInnings].bowlerList[_currentBowler].runs += (int)newRuns; } else if (ScoreMap.extras.ContainsKey(gameEvent)) { newRuns = ScoreMap.extras[gameEvent]; _card.MatchCard[_currentInnings].extras += (int)newRuns; _card.MatchCard[_currentInnings].runs += (int)newRuns; _card.MatchCard[_currentInnings].bowlerList[_currentBowler].runs += (int)newRuns; //runsThisOver += newRuns; } else if (ScoreMap.wickets.Contains(gameEvent)) { _card.MatchCard[_currentInnings].wickets++; _card.MatchCard[_currentInnings].bowlerList[_currentBowler].wickets++; if (_striker > _nonStriker) { _striker++; } else { _striker = _nonStriker + 1; } } if (ScoreMap.changeEnds.Contains(gameEvent)) { int v = _striker; _striker = _nonStriker; _nonStriker = v; } _runsThisOver += newRuns; if (!ScoreMap.extraBall.Contains(gameEvent)) { _card.MatchCard[_currentInnings].balls++; _card.MatchCard[_currentInnings].bowlerList[_currentBowler].balls++; } return(_card.MatchCard[_currentInnings].wickets == 10); }
public bool CountBalls(outcomes outcome) { outcomes[] extras = { outcomes.NO_BALL, outcomes.WIDE, outcomes.TWO_WIDES, outcomes.THREE_WIDES, outcomes.FOUR_WIDES }; // Check if extra ball required if (extras.Contains(outcome)) { return(false); } // check for end of over _ball++; if (_ball == _balls_per_over) { return(true); } return(false); }