Created
April 5, 2013 01:39
-
-
Save al-the-x/5315954 to your computer and use it in GitHub Desktop.
Coding Dojo at Orlando PHP 2013-04-04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Imagine a hallway (from the Matrix) with 50 doors on each side. | |
| * Take a walk down the hallway and back up, opening every door. | |
| * On a second pass, close all the even numbered doors. | |
| * The third pass, each third door, close it if it's open and open if it's closed. | |
| * Repeat. | |
| * What is the state of the doors after 100 passes? | |
| */ | |
| class Hallway implements Countable, Iterator | |
| { | |
| protected $index = 0; | |
| protected $doors = array(false, false); | |
| function count() | |
| { | |
| return 10; | |
| } | |
| function current() | |
| { | |
| return $this->doors[$this->index]; | |
| } | |
| function next() | |
| { | |
| $this->index++; | |
| } | |
| function key() | |
| { | |
| return $this->index; | |
| } | |
| function valid() | |
| { | |
| return isset($this->doors[$this->index]); | |
| } | |
| function rewind() | |
| { | |
| $this->index = 0; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'main.php'; | |
| class Test extends PHPUnit_Framework_TestCase | |
| { | |
| function test_something ( ) | |
| { | |
| //$this->assertTrue(false, 'This will never work'); | |
| //$this->assertEquals(true, false, 'Some message'); | |
| //$this->assertFalse((boolean) 0); | |
| } | |
| function test_that_we_have_a_hallway() | |
| { | |
| $this->assertTrue(class_exists('Hallway'), | |
| 'We should have a class called "Hallway"'); | |
| $this->assertCount(10, new Hallway); | |
| $hallway = new Hallway(); | |
| $this->assertEquals($hallway->doors[0], false, "Door must be closed by default"); | |
| $this->assertEquals($hallway->doors[1], false); | |
| foreach($hallway as $door) $this->assertFalse($door); | |
| $hallway->next(); | |
| $this->assertTrue($hallway->previous(), true, "The last door is still closed"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Dave