Revert removal of compare nesting

Since we want the user to be able to pass a negative comparison function, the extra layer of wrapping is now needed
This commit is contained in:
Kyriacos Souroullas and Sheel Choksi
2013-10-28 13:49:54 -07:00
parent dd8a455f91
commit e346e7dcc1
37 changed files with 493 additions and 435 deletions

View File

@@ -1,51 +1,51 @@
describe("toBeCloseTo", function() {
it("passes when within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
var matcher = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0);
result = matcher.compare(0, 0);
expect(result.pass).toBe(true);
result = matcherComparator(0, 0.001);
result = matcher.compare(0, 0.001);
expect(result.pass).toBe(true);
});
it("fails when not within two decimal places by default", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
var matcher = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0.01);
result = matcher.compare(0, 0.01);
expect(result.pass).toBe(false);
});
it("accepts an optional precision argument", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
var matcher = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(0, 0.1, 0);
result = matcher.compare(0, 0.1, 0);
expect(result.pass).toBe(true);
result = matcherComparator(0, 0.0001, 3);
result = matcher.compare(0, 0.0001, 3);
expect(result.pass).toBe(true);
});
it("rounds expected values", function() {
var matcherComparator = j$.matchers.toBeCloseTo(),
var matcher = j$.matchers.toBeCloseTo(),
result;
result = matcherComparator(1.23, 1.229);
result = matcher.compare(1.23, 1.229);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.226);
result = matcher.compare(1.23, 1.226);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.225);
result = matcher.compare(1.23, 1.225);
expect(result.pass).toBe(true);
result = matcherComparator(1.23, 1.2249999);
result = matcher.compare(1.23, 1.2249999);
expect(result.pass).toBe(false);
result = matcherComparator(1.23, 1.234);
result = matcher.compare(1.23, 1.234);
expect(result.pass).toBe(true);
});
});