Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created April 5, 2013 01:39
Show Gist options
  • Select an option

  • Save al-the-x/5315954 to your computer and use it in GitHub Desktop.

Select an option

Save al-the-x/5315954 to your computer and use it in GitHub Desktop.
Coding Dojo at Orlando PHP 2013-04-04
<?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;
}
}
<?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");
}
}
@sultanshakir

Copy link
Copy Markdown

Thanks Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment