Skip to content

Instantly share code, notes, and snippets.

@joshuaconner
Forked from anonymous/gist:6258993
Last active December 21, 2015 05:39
Show Gist options
  • Save joshuaconner/6259005 to your computer and use it in GitHub Desktop.
Save joshuaconner/6259005 to your computer and use it in GitHub Desktop.
// 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;
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