#!/usr/bin/perl use 5.012003; # Perl version requirement use strict; use warnings; use Game::Bowling; use Test::Spec 0.45; describe "A Game::Bowling" => sub { my $game; my @rolls; my $expected_score; before each => sub { $game = new Game::Bowling; @rolls = (2)x20; $expected_score = 40; }; describe 'counts that the score is' => sub { it '0, if 0 pins are shot' => sub { @rolls = (0)x20; is $game->played_with_rolls(\@rolls)->score(), 0; }; it '40, if 2 pins are shot at each roll' => sub { is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; it '41, if 1 more pin is shot at one roll' => sub { $rolls[5] = 3; $expected_score += (-2+3); is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; }; describe 'takes into account a spare' => sub { it 'in the 2nd frame' => sub { @rolls[3,4] = (8,5); $expected_score += (-2+8+5) + (-2+5); is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; it 'in the last frame' => sub { $rolls[19] = 8; push @rolls, 3; $expected_score += (-2+8+3) + 3; is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; }; describe 'takes into account a strike' => sub { it 'in the 2nd frame' => sub { @rolls[2,3,4] = (10,7,1); $expected_score += (-2-2+10+7+1) + (-2+7) + (-2+1); pop @rolls; is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; it 'in the last frame' => sub { @rolls[18,19] = (10,7); push @rolls, 2; $expected_score += (-2-2+10+7+2) + (+7) + (+2); is $game->played_with_rolls(\@rolls)->score(), $expected_score; }; }; describe 'with zero players' => sub { it 'is not interesting' => sub { ok(1); }; }; }; runtests unless caller;