Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests refactorizados

  • Loading branch information...
commit 7bd138bbb8a9f8b34637e0747e878f62b18191fa 1 parent 46c39be
@fiunchinho fiunchinho authored
Showing with 40 additions and 109 deletions.
  1. +40 −109 fiunchinho/tests/BowlingTest.php
View
149 fiunchinho/tests/BowlingTest.php
@@ -3,118 +3,49 @@
require_once realpath( __DIR__ . '/..' ) . '/Bowling.php';
/**
- * Test class for Bowling.
- * Generated by PHPUnit on 2011-07-31 at 13:09:18.
+ * Test class for Bowling Kata.
+ *
*/
class BowlingTest extends PHPUnit_Framework_TestCase
{
-
- public function testThrowing9PinsInFirstFrame()
- {
- $this->bowling = new Bowling( array( 9, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 9, $this->bowling->getScore() );
- }
-
- public function testThrowing5PinsInFirstFrame()
- {
- $this->bowling = new Bowling( array( 5, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 5, $this->bowling->getScore() );
- }
-
- public function testThrowing12PinsInFirstFrameWithoutStrike()
- {
- $this->bowling = new Bowling( array( 9, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 12, $this->bowling->getScore() );
- }
-
- public function testThrowing12PinsInSecondFrameWithoutStrike()
- {
- $this->bowling = new Bowling( array( '-', '-', 9, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 12, $this->bowling->getScore() );
- }
-
- public function testThrowing12PinsBetweenFirstAndSecondFrameWithoutStrike()
- {
- $this->bowling = new Bowling( array( 9, '-', '-', 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 12, $this->bowling->getScore() );
- }
-
- public function testThrowingSpareInFirstFrameAnd2PinsInSecondIs14()
- {
- $this->bowling = new Bowling( array( 5, '/', 2, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 14, $this->bowling->getScore() );
- }
-
- public function testThrowingSpareInFirstFrameAnd2And3PinsInSecondIs17()
- {
- $this->bowling = new Bowling( array( 5, '/', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 17, $this->bowling->getScore() );
- }
-
- public function testThrowingSpareInFirstFrameAndSpareInSecondAnd2PinsInThirdIs26()
- {
- $this->bowling = new Bowling( array( 5, '/', 2, '/', 2, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 26, $this->bowling->getScore() );
- }
-
- public function testOneStrikeInFirstThrowIs10()
- {
- $this->bowling = new Bowling( array( 'X', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 10, $this->bowling->getScore() );
- }
-
- public function testOneStrikeInFirstThrowAnd2PinsIs14()
- {
- $this->bowling = new Bowling( array( 'X', 2, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 14, $this->bowling->getScore() );
- }
-
- public function testOneStrikeInFirstThrowAnd2And3PinsIs20()
- {
- $this->bowling = new Bowling( array( 'X', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 20, $this->bowling->getScore() );
- }
-
- public function testComplexFrameThatScores81()
- {
- $this->bowling = new Bowling( array( 'X', 2, 3, 4, '/', 2, 5, 'X', 'X', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-' ) );
- $this->assertEquals( 81, $this->bowling->getScore() );
- }
-
- public function testEndingInSpare()
- {
- $this->bowling = new Bowling( array( 2, 3, '-', '-', '-', '-', '-', '-', '-', '/', 2 ) );
- $this->assertEquals( 17, $this->bowling->getScore() );
- }
-
- public function testEndingInStrike()
- {
- $this->bowling = new Bowling( array( '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 'X', 'X', 'X' ) );
- $this->assertEquals( 30, $this->bowling->getScore() );
- }
-
- public function testFullStrikes()
- {
- $this->bowling = new Bowling( array( 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ) );
- $this->assertEquals( 300, $this->bowling->getScore() );
- }
-
- public function testEndingInStrikeAndSpare()
- {
- $this->bowling = new Bowling( array( '-', '-', 2, 3, 'X', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 'X', 2, '/' ) );
- $this->assertEquals( 35, $this->bowling->getScore() );
- }
-
- public function test10PairsOf9AndMiss()
- {
- $this->bowling = new Bowling( array( 9, '-', 9, '-', 9, '-', 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' ) );
- $this->assertEquals( 90, $this->bowling->getScore() );
- }
-
- public function test10PairsOf5AndSpareWithFinal5()
- {
- $this->bowling = new Bowling( array( 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5 ) );
- $this->assertEquals( 150, $this->bowling->getScore() );
+ /**
+ * Dataprovider for the Bowling test.
+ *
+ * @return array Array containing the different test cases.
+ */
+ public function providerBowling()
+ {
+ return array(
+ 'testThrowing9PinsInFirstFrame' => array( array( 9, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 9 ),
+ 'testThrowing5PinsInFirstFrame' => array( array( 5, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 5 ),
+ 'testThrowing12PinsInFirstFrameWithoutStrike' => array( array( 9, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 12 ),
+ 'testThrowing12PinsInSecondFrameWithoutStrike' => array( array( '-', '-', 9, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 12 ),
+ 'testThrowing12PinsBetweenFirstAndSecondFrameWithoutStrike' => array( array( 9, '-', '-', 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 12 ),
+ 'testThrowingSpareInFirstFrameAnd2PinsInSecondIs14' => array( array( 5, '/', 2, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 14 ),
+ 'testThrowingSpareInFirstFrameAnd2And3PinsInSecondIs17' => array( array( 5, '/', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 17 ),
+ 'testOneStrikeInFirstThrowIs10' => array( array( 'X', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 10 ),
+ 'testOneStrikeInFirstThrowAnd2PinsIs14' => array( array( 'X', 2, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 14 ),
+ 'testOneStrikeInFirstThrowAnd2And3PinsIs20' => array( array( 'X', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ), 20 ),
+ 'testComplexFrameThatScores81' => array( array( 'X', 2, 3, 4, '/', 2, 5, 'X', 'X', 2, 3, '-', '-', '-', '-', '-', '-', '-', '-' ), 81 ),
+ 'testEndingInSpare' => array( array( 2, 3, '-', '-', '-', '-', '-', '-', '-', '/', 2 ), 17 ),
+ 'testEndingInStrike' => array( array( '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 'X', 'X', 'X' ), 30 ),
+ 'testFullStrikes' => array( array( 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), 300 ),
+ 'testEndingInStrikeAndSpare' => array( array( '-', '-', 2, 3, 'X', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 'X', 2, '/' ), 35 ),
+ 'test10PairsOf9AndMiss' => array( array( 9, '-', 9, '-', 9, '-', 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' , 9, '-' ), 90 ),
+ 'test10PairsOf5AndSpareWithFinal5' => array( array( 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5, '/', 5 ), 150 )
+ );
+ }
+
+ /**
+ *
+ * @dataProvider providerBowling
+ * @param array $frames
+ * @param int $expectedScore
+ */
+ public function testBowling( $frames, $expectedScore )
+ {
+ $this->bowling = new Bowling( $frames );
+ $this->assertEquals( $expectedScore, $this->bowling->getScore() );
}
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.