Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created July 16, 2011 17:06
Show Gist options
  • Save al-the-x/1086550 to your computer and use it in GitHub Desktop.
Save al-the-x/1086550 to your computer and use it in GitHub Desktop.
Coding Dojo -- July 16, 2011
Hallway = function(){
/*
var private_property = null;
this.public_property = null;
this.public_method = function(){
private_method();
};
private_method = function(){
};
*/
var doors = [ 0, 0, 0, 0 ];
var trip_count = 0;
this.num_doors = doors.length;
this.state = function()
{
return doors;
}
this.trips = function(num_trips)
{
for (var crnt_trip = 0; crnt_trip < num_trips; crnt_trip++)
{
this.trip();
}
}
this.trip = function()
{
trip_count++;
doors.forEach(function(door,index)
{
if ((index + 1) % trip_count == 0){
if (doors[index])
doors[index] = 0;
else
doors[index] = 1;
}
/* if (!(door%trip_count))
{
} else {
doors[door]
}*/
});
}
};
(function(){ // closure
load('javascript/main.js', 'javascript/jsunity.js');
jsUnity.log = print;
/**
* Attaches the following assertion methods to
* the global scope for convenience.
* - assertException
* - assertTrue
* - assertFalse
* - assertIdentical
* - assertNotIdentical
* - assertEqual
* - assertNotEqual
* - assertMatch
* - assertNotMatch
* - assertTypeOf
* - assertNotTypeOf
* - assertInstanceOf
* - assertNotInstanceOf
* - assertNull
* - assertNotNull
* - assertUndefined
* - assertNotUndefined
* - assertNaN
* - assertNotNaN
* - fail
*/
jsUnity.attachAssertions()
})();
jsUnity.run(function SomeTest ( )
{
function setUp ( )
{
print('setting up');
h = new Hallway();
}
function tearDown ( )
{
print('tearing down');
}
function test_pass_0 ( )
{
assertEqual([ 0, 0, 0, 0], h.state());
}
function test_pass_trip_one ( )
{
h.trip();
assertEqual([1, 1, 1, 1], h.state());
}
function test_pass_2 ( )
{
h.trips(2);
assertEqual([1, 0, 1, 0], h.state());
}
function test_pass_3 ( )
{
h.trips(3);
assertEqual([1,0,0,0], h.state());
}
function test_pass_4()
{
h.trips(4);
assertEqual([1,0,0,1], h.state());
}
function run_trips(amount, hallway){
for (amount in hallway){
hallway.trip();
}
return hallway;
}
}); // END jsUnity.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment