-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
33 lines (29 loc) · 1007 Bytes
/
test.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
'use strict';
require('mocha');
const assert = require('assert');
const isOdd = require('./');
describe('isOdd', function() {
it('should return true if the number is odd:', function() {
assert(!isOdd(0));
assert(!isOdd(2));
assert(isOdd(1));
assert(isOdd(-1));
assert(isOdd(-3));
assert(isOdd(1.0e0));
assert(isOdd(9007199254740991));
});
it('should work with strings:', function() {
assert(!isOdd('0'));
assert(!isOdd('2'));
assert(isOdd('1'));
assert(isOdd('3'));
assert(isOdd('9007199254740991'));
});
it('should throw an error when an invalid value is passed', function() {
assert.throws(() => isOdd(), /expected a number/);
assert.throws(() => isOdd('foo'), /expected a number/);
assert.throws(() => isOdd('1.1e0'), /expected an integer/);
assert.throws(() => isOdd('9007199254740992'), /value exceeds maximum safe integer/);
assert.throws(() => isOdd(9007199254740992), /value exceeds maximum safe integer/);
});
});