Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Funny behavior with the mocha test runner, globals not so good..
- Loading branch information
Ilya Radchenko
committed
Feb 5, 2015
1 parent
042a7ac
commit f6b0394
Showing
4 changed files
with
98 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
// run tests | ||
require('./interval'); | ||
require('./math'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,116 @@ | ||
var expect = require('expect.js'); | ||
var interval = require('../'); | ||
|
||
describe('interval', function() { | ||
'use strict'; | ||
|
||
// zero undefined properties | ||
function create(i) { | ||
var props = ['days', 'hours', 'minutes', 'seconds', 'milliseconds']; | ||
props.forEach(function(prop) { | ||
if (!i[prop]) { | ||
i[prop] = 0; | ||
} | ||
}); | ||
return i; | ||
} | ||
var test = require('tape'); | ||
var interval = require('../'); | ||
|
||
it('should convert days property to milliseconds', function() { | ||
expect(interval({ days: 4 })).to.be(4 * 24 * 60 * 60 * 1000); | ||
test('interval', function (t) { | ||
t.test('should convert days property to milliseconds', function (n) { | ||
n.equal(interval({ days: 4 }), 4 * 24 * 60 * 60 * 1000); | ||
n.end(); | ||
}); | ||
|
||
it('should convert hours property to milliseconds', function() { | ||
expect(interval({ hours: 2 })).to.be(2 * 60 * 60 * 1000); | ||
t.test('should convert hours property to milliseconds', function (n) { | ||
n.equal(interval({ hours: 2 }), 2 * 60 * 60 * 1000); | ||
n.end(); | ||
}); | ||
|
||
it('should convert minutes property to milliseconds', function() { | ||
expect(interval({ minutes: 6 })).to.be(6 * 60 * 1000); | ||
t.test('should convert minutes property to milliseconds', function (n) { | ||
n.equal(interval({ minutes: 6 }), 6 * 60 * 1000); | ||
n.end(); | ||
}); | ||
|
||
it('should convert seconds property to milliseconds', function() { | ||
expect(interval({ seconds: 25 })).to.be(25 * 1000); | ||
t.test('should convert seconds property to milliseconds', function (n) { | ||
n.equal(interval({ seconds: 25 }), 25 * 1000); | ||
n.end(); | ||
}); | ||
|
||
it('should convert milliseconds property to milliseconds', function() { | ||
expect(interval({ milliseconds: 25 })).to.be(25); | ||
t.test('should convert milliseconds property to milliseconds', function (n) { | ||
n.equal(interval({ milliseconds: 25 }), 25); | ||
n.end(); | ||
}); | ||
|
||
it('should convert composite units to milliseconds', function() { | ||
t.test('should convert composite units to milliseconds', function (n) { | ||
var actual = interval({ hours: 7, milliseconds: 43 }); | ||
expect(actual).to.be(7 * 60 * 60 * 1000 + 43); | ||
|
||
n.equal(actual, 7 * 60 * 60 * 1000 + 43); | ||
n.end(); | ||
}); | ||
|
||
it('should return numeric parameter as milliseconds', function() { | ||
expect(interval(852)).to.be(852); | ||
t.test('should return numeric parameter as milliseconds', function (n) { | ||
n.equal(interval(852), 852); | ||
n.end(); | ||
}); | ||
|
||
it('should stringify hours', function() { | ||
expect(interval.stringify({ hours: 1 })).to.be('1 hours'); | ||
t.test('should stringify hours', function (n) { | ||
n.equal(interval.stringify({ hours: 1 }), '1 hours'); | ||
n.end(); | ||
}); | ||
|
||
it('should stringify minutes', function() { | ||
expect(interval.stringify({ minutes: 1 })).to.be('1 minutes'); | ||
t.test('should stringify minutes', function (n) { | ||
n.equal(interval.stringify({ minutes: 1 }), '1 minutes'); | ||
n.end(); | ||
}); | ||
|
||
it('should build object from milliseconds', function() { | ||
t.test('should build object from milliseconds', function (n) { | ||
var actual = interval.fromMilliseconds((50 * 1000) + 40); | ||
var expected = create({ seconds: 50, milliseconds: 40 }); | ||
expect(actual).to.eql(expected); | ||
|
||
n.same(actual, expected); | ||
n.end(); | ||
}); | ||
|
||
it('should normalize over accounted units', function() { | ||
t.test('should normalize over accounted units', function (n) { | ||
var source = { seconds: 75 }; | ||
var expected = create({ minutes: 1, seconds: 15 }); | ||
expect(interval.normalize(source)).to.eql(expected); | ||
|
||
n.same(interval.normalize(source), expected); | ||
n.end(); | ||
}); | ||
|
||
it('should add interval to date', function() { | ||
t.test('should add interval to date', function (n) { | ||
var date = new Date(2000, 1, 2); | ||
var actual = interval.add(date, {days: 1}); | ||
var actual = interval.add(date, { days: 1 }); | ||
var expected = new Date(2000, 1, 3); | ||
expect(actual).to.eql(expected); | ||
|
||
n.same(actual, expected); | ||
n.end(); | ||
}); | ||
|
||
it('should add negative interval to date', function() { | ||
t.test('should add negative interval to date', function (n) { | ||
var date = new Date(2000, 1, 2); | ||
var actual = interval.add(date, {days: -1}); | ||
var actual = interval.add(date, { days: -1 }); | ||
var expected = new Date(2000, 1, 1); | ||
expect(actual).to.eql(expected); | ||
|
||
n.same(actual, expected); | ||
n.end(); | ||
}); | ||
|
||
it('should subtract interval from date', function() { | ||
t.test('should subtract interval from date', function (n) { | ||
var date = new Date(2100, 5, 10); | ||
var actual = interval.subtract(date, {days: 7}); | ||
var actual = interval.subtract(date, { days: 7 }); | ||
var expected = new Date(2100, 5, 3); | ||
expect(actual).to.eql(expected); | ||
|
||
n.same(actual, expected); | ||
n.end(); | ||
}); | ||
|
||
it('should add intervals', function() { | ||
var actual = interval.add({hours: 5}, {days: 7}); | ||
expect(actual).to.eql(interval({hours: 5, days: 7})); | ||
t.test('should add intervals', function (n) { | ||
var actual = interval.add({ hours: 5 }, { days: 7 }); | ||
|
||
n.equal(actual, interval({ hours: 5, days: 7 })); | ||
n.end(); | ||
}); | ||
}); | ||
|
||
// zero undefined properties | ||
function create(i) { | ||
var props = ['days', 'hours', 'minutes', 'seconds', 'milliseconds']; | ||
|
||
props.forEach(function(prop) { | ||
if (!i[prop]) { | ||
i[prop] = 0; | ||
} | ||
}); | ||
|
||
return i; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
var expect = require('expect.js'); | ||
var math = require('../lib/math'); | ||
'use strict'; | ||
|
||
describe('math', function () { | ||
var test = require('tape'); | ||
var math = require('../lib/math'); | ||
|
||
it('should divide evenly', function () { | ||
test('math', function (t) { | ||
t.test('should divide evenly', function (n) { | ||
var result = math.integerDivision(100, 10); | ||
expect(result).to.eql({ quotient: 10, remainder: 0}); | ||
|
||
n.same(result, { quotient: 10, remainder: 0 }); | ||
n.end(); | ||
}); | ||
it('should have remainder', function () { | ||
|
||
t.test('should have remainder', function (n) { | ||
var result = math.integerDivision(15, 10); | ||
expect(result).to.eql({ quotient: 1, remainder: 5}); | ||
|
||
n.same(result, { quotient: 1, remainder: 5 }); | ||
n.end(); | ||
}); | ||
}); |