Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tested the class SquareSimple.

  • Loading branch information...
commit e5ff9079d3ad22f438ae99978af23a53f804d855 1 parent 79f257c
Ian Monge authored
14 ianmonge/src/SquareSimple.php
View
@@ -20,17 +20,23 @@ class SquareSimple extends SquareAbstract
* @return integer
*/
public function getNumOfBombs()
- {}
+ {
+ return $this->numBombs;
+ }
/**
* Increment the number of bombs near the square.
*/
public function incrementNumOfBombs()
- {}
+ {
+ $this->numBombs++;
+ }
/**
- * Prints the representation of the square.
+ * Returns the representation of the square.
*/
public function __toString()
- {}
+ {
+ return (string) $this->numBombs;
+ }
}
6 ianmonge/tests/src/SquareBombTest.php
View
@@ -16,14 +16,16 @@ class SquareBombTest extends PHPUnit_Framework_TestCase {
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
- protected function setUp() {
+ protected function setUp()
+ {
$this->object = new SquareBomb;
}
/**
* Test the method __toString().
*/
- public function test__toString() {
+ public function test__toString()
+ {
$result = $this->object->__toString();
$expected = '*';
79 ianmonge/tests/src/SquareSimpleTest.php
View
@@ -22,41 +22,72 @@ protected function setUp() {
}
/**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
+ * Test the method getNumOfBombs().
*/
- protected function tearDown() {
+ public function testGetNumOfBombs()
+ {
+ $result = $this->object->getNumOfBombs();
+ $expected = 0;
+ $this->assertEquals( $result, $expected, 'There must be zero bombs.' );
}
/**
- * @todo Implement testGetNumOfBombs().
+ * Test the method incrementNumOfBombs().
*/
- public function testGetNumOfBombs() {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
+ public function testIncrementNumOfBombs()
+ {
+ $this->object->incrementNumOfBombs();
+ $result = $this->object->getNumOfBombs();
+ $expected = 1;
- /**
- * @todo Implement testIncrementNumOfBombs().
- */
- public function testIncrementNumOfBombs() {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ $this->assertEquals( $result, $expected, 'There must be one bomb near.' );
+
+ $this->object->incrementNumOfBombs();
+ $result = $this->object->getNumOfBombs();
+ $expected = 2;
+
+ $this->assertEquals( $result, $expected, 'There must be two bombs near.' );
+
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $result = $this->object->getNumOfBombs();
+ $expected = 8;
+
+ $this->assertEquals( $result, $expected, 'There must be two bombs near.' );
}
/**
- * @todo Implement test__toString().
+ * Test the method __toString().
*/
- public function test__toString() {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
+ public function test__toString()
+ {
+ $result = $this->object->__toString();
+ $expected = '0';
+
+ $this->assertEquals( $result, $expected, 'The method "__toString" must return "0".' );
+
+ $this->object->incrementNumOfBombs();
+ $result = $this->object->__toString();
+ $expected = '1';
+
+ $this->assertEquals( $result, $expected, 'The method "__toString" must return "1".' );
+
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $this->object->incrementNumOfBombs();
+ $result = $this->object->__toString();
+ $expected = '8';
+
+ $this->assertEquals( $result, $expected, 'The method "__toString" must return "8".' );
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.