Repository navigation
Expand file tree
/
Copy pathbig-integer.spec.js
More file actions
60 lines (48 loc) · 1.56 KB
/
Copy pathbig-integer.spec.js
File metadata and controls
60 lines (48 loc) · 1.56 KB
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
54
55
56
57
58
59
60
var BigInt = require('./big-integer');
describe('The big-integer module\'s returned object', function () {
var bigI;
beforeEach(function() {
bigI = BigInt(42);
});
afterEach(function() {
bigI = null;
});
it('is not a number', function () {
expect(typeof 42).toBe('number');
expect(typeof bigI).not.toBe('number');
expect(typeof bigI).toBe('object');
});
it('can be compared to a stringified number by calling \'.toString()\'',
function () {
expect(bigI).not.toBe(42);
expect(bigI).not.toBe('42');
expect(bigI.toString()).toBe('42');
// NOTE:
// The '==' operator calls '.toString()' here in order to compare.
expect(bigI == '42').toBe(true);
// While the line above is easier to write and read, we will use the
// 'expect(bigI.toString()).toBe(expected)' way so that test failure
// messages will be more informative. Eg,
// "Expected '84' to be '42'." instead of
// "Expected false to be true."
});
it('is immutable', function () {
bigI.add(10);
expect(bigI.toString()).toBe('42');
bigI.subtract(10);
expect(bigI.toString()).toBe('42');
});
it('can add', function () {
bigI = bigI.add(42);
expect(bigI.toString()).toBe('84');
});
it('can perform power operations', function () {
bigI = BigInt(10);
bigI = bigI.pow(2);
expect(bigI.toString()).toBe('100');
});
// ...see the official docs for more info, if you want.
// The "Methods" section of the README is especially useful:
//
// https://github.com/peterolson/BigInteger.js#methods
});