-
-
Save joshuaconner/6259005 to your computer and use it in GitHub Desktop.
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
// think of this as the "constructor" function - returns a GridSpace object | |
// so do your init stuff here | |
var GridSpace = function (x, y, height) { | |
this.x = x; | |
this.y = y; | |
this.height = height; | |
}; | |
// this of this as sort of the "class definition", define your other functions here | |
// be warned though: everything in the prototype is shared between all GridSpace instances! | |
GridSpace.prototype = { | |
/** | |
* ...so don't do this in the prototype... | |
* | |
* x: null, | |
* y: null, | |
* | |
* ...becuase then every GridSpace instance would have the same x and y | |
*/ | |
compareTo: function (height) { | |
if (this.height > height) return 1; | |
if (this.height < height) return -1; | |
return 0; | |
} | |
}; | |
// need to expose if in a Node.js environment | |
if (typeof exports != 'undefined') exports.GridSpace = GridSpace; |
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
var assert = require('assert'); | |
describe('GridSpace', function () { | |
var GridSpace = require('../grid_space.js').GridSpace; | |
describe('#compareTo(height)', function () { | |
it('should return -1 when this.height is smaller than height', function () { | |
// setup | |
var gs = new GridSpace(1, 2, 5); | |
// exercise/verify | |
assert.equal(-1, gs.compareTo(6); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment