Skip to content

Commit

Permalink
fixed some bugs in the specs (code unaffected)
Browse files Browse the repository at this point in the history
Sometimes testing the tests isn't overkill...
sinisterchipmunk committed May 10, 2012
1 parent 37716ad commit afa6d58
Showing 3 changed files with 47 additions and 5 deletions.
15 changes: 12 additions & 3 deletions spec/javascripts/helpers/spec_helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
beforeEach(function() {
var HELPER_MATCHERS = (function() {
var EPSILON = 0.00001;

this.addMatchers({
return {
/*
Returns true if `actual` has the same length as `expected`, and
if each element of both arrays is within 0.000001 of each other.
@@ -14,9 +14,18 @@ beforeEach(function() {

if (this.actual.length != expected.length) return false;
for (var i = 0; i < this.actual.length; i++)
if (isNaN(this.actual[i]) !== isNaN(expected[i]))
return false;
if (Math.abs(this.actual[i] - expected[i]) >= EPSILON)
return false;
return true;
}
});
};
})();

beforeEach(function() {
this.addMatchers(HELPER_MATCHERS);
});

if (typeof(global) != 'undefined')
global.HELPER_MATCHERS = HELPER_MATCHERS;
33 changes: 33 additions & 0 deletions spec/javascripts/spec_helper_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe("spec helper", function() {
var mock = null;
describe("toBeEqualish", function() {
beforeEach(function() {
mock = function(actual) {
return {
actual: actual,
equalish: HELPER_MATCHERS.toBeEqualish
};
};
});

it("should fail if a is NaN and b is not", function() {
expect(mock(NaN).equalish(1)).not.toBeTruthy()
});

it("should fail if b is NaN and a is not", function() {
expect(mock(1).equalish(NaN)).not.toBeTruthy()
});

it("should fail if a is vec of NaN and b is not", function() {
expect(mock([NaN, NaN, NaN, NaN]).equalish([1, 2, 3, 4])).not.toBeTruthy()
});

it("should fail if b is vec of NaN and a is not", function() {
expect(mock([1, 2, 3, 4]).equalish([NaN, NaN, NaN, NaN])).not.toBeTruthy()
});

it("should not fail if a and b are the same", function() {
expect(mock(1).equalish(1)).toBeTruthy()
});
});
});
4 changes: 2 additions & 2 deletions spec/javascripts/vec2_spec.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ describe("vec2", function() {
});

describe("without dest", function() {
beforeEach(function() { result = vec2.lerp(vecA, vecB); });
beforeEach(function() { result = vec2.lerp(vecA, vecB, 0.5); });
it("should return vecA", function() { expect(result).toBe(vecA); });
it("should modify vecA", function() { expect(vecA).toBeEqualish([2, 3]); });
it("should not modify vecB", function() { expect(vecB).toBeEqualish([3, 4]); });
@@ -130,7 +130,7 @@ describe("vec2", function() {
});

describe("without dest vec2", function() {
beforeEach(function() { result = vec2.scale(vecA, vecB); });
beforeEach(function() { result = vec2.scale(vecA, vecB, 0.5); });

it("should place values into vecA", function() { expect(vecA).toBeEqualish([0.5, 1]); });
});

0 comments on commit afa6d58

Please sign in to comment.