Skip to content

Instantly share code, notes, and snippets.

@danshearmur
Last active December 15, 2015 11:39
Show Gist options
  • Save danshearmur/5254619 to your computer and use it in GitHub Desktop.
Save danshearmur/5254619 to your computer and use it in GitHub Desktop.
define(['hashmap'], function (HashMap) {
describe('HashMap', function () {
var hash;
function size (obj) {
var size = 0;
for (var key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
}
beforeEach(function () {
hash = new HashMap();
});
it('should be an instanceof the HashMap class', function () {
assert(hash instanceof HashMap);
});
it('should have an array to store the hash in', function () {
hash.data.should.be.an('array');
});
it('should have a length', function () {
hash.length.should.be.a('number');
});
it('hash should have an add function', function () {
hash.add.should.be.a('function');
});
it('hash should have a get function', function () {
hash.get.should.be.a('function');
});
it('hash data\'s size should grow when item is added', function () {
var sizeBefore = size(hash.data);
hash.add('test-field', 'test text');
var sizeAfter = size(hash.data);
sizeAfter.should.equal(sizeBefore + 1);
});
it('hash should return the same item you put in', function () {
var testText = 'testing testing 123';
var key = 'test';
hash.add(key, testText);
hash.get(key).should.equal(testText);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment