|
1 |
| -import { format, parseFloat, round } from '#src/utils/number'; |
| 1 | +import { formatNumber, roundNumber, toFloat } from '#src/utils/number'; |
2 | 2 |
|
3 | 3 | describe('number utils', () => {
|
4 | 4 | test('format floating point with another decimal different of 5', () => {
|
5 |
| - expect(format(1e-8, 8)).toBe('0.00000001'); |
| 5 | + expect(formatNumber(1e-8, 8)).toBe('0.00000001'); |
6 | 6 | });
|
7 | 7 |
|
8 | 8 | test('format floating point number 5 upper half of an integer', () => {
|
9 |
| - expect(format(0.1234565, 6)).toBe('0.123457'); |
| 9 | + expect(formatNumber(0.1234565, 6)).toBe('0.123457'); |
10 | 10 | });
|
11 | 11 |
|
12 | 12 | test('format other numbers with fraction such as .005', () => {
|
13 |
| - expect(format(1.015, 2)).toBe('1.02'); |
14 |
| - expect(format(4.015, 2)).toBe('4.02'); |
15 |
| - expect(format(5.015, 2)).toBe('5.02'); |
16 |
| - expect(format(6.015, 2)).toBe('6.02'); |
17 |
| - expect(format(7.015, 2)).toBe('7.02'); |
18 |
| - expect(format(128.015, 2)).toBe('128.02'); |
19 |
| - expect(format(0.005, 2)).toBe('0.01'); |
| 13 | + expect(formatNumber(4.015, 2)).toBe('4.02'); |
| 14 | + expect(formatNumber(5.015, 2)).toBe('5.02'); |
| 15 | + expect(formatNumber(6.015, 2)).toBe('6.02'); |
| 16 | + expect(formatNumber(7.015, 2)).toBe('7.02'); |
| 17 | + expect(formatNumber(128.015, 2)).toBe('128.02'); |
| 18 | + expect(formatNumber(0.005, 2)).toBe('0.01'); |
20 | 19 | });
|
21 | 20 |
|
22 | 21 | test('parseFloat works with NaN numbers', () => {
|
23 |
| - expect(parseFloat('')).toBe(0); |
24 |
| - expect(parseFloat('0.0001')).toBe(0.0001); |
25 |
| - expect(parseFloat('1.0')).toBe(1); |
| 22 | + expect(toFloat('')).toBe(0); |
| 23 | + expect(toFloat('0.0001')).toBe(0.0001); |
| 24 | + expect(toFloat('1.0')).toBe(1); |
26 | 25 | });
|
27 | 26 |
|
28 | 27 | test('round works with negative numbers', () => {
|
29 |
| - expect(round(-1.015, 2)).toBe(-1.02); |
| 28 | + expect(roundNumber(-1.015, 2)).toBe(-1.02); |
30 | 29 | });
|
31 | 30 | });
|
0 commit comments