forked from jamaljsr/polar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbers.spec.ts
39 lines (34 loc) · 1.31 KB
/
numbers.spec.ts
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
import { abbreviate } from './numbers';
const baseNumbers = [9, 15, 248, 826, 999];
describe('Numbers Util', () => {
it('should not abbreviate values less than 1000', () => {
const expected = ['9', '15', '248', '826', '999'];
for (let i = 0; i < baseNumbers.length; i++) {
expect(abbreviate(baseNumbers[i])).toBe(expected[i]);
}
});
it('should add k for numbers in the thousands', () => {
const expected = ['9.0k', '15.0k', '248.0k', '826.0k', '999.0k'];
const multiplier = 1000;
for (let i = 0; i < baseNumbers.length; i++) {
const result = abbreviate(baseNumbers[i] * multiplier);
expect(result).toBe(expected[i]);
}
});
it('should add M for numbers in the millions', () => {
const expected = ['9.0M', '15.0M', '248.0M', '826.0M', '999.0M'];
const multiplier = 1000000;
for (let i = 0; i < baseNumbers.length; i++) {
const result = abbreviate(baseNumbers[i] * multiplier);
expect(result).toBe(expected[i]);
}
});
it('should add B for numbers in the millions', () => {
const expected = ['9.0B', '15.0B', '248.0B', '826.0B', '999.0B'];
const multiplier = 1000000000;
for (let i = 0; i < baseNumbers.length; i++) {
const result = abbreviate(baseNumbers[i] * multiplier);
expect(result).toBe(expected[i]);
}
});
});