-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
53 lines (47 loc) · 1.38 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
var should = require('should');
var lib = require('../lib');
describe('numSort', function () {
it('should sort numbers by numeric value, ascending', function () {
should.deepEqual(lib.numSort([1, -4.5, 2, 3, -5, 0, 5, 20, 0.2, 9]),
[-5, -4.5, 0, 0.2, 1, 2, 3, 5, 9, 20]);
});
it('should gracefully handle an empty argument', function () {
should.deepEqual(lib.numSort([]), []);
});
});
describe('untilValue', function () {
it('should return a found value which is the first', function (done) {
lib.untilValue([
1, 5
], function (val, ncbValHandled) {
ncbValHandled(val === 5, val === 1 ? (val * 2) : undefined);
}, function (errs, res) {
should.not.exist(errs);
res.should.eql(2);
done();
});
});
it('should return a found value which is not the first', function (done) {
lib.untilValue([
1, 5
], function (val, ncbValHandled) {
ncbValHandled(val === 1, val === 5 ? (val * 2) : undefined);
}, function (errs, res) {
should.not.exist(errs);
res.should.eql(10);
done();
});
});
it('should return errors if no value found', function (done) {
lib.untilValue([
1, 5
], function (val, ncbValHandled) {
ncbValHandled(val * 2);
}, function (errs, res) {
should.exist(errs);
errs.should.eql([2, 10]);
done();
});
});
});