Skip to content

Instantly share code, notes, and snippets.

@murum
Last active August 29, 2015 14:14
Show Gist options
  • Save murum/d44e1bddce9db9cae0ac to your computer and use it in GitHub Desktop.
Save murum/d44e1bddce9db9cae0ac to your computer and use it in GitHub Desktop.
BowlingGameSpec Updated
<?php namespace spec;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class BowlingGameSpec extends ObjectBehavior {
function it_scores_a_gutter_game_as_zero() {
$this->rollTimes( 20, 0 );
$this->score()->shouldBe( 0 );
}
function it_scores_the_sum_of_all_knocked_down_pins_for_a_game() {
$this->rollTimes( 20, 1 );
$this->score()->shouldBe( 20 );
}
function it_awards_a_one_roll_bonus_for_every_spare() {
$this->rollSpare();
$this->roll( 5 );
$this->rollTimes( 17, 0 );
$this->score()->shouldBe( 20 );
}
function it_awards_a_two_roll_bonus_for_a_strike_in_the_previous_frame() {
$this->rollTen();
$this->roll( 7 );
$this->roll( 2 );
$this->rollTimes( 17, 0 );
$this->score()->shouldBe( 28 );
}
function it_awards_a_one_roll_bonus_for_a_gutter_and_a_ten() {
$this->roll( 0 );
$this->roll( 10 );
$this->roll( 7 );
$this->roll( 2 );
$this->rollTimes( 16, 0 );
$this->score()->shouldBe( 26 );
}
function it_should_roll_three_frames() {
$this->roll( 0 );
$this->roll( 10 );
$this->roll( 7 );
$this->roll( 3 );
$this->roll( 2 );
$this->roll( 3 );
$this->rollTimes( 14, 0 );
$this->score()->shouldBe( 34 );
}
function it_scores_a_perfect_game() {
$this->rollTimes( 12, 10 );
$this->score()->shouldBe( 300 );
}
function it_takes_exception_with_invalid_rolls() {
$this->shouldThrow( 'InvalidArgumentException' )->duringRoll( - 10 );
}
private function rollSpare() {
$this->roll( 2 );
$this->roll( 8 );
}
private function rollTen() {
$this->roll( 10 );
}
private function rollTimes( $count, $pins ) {
for ( $i = 0; $i < $count; $i ++ ) {
$this->roll( $pins );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment