-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
118 lines (101 loc) · 3.63 KB
/
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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var assert = require('assert');
var jorts = require('./jorts.js');
// Shims to switch from qunit to mocha while tests still test
var one = function (a, e) { assert.equal(String(jorts.one(a)), String(e)) };
var many = function (a, e) { assert.equal(String(jorts.many(a)), String(e)) };
var test = function (name, fn) {
it(name, fn);
}
test('General: Readme scenarios', function () {
// Readme uses these to explain how the library works, how it works on
// multiple vs. single values.
many([1231, 8345, 0, 19353], ['1K', '8K', '0', '19K']);
many([1231, 8345, 117, 19353], ['1K', '8K', '0K', '19K']);
many([117], ['117']);
many([0], ['0']);
// Readme notes mention the M vs MM vs B behavior
many([1000000], ['1M']);
many([1000000000], ['1B']);
// Readme uses this cases to explain why this library's not really for charting.
many([545, 627, 1993, 4871], ['1K', '1K', '2K', '5K']);
});
test('General: Basic scenarios needed to understand jorts', function () {
one(1184, '1K'); // common use for one number
one(0, '0'); // 0 is always 0
many([0, 1000, 2000], ['0', '1K', '2K']); // 0 is always 0, but the others are Ks
one(17, '17'); // 17 alone isn't worth shortening
many([17, 500, 1000, 2000], ['0K', '1K', '1K', '2K']); // but mix 17 with K's, and for comparison it's 0K
one(117, '117'); // 117 alone needn't be shortened
many([117, 1000, 2000], ['0K', '1K', '2K']); // but mix 117 in with K's, and we shorten it again
many([117, 1000, 2000, 2200], ['0K', '1K', '2K', '2K']);
// note the tests above show we're not using decimals at all. We may reconsider adding decimals,
// which in particular would change the final call expected to ['.1K', '1K', '2K', '2.2K']
});
test('General: Small numbers left alone', function () {
many([0, 1, 2], ['0', '1', '2']);
many([5, 1, 0], ['5', '1', '0']);
many([3, 9], ['3', '9']);
});
test('General: Gamut positive', function () {
many([0], ['0']);
many([1e0], ['1']);
many([1e1], ['10'])
many([1e2], ['100'])
many([1e3], ['1K']);
many([1e4], ['10K']);
many([1e5], ['100K']);
many([1e6], ['1M']);
many([1e7], ['10M']);
many([1e8], ['100M']);
many([1e9], ['1B']);
many([1e10], ['10B']);
many([1e11], ['100B']);
many([1e12], ['1T']);
many([1e13], ['10T']);
many([1e14], ['100T']);
});
test('General: Gamut negative', function () {
many([0], ['0']);
many([-1e0], ['-1']);
many([-1e1], ['-10']);
many([-1e2], ['-100']);
many([-1e3], ['-1K']);
many([-1e4], ['-10K']);
many([-1e5], ['-100K']);
many([-1e6], ['-1M']);
many([-1e7], ['-10M']);
many([-1e8], ['-100M']);
many([-1e9], ['-1B']);
many([-1e10], ['-10B']);
many([-1e11], ['-100B']);
many([-1e12], ['-1T']);
many([-1e13], ['-10T']);
many([-1e14], ['-100T']);
});
test('General: Trillion is the largest supported scale', function () {
many([1000000000000000], ['1000T']);
});
test('General: National debt as mentioned in readme works', function () {
many([17635936048534], ['18T']);
});
test('Many: Empty yields empty', function () {
many([], []);
});
test('One: Unexpected values', function () {
one(undefined, undefined);
one("Fragrant Banana", undefined);
});
test("Many: Unexpected values", function () {
many(undefined, undefined);
many("Palomino", undefined);
many({ A: 1 }, undefined);
});
test('General: Negatives in mixed company', function () {
many([1000, -1000], ['1K', '-1K']);
many([1, -1000], ['0K', '-1K']);
many([-1, 1000], ['0K', '1K']);
many([-1000, 10000], ['-1K', '10K'])
many([1000, -10000], ['1K', '-10K'])
many([0, 1000, -1000], ['0', '1K', '-1K']);
many([0, 1000000, -1000], ['0', '1M', '0M']);
});