@oliasoft-open-source/units 4.2.5 → 4.3.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/README.md +570 -0
- package/dist/index.d.ts +399 -8
- package/dist/index.js +2514 -79
- package/package.json +33 -34
- package/dist/comparison/comparison.d.ts +0 -15
- package/dist/comparison/comparison.js +0 -120
- package/dist/comparison/comparison.js.map +0 -1
- package/dist/comparison/comparison.test.d.ts +0 -1
- package/dist/comparison/comparison.test.js +0 -261
- package/dist/comparison/comparison.test.js.map +0 -1
- package/dist/constants.d.ts +0 -1218
- package/dist/constants.js +0 -1305
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces.d.ts +0 -13
- package/dist/interfaces.js +0 -3
- package/dist/interfaces.js.map +0 -1
- package/dist/internationalization/internationalization.d.ts +0 -4
- package/dist/internationalization/internationalization.js +0 -64
- package/dist/internationalization/internationalization.js.map +0 -1
- package/dist/internationalization/internationalization.test.d.ts +0 -1
- package/dist/internationalization/internationalization.test.js +0 -65
- package/dist/internationalization/internationalization.test.js.map +0 -1
- package/dist/internationalization/utils.d.ts +0 -5
- package/dist/internationalization/utils.js +0 -114
- package/dist/internationalization/utils.js.map +0 -1
- package/dist/numbers/display-number.d.ts +0 -20
- package/dist/numbers/display-number.js +0 -141
- package/dist/numbers/display-number.js.map +0 -1
- package/dist/numbers/display-number.test.d.ts +0 -1
- package/dist/numbers/display-number.test.js +0 -182
- package/dist/numbers/display-number.test.js.map +0 -1
- package/dist/numbers/numbers.d.ts +0 -4
- package/dist/numbers/numbers.js +0 -94
- package/dist/numbers/numbers.js.map +0 -1
- package/dist/numbers/numbers.test.d.ts +0 -1
- package/dist/numbers/numbers.test.js +0 -167
- package/dist/numbers/numbers.test.js.map +0 -1
- package/dist/parse/parse-number.d.ts +0 -13
- package/dist/parse/parse-number.js +0 -49
- package/dist/parse/parse-number.js.map +0 -1
- package/dist/parse/parse-number.test.d.ts +0 -1
- package/dist/parse/parse-number.test.js +0 -86
- package/dist/parse/parse-number.test.js.map +0 -1
- package/dist/rounding/deprecated-rounding.d.ts +0 -4
- package/dist/rounding/deprecated-rounding.js +0 -80
- package/dist/rounding/deprecated-rounding.js.map +0 -1
- package/dist/rounding/rounding.d.ts +0 -13
- package/dist/rounding/rounding.js +0 -199
- package/dist/rounding/rounding.js.map +0 -1
- package/dist/rounding/rounding.test.d.ts +0 -1
- package/dist/rounding/rounding.test.js +0 -543
- package/dist/rounding/rounding.test.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/units.d.ts +0 -29
- package/dist/units.js +0 -365
- package/dist/units.js.map +0 -1
- package/dist/utils.d.ts +0 -27
- package/dist/utils.js +0 -280
- package/dist/utils.js.map +0 -1
- package/dist/validate/ajv-validators.d.ts +0 -6
- package/dist/validate/ajv-validators.js +0 -127
- package/dist/validate/ajv-validators.js.map +0 -1
- package/dist/validate/errors-transform.d.ts +0 -2
- package/dist/validate/errors-transform.js +0 -8
- package/dist/validate/errors-transform.js.map +0 -1
- package/dist/validate/schemas/index.d.ts +0 -2
- package/dist/validate/schemas/index.js +0 -11
- package/dist/validate/schemas/index.js.map +0 -1
- package/dist/validate/schemas/test.schema.d.ts +0 -12
- package/dist/validate/schemas/test.schema.js +0 -15
- package/dist/validate/schemas/test.schema.js.map +0 -1
- package/dist/validate/schemas/validate-number.schema.d.ts +0 -5
- package/dist/validate/schemas/validate-number.schema.js +0 -8
- package/dist/validate/schemas/validate-number.schema.js.map +0 -1
- package/dist/validate/validate.test.d.ts +0 -1
- package/dist/validate/validate.test.js +0 -32
- package/dist/validate/validate.test.js.map +0 -1
|
@@ -1,543 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rounding_1 = require("./rounding");
|
|
4
|
-
const deprecated_rounding_1 = require("./deprecated-rounding");
|
|
5
|
-
describe('Rounding', () => {
|
|
6
|
-
describe('roundNumber (private)', () => {
|
|
7
|
-
test('rounds values to N decimal places', () => {
|
|
8
|
-
expect((0, rounding_1.roundNumber)(1.234567)).toBe(1.2346);
|
|
9
|
-
expect((0, rounding_1.roundNumber)(1.234567, 3)).toBe(1.235);
|
|
10
|
-
expect((0, rounding_1.roundNumber)(0.00000000123456789)).toBe(0);
|
|
11
|
-
expect((0, rounding_1.roundNumber)(0.00000000123456789, 12)).toBe(1.235e-9);
|
|
12
|
-
expect((0, rounding_1.roundNumber)(1.23456789e-9, 12)).toBe(1.235e-9);
|
|
13
|
-
expect((0, rounding_1.roundNumber)(100000.123456)).toBe(100000.1235);
|
|
14
|
-
expect((0, rounding_1.roundNumber)(100000.00000000124)).toBe(100000);
|
|
15
|
-
expect((0, rounding_1.roundNumber)(-0.00049)).toBe(-0.0005);
|
|
16
|
-
expect((0, rounding_1.roundNumber)(-100000.123456)).toBe(-100000.1235);
|
|
17
|
-
expect((0, rounding_1.roundNumber)(1.005, 2)).toBe(1);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
describe('roundNumberToPrecision (private)', () => {
|
|
21
|
-
test('rounds a number to N significant digits', () => {
|
|
22
|
-
expect((0, rounding_1.roundNumberToPrecision)(0.00000000000456789)).toBe(4.568e-12);
|
|
23
|
-
expect((0, rounding_1.roundNumberToPrecision)(0.0000456789)).toBe(0.00004568);
|
|
24
|
-
expect((0, rounding_1.roundNumberToPrecision)(0.0123456789)).toBe(0.01235);
|
|
25
|
-
expect((0, rounding_1.roundNumberToPrecision)(1)).toBe(1);
|
|
26
|
-
expect((0, rounding_1.roundNumberToPrecision)(10)).toBe(10);
|
|
27
|
-
expect((0, rounding_1.roundNumberToPrecision)(-10)).toBe(-10);
|
|
28
|
-
expect((0, rounding_1.roundNumberToPrecision)(10.01)).toBe(10.01);
|
|
29
|
-
expect((0, rounding_1.roundNumberToPrecision)(12.12345678)).toBe(12.12);
|
|
30
|
-
expect((0, rounding_1.roundNumberToPrecision)(123.12345678)).toBe(123.1);
|
|
31
|
-
expect((0, rounding_1.roundNumberToPrecision)(12345.12345678)).toBe(12350);
|
|
32
|
-
expect((0, rounding_1.roundNumberToPrecision)(1.234567891010111213e21)).toBe(1.235e+21);
|
|
33
|
-
expect((0, rounding_1.roundNumberToPrecision)(0.0000456789, 2)).toBe(0.000046);
|
|
34
|
-
expect((0, rounding_1.roundNumberToPrecision)(12345.12345678, 2)).toBe(12000);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('roundNumberToFixedPrecision (private)', () => {
|
|
38
|
-
test('rounds a number to N significant digits, preserving trailing decimals zeros', () => {
|
|
39
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.00045123456)).toBe('0.0004512');
|
|
40
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.0004500000)).toBe('0.0004500');
|
|
41
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.0004500001)).toBe('0.0004500');
|
|
42
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(4.500001e-4)).toBe('0.0004500');
|
|
43
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.00000456012)).toBe('0.000004560');
|
|
44
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.000000456012)).toBe('4.560e-7');
|
|
45
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(0.00000000000450000)).toBe('4.500e-12');
|
|
46
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(1230)).toBe('1230');
|
|
47
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(12321)).toBe('1.232e+4');
|
|
48
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(1230000)).toBe('1.230e+6');
|
|
49
|
-
expect((0, rounding_1.roundNumberToFixedPrecision)(123412.00000456012)).toBe('1.234e+5');
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('roundNumberToDecimalPrecision (private)', () => {
|
|
53
|
-
test('can be configured to exclude the integer part', () => {
|
|
54
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(12345.0012345678)).toBe(12345.001235);
|
|
55
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(67891234)).toBe(67891234);
|
|
56
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(1.23450012345678e+4)).toBe(12345.001235);
|
|
57
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(3.456315667346e6)).toBe(3456315.6673);
|
|
58
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(-12345.12345678)).toBe(-12345.1235);
|
|
59
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(-3.456315667346e6)).toBe(-3456315.6673);
|
|
60
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(9.2345453325e-3)).toBe(0.009235);
|
|
61
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(1.23450012345678e+4)).toBe(12345.001235);
|
|
62
|
-
expect((0, rounding_1.roundNumberToDecimalPrecision)(1.234567891010111213e21)).toBe(1.2345678910101111e+21);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe('roundNumberByMagnitude (private)', () => {
|
|
66
|
-
test('rounds a number based on its magnitude', () => {
|
|
67
|
-
expect((0, rounding_1.roundNumberByMagnitude)(123456.789)).toBe(123457);
|
|
68
|
-
expect((0, rounding_1.roundNumberByMagnitude)(100.789)).toBe(100.8);
|
|
69
|
-
expect((0, rounding_1.roundNumberByMagnitude)(7.12345678)).toBe(7.123);
|
|
70
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.0000456789)).toBe(0.00004568);
|
|
71
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1.345678910111213e-21)).toBe(1.346e-21);
|
|
72
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.0000000000000123456789)).toBe(1.235e-14);
|
|
73
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.00000000123456789)).toBe(1.235e-9);
|
|
74
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.0000123456789)).toBe(0.00001235);
|
|
75
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.000123456789)).toBe(0.0001235);
|
|
76
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.000123756789)).toBe(0.0001238);
|
|
77
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.00123456789)).toBe(0.001235);
|
|
78
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.0123456789)).toBe(0.01235);
|
|
79
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.123456789)).toBe(0.1235);
|
|
80
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1.123456789)).toBe(1.123);
|
|
81
|
-
expect((0, rounding_1.roundNumberByMagnitude)(10.123456789)).toBe(10.12);
|
|
82
|
-
expect((0, rounding_1.roundNumberByMagnitude)(100.123456789)).toBe(100.1);
|
|
83
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1000.123456789)).toBe(1000);
|
|
84
|
-
expect((0, rounding_1.roundNumberByMagnitude)(10000.123456789)).toBe(10000);
|
|
85
|
-
expect((0, rounding_1.roundNumberByMagnitude)(9999.123456789)).toBe(9999);
|
|
86
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1000)).toBe(1000);
|
|
87
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1.234567891010111213e21)).toBe(1.2345678910101111e+21);
|
|
88
|
-
expect((0, rounding_1.roundNumberByMagnitude)(123e21)).toBe(1.23e+23);
|
|
89
|
-
expect((0, rounding_1.roundNumberByMagnitude)(0.123456789, 2)).toBe(0.12);
|
|
90
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1.123456789, 2)).toBe(1.1);
|
|
91
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 2)).toBe(12);
|
|
92
|
-
});
|
|
93
|
-
test('Never rounds the integer part (OW-12391)', () => {
|
|
94
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789)).toBe(1234);
|
|
95
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 6)).toBe(1234.12);
|
|
96
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 5)).toBe(1234.1);
|
|
97
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 4)).toBe(1234);
|
|
98
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 3)).toBe(1234);
|
|
99
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 2)).toBe(1234);
|
|
100
|
-
expect((0, rounding_1.roundNumberByMagnitude)(1234.123456789, 1)).toBe(1234);
|
|
101
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789)).toBe(12.12);
|
|
102
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 6)).toBe(12.1235);
|
|
103
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 5)).toBe(12.123);
|
|
104
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 4)).toBe(12.12);
|
|
105
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 3)).toBe(12.1);
|
|
106
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 2)).toBe(12);
|
|
107
|
-
expect((0, rounding_1.roundNumberByMagnitude)(12.123456789, 1)).toBe(12);
|
|
108
|
-
});
|
|
109
|
-
test('Compare old and new implementations for equivalence', () => {
|
|
110
|
-
const n = 4;
|
|
111
|
-
const oldImplementation = (value) => (Number(value.toExponential(n - 1).toString()));
|
|
112
|
-
const newImplementation = (value) => Number(value.toPrecision(n));
|
|
113
|
-
expect(oldImplementation(0.0012345)).toBe(0.001234);
|
|
114
|
-
expect(newImplementation(0.0012345)).toBe(0.001234);
|
|
115
|
-
expect(oldImplementation(0.12345)).toBe(0.1235);
|
|
116
|
-
expect(newImplementation(0.12345)).toBe(0.1235);
|
|
117
|
-
expect(oldImplementation(1.12345)).toBe(1.123);
|
|
118
|
-
expect(newImplementation(1.12345)).toBe(1.123);
|
|
119
|
-
expect(oldImplementation(12.12345)).toBe(12.12);
|
|
120
|
-
expect(newImplementation(12.12345)).toBe(12.12);
|
|
121
|
-
expect(oldImplementation(1212.12345)).toBe(1212);
|
|
122
|
-
expect(newImplementation(1212.12345)).toBe(1212);
|
|
123
|
-
expect(oldImplementation(12126.12345)).toBe(12130);
|
|
124
|
-
expect(newImplementation(12126.12345)).toBe(12130);
|
|
125
|
-
expect(oldImplementation(1212678.12345)).toBe(1213000);
|
|
126
|
-
expect(newImplementation(1212678.12345)).toBe(1213000);
|
|
127
|
-
expect(oldImplementation(12.123456789)).toBe(12.12);
|
|
128
|
-
expect(newImplementation(12.123456789)).toBe(12.12);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('roundNumberByRange (private)', () => {
|
|
132
|
-
test('shows more significant digits when the range is small and close to the value', () => {
|
|
133
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, 1.2345678, 1.2345679)).toBe(1.1234568);
|
|
134
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, 1.2346, 1.2347)).toBe(1.12346);
|
|
135
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, 0, 10)).toBe(1.1235);
|
|
136
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, -1e5, 1e5)).toBe(1.1235);
|
|
137
|
-
expect((0, rounding_1.roundNumberByRange)(0.123456789, 0.1, 0.2)).toBe(0.1235);
|
|
138
|
-
expect((0, rounding_1.roundNumberByRange)(0.0123456789, 0.01, 0.02)).toBe(0.0123);
|
|
139
|
-
expect((0, rounding_1.roundNumberByRange)(0.0123456789, 0.0123457, 0.0123458)).toBe(0.0123457);
|
|
140
|
-
expect((0, rounding_1.roundNumberByRange)(0.00123456789, 0.001, 0.002)).toBe(0.0012);
|
|
141
|
-
expect((0, rounding_1.roundNumberByRange)(0.00123456789, 0.00123457, 0.00123458)).toBe(0.00123457);
|
|
142
|
-
expect((0, rounding_1.roundNumberByRange)(0.000123456789, 0.0001, 0.0002)).toBe(0.0001);
|
|
143
|
-
expect((0, rounding_1.roundNumberByRange)(0.000123456789, 0.000123457, 0.000123458)).toBe(0.000123457);
|
|
144
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.00001, 0.00002)).toBe(0.00001);
|
|
145
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.0000123457, 0.0000123458)).toBe(0.0000123457);
|
|
146
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.000123457, 0.000123458)).toBe(0.000012346);
|
|
147
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.00123457, 0.00123458)).toBe(0.00001235);
|
|
148
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.0123457, 0.0123458)).toBe(0.0000123);
|
|
149
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 0.123457, 0.123458)).toBe(0.000012);
|
|
150
|
-
expect((0, rounding_1.roundNumberByRange)(0.0000123456789, 1, 2)).toBe(0);
|
|
151
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, -1e5, 1e5, 0)).toBe(1);
|
|
152
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, -1e5, 1e5, 1)).toBe(1.1);
|
|
153
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, -1e5, 1e5, 2)).toBe(1.12);
|
|
154
|
-
expect((0, rounding_1.roundNumberByRange)(1.123456789, -1e5, 1e5, 3)).toBe(1.123);
|
|
155
|
-
});
|
|
156
|
-
test('handles edge-cases', () => {
|
|
157
|
-
expect((0, rounding_1.roundNumberByRange)(1.2345678, 1.2345678, 1.2345678)).toBe(1.2345678);
|
|
158
|
-
expect((0, rounding_1.roundNumberByRange)(0.300123456789, 0.3, (0.1 + 0.2))).toBe(0.300123456789);
|
|
159
|
-
expect((0, rounding_1.roundNumberByRange)(0.3, (0.1 + 0.2), 0.3)).toBe(0.3);
|
|
160
|
-
expect((0, rounding_1.roundNumberByRange)(1.23456789, 10, 0)).toBe(1.23456789);
|
|
161
|
-
expect((0, rounding_1.roundNumberByRange)(0.300123456789, (0.1 + 0.2), 0.3)).toBe(0.300123456789);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
describe('round', () => {
|
|
165
|
-
test('rounds values to N decimal places', () => {
|
|
166
|
-
expect((0, rounding_1.round)(1.234567)).toBe(1.2346);
|
|
167
|
-
expect((0, rounding_1.round)(1.234567, 3)).toBe(1.235);
|
|
168
|
-
});
|
|
169
|
-
test('does not append trailing 0s', () => {
|
|
170
|
-
expect((0, rounding_1.round)(1, 3)).toBe(1);
|
|
171
|
-
expect((0, rounding_1.round)(1.1, 3)).toBe(1.1);
|
|
172
|
-
});
|
|
173
|
-
test('handles stringified numbers', () => {
|
|
174
|
-
expect((0, rounding_1.round)('1.234567', 3)).toBe('1.235');
|
|
175
|
-
expect((0, rounding_1.round)('1.', 3)).toBe('1.');
|
|
176
|
-
expect((0, rounding_1.round)('1,', 3)).toBe('1,');
|
|
177
|
-
});
|
|
178
|
-
test('handles comma decimals', () => {
|
|
179
|
-
expect((0, rounding_1.round)('1,234567', 3)).toBe('1.235');
|
|
180
|
-
});
|
|
181
|
-
test('handles numbers with units', () => {
|
|
182
|
-
expect((0, rounding_1.round)('1.234567|m', 3)).toBe('1.235|m');
|
|
183
|
-
expect((0, rounding_1.round)('1.234567|kg/m3', 3)).toBe('1.235|kg/m3');
|
|
184
|
-
expect((0, rounding_1.round)('1.234567|badUnit/moo', 3)).toBe('1.234567|badUnit/moo');
|
|
185
|
-
});
|
|
186
|
-
test('handles fractions', () => {
|
|
187
|
-
expect((0, rounding_1.round)('1/3', 3)).toBe('0.333');
|
|
188
|
-
expect((0, rounding_1.round)('1/3|m', 3)).toBe('0.333|m');
|
|
189
|
-
});
|
|
190
|
-
test('handles scientific notation', () => {
|
|
191
|
-
expect((0, rounding_1.round)('1.1e-2', 3)).toBe('0.011');
|
|
192
|
-
expect((0, rounding_1.round)('1.1e-2|m', 3)).toBe('0.011|m');
|
|
193
|
-
expect((0, rounding_1.round)('1.1e-9', 12)).toBe('1.1e-9');
|
|
194
|
-
expect((0, rounding_1.round)('1.1e-9|m', 12)).toBe('1.1e-9|m');
|
|
195
|
-
});
|
|
196
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
197
|
-
expect((0, rounding_1.round)(null, 2)).toBe(null);
|
|
198
|
-
expect((0, rounding_1.round)(NaN, 2)).toBe(NaN);
|
|
199
|
-
expect((0, rounding_1.round)(undefined, 2)).toBe(undefined);
|
|
200
|
-
expect((0, rounding_1.round)(Infinity, 2)).toBe(Infinity);
|
|
201
|
-
expect((0, rounding_1.round)(-Infinity, 2)).toBe(-Infinity);
|
|
202
|
-
expect((0, rounding_1.round)('', 2)).toBe('');
|
|
203
|
-
expect((0, rounding_1.round)('foobar', 2)).toBe('foobar');
|
|
204
|
-
expect((0, rounding_1.round)('|m', 2)).toBe('|m');
|
|
205
|
-
});
|
|
206
|
-
test('handles small numbers OW-17645', () => {
|
|
207
|
-
expect((0, rounding_1.round)(0.0000002, 9)).toBe(0.0000002);
|
|
208
|
-
expect((0, rounding_1.round)('0.0000002', 9)).toBe('0.0000002');
|
|
209
|
-
expect((0, rounding_1.round)('0.0000002|m', 9)).toBe('0.0000002|m');
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
describe('roundToPrecision', () => {
|
|
213
|
-
test('rounds a number to N significant digits', () => {
|
|
214
|
-
expect((0, rounding_1.roundToPrecision)(0.0000456789)).toBe(0.00004568);
|
|
215
|
-
expect((0, rounding_1.roundToPrecision)('0.0000456789')).toBe('0.00004568');
|
|
216
|
-
expect((0, rounding_1.roundToPrecision)('0.0000456789|m')).toBe('0.00004568|m');
|
|
217
|
-
});
|
|
218
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
219
|
-
expect((0, rounding_1.roundToPrecision)(null)).toBe(null);
|
|
220
|
-
expect((0, rounding_1.roundToPrecision)(NaN)).toBe(NaN);
|
|
221
|
-
expect((0, rounding_1.roundToPrecision)(undefined)).toBe(undefined);
|
|
222
|
-
expect((0, rounding_1.roundToPrecision)(Infinity)).toBe(Infinity);
|
|
223
|
-
expect((0, rounding_1.roundToPrecision)(-Infinity)).toBe(-Infinity);
|
|
224
|
-
expect((0, rounding_1.roundToPrecision)('')).toBe('');
|
|
225
|
-
expect((0, rounding_1.roundToPrecision)('foobar')).toBe('foobar');
|
|
226
|
-
expect((0, rounding_1.roundToPrecision)('|m')).toBe('|m');
|
|
227
|
-
});
|
|
228
|
-
test('handles small numbers OW-17645', () => {
|
|
229
|
-
expect((0, rounding_1.roundToPrecision)(0.0000002)).toBe(0.0000002);
|
|
230
|
-
expect((0, rounding_1.roundToPrecision)('0.0000002')).toBe('0.0000002');
|
|
231
|
-
expect((0, rounding_1.roundToPrecision)('0.0000002|m')).toBe('0.0000002|m');
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
describe('roundToDecimalPrecision', () => {
|
|
235
|
-
test('rounds to N significant digits, not including the integer part', () => {
|
|
236
|
-
expect((0, rounding_1.roundToDecimalPrecision)(0.00000000000456789)).toBe(4.568e-12);
|
|
237
|
-
expect((0, rounding_1.roundToDecimalPrecision)(0.0000456789)).toBe(0.00004568);
|
|
238
|
-
expect((0, rounding_1.roundToDecimalPrecision)(0.0123456789)).toBe(0.01235);
|
|
239
|
-
expect((0, rounding_1.roundToDecimalPrecision)(-0.0123456789)).toBe(-0.01235);
|
|
240
|
-
expect((0, rounding_1.roundToDecimalPrecision)(1)).toBe(1);
|
|
241
|
-
expect((0, rounding_1.roundToDecimalPrecision)(10)).toBe(10);
|
|
242
|
-
expect((0, rounding_1.roundToDecimalPrecision)(-10)).toBe(-10);
|
|
243
|
-
expect((0, rounding_1.roundToDecimalPrecision)(10.01)).toBe(10.01);
|
|
244
|
-
expect((0, rounding_1.roundToDecimalPrecision)(12.12345678)).toBe(12.1235);
|
|
245
|
-
expect((0, rounding_1.roundToDecimalPrecision)(123.12345678)).toBe(123.1235);
|
|
246
|
-
expect((0, rounding_1.roundToDecimalPrecision)(12345.12345678)).toBe(12345.1235);
|
|
247
|
-
expect((0, rounding_1.roundToDecimalPrecision)(0.0000456789, 2)).toBe(0.000046);
|
|
248
|
-
expect((0, rounding_1.roundToDecimalPrecision)(12345.12345678, 2)).toBe(12345.12);
|
|
249
|
-
});
|
|
250
|
-
test('bug', () => {
|
|
251
|
-
expect((0, rounding_1.roundToDecimalPrecision)(12.00012345678)).toBe(12.0001235);
|
|
252
|
-
});
|
|
253
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
254
|
-
expect((0, rounding_1.roundToDecimalPrecision)(null)).toBe(null);
|
|
255
|
-
expect((0, rounding_1.roundToDecimalPrecision)(NaN)).toBe(NaN);
|
|
256
|
-
expect((0, rounding_1.roundToDecimalPrecision)(undefined)).toBe(undefined);
|
|
257
|
-
expect((0, rounding_1.roundToDecimalPrecision)(Infinity)).toBe(Infinity);
|
|
258
|
-
expect((0, rounding_1.roundToDecimalPrecision)(-Infinity)).toBe(-Infinity);
|
|
259
|
-
expect((0, rounding_1.roundToDecimalPrecision)('')).toBe('');
|
|
260
|
-
expect((0, rounding_1.roundToDecimalPrecision)('foobar')).toBe('foobar');
|
|
261
|
-
expect((0, rounding_1.roundToDecimalPrecision)('|m')).toBe('|m');
|
|
262
|
-
});
|
|
263
|
-
test('handles small numbers OW-17645', () => {
|
|
264
|
-
expect((0, rounding_1.roundToDecimalPrecision)(0.0000002)).toBe(0.0000002);
|
|
265
|
-
expect((0, rounding_1.roundToDecimalPrecision)('0.0000002')).toBe('0.0000002');
|
|
266
|
-
expect((0, rounding_1.roundToDecimalPrecision)('0.0000002|m')).toBe('0.0000002|m');
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
describe('roundByMagnitude', () => {
|
|
270
|
-
test('rounds a number based on its magnitude', () => {
|
|
271
|
-
expect((0, rounding_1.roundByMagnitude)(1.234567)).toBe(1.235);
|
|
272
|
-
expect((0, rounding_1.roundByMagnitude)('1.234567')).toBe('1.235');
|
|
273
|
-
expect((0, rounding_1.roundByMagnitude)('1.234567|m')).toBe('1.235|m');
|
|
274
|
-
});
|
|
275
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
276
|
-
expect((0, rounding_1.roundByMagnitude)(null)).toBe(null);
|
|
277
|
-
expect((0, rounding_1.roundByMagnitude)(NaN)).toBe(NaN);
|
|
278
|
-
expect((0, rounding_1.roundByMagnitude)(undefined)).toBe(undefined);
|
|
279
|
-
expect((0, rounding_1.roundByMagnitude)(Infinity)).toBe(Infinity);
|
|
280
|
-
expect((0, rounding_1.roundByMagnitude)(-Infinity)).toBe(-Infinity);
|
|
281
|
-
expect((0, rounding_1.roundByMagnitude)('')).toBe('');
|
|
282
|
-
expect((0, rounding_1.roundByMagnitude)('foobar')).toBe('foobar');
|
|
283
|
-
expect((0, rounding_1.roundByMagnitude)('|m')).toBe('|m');
|
|
284
|
-
});
|
|
285
|
-
test('handles small numbers OW-17645', () => {
|
|
286
|
-
expect((0, rounding_1.roundByMagnitude)(0.0000002)).toBe(0.0000002);
|
|
287
|
-
expect((0, rounding_1.roundByMagnitude)('0.0000002')).toBe('0.0000002');
|
|
288
|
-
expect((0, rounding_1.roundByMagnitude)('0.0000002|m')).toBe('0.0000002|m');
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
describe('roundByMagnitudeToFixed', () => {
|
|
292
|
-
test('test cases from Ida', () => {
|
|
293
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.131214)).toBe('0.1312');
|
|
294
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.13101)).toBe('0.1310');
|
|
295
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.000010021)).toBe('0.00001002');
|
|
296
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.000010000)).toBe('0.00001000');
|
|
297
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.1231234)).toBe('1.123');
|
|
298
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.120021)).toBe('1.120');
|
|
299
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.0001)).toBe('1.000');
|
|
300
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.12345)).toBe('12.12');
|
|
301
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.012)).toBe('12.01');
|
|
302
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.10000)).toBe('12.10');
|
|
303
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(123.109)).toBe('123.1');
|
|
304
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(123.011)).toBe('123.0');
|
|
305
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1233.12)).toBe('1233');
|
|
306
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1233.00)).toBe('1233');
|
|
307
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1230)).toBe('1230');
|
|
308
|
-
});
|
|
309
|
-
test('compare with roundByMagnitude', () => {
|
|
310
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(123456.789)).toBe('123457');
|
|
311
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(100.789)).toBe('100.8');
|
|
312
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(7.12345678)).toBe('7.123');
|
|
313
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.0000456789)).toBe('0.00004568');
|
|
314
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.345678910111213e-21)).toBe(String(1.346e-21));
|
|
315
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.0000000000000123456789)).toBe(String(1.235e-14));
|
|
316
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.00000000123456789)).toBe(String(1.235e-9));
|
|
317
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.0000123456789)).toBe('0.00001235');
|
|
318
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.000123456789)).toBe('0.0001235');
|
|
319
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.000123756789)).toBe('0.0001238');
|
|
320
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.00123456789)).toBe('0.001235');
|
|
321
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.0123456789)).toBe('0.01235');
|
|
322
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.123456789)).toBe('0.1235');
|
|
323
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.123456789)).toBe('1.123');
|
|
324
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(10.123456789)).toBe('10.12');
|
|
325
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(100.123456789)).toBe('100.1');
|
|
326
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1000.123456789)).toBe('1000');
|
|
327
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(10000.123456789)).toBe('10000');
|
|
328
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(9999.123456789)).toBe('9999');
|
|
329
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.234567891010111213e21)).toBe(String(1.2345678910101111e+21));
|
|
330
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(123e21)).toBe(String(1.23e+23));
|
|
331
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.123456789, 2)).toBe('0.12');
|
|
332
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.123456789, 2)).toBe('1.1');
|
|
333
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 2)).toBe('12');
|
|
334
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789)).toBe('1234');
|
|
335
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 6)).toBe('1234.12');
|
|
336
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 5)).toBe('1234.1');
|
|
337
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 4)).toBe('1234');
|
|
338
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 3)).toBe('1234');
|
|
339
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 2)).toBe('1234');
|
|
340
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1234.123456789, 1)).toBe('1234');
|
|
341
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789)).toBe('12.12');
|
|
342
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 6)).toBe('12.1235');
|
|
343
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 5)).toBe('12.123');
|
|
344
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 4)).toBe('12.12');
|
|
345
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 3)).toBe('12.1');
|
|
346
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 2)).toBe('12');
|
|
347
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.123456789, 1)).toBe('12');
|
|
348
|
-
});
|
|
349
|
-
test('handles different input formats', () => {
|
|
350
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.230067)).toBe('1.230');
|
|
351
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.230067')).toBe('1.230');
|
|
352
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1,230067')).toBe('1.230');
|
|
353
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345,230067')).toBe('12345');
|
|
354
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.230067|m')).toBe('1.230|m');
|
|
355
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.230067e-5)).toBe('0.00001230');
|
|
356
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.230067e+3)).toBe('1230');
|
|
357
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.230067e-5|ft')).toBe('0.00001230|ft');
|
|
358
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.230067e+3|ft')).toBe('1230|ft');
|
|
359
|
-
});
|
|
360
|
-
test('extra test cases (range of values)', () => {
|
|
361
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12345)).toBe('12345');
|
|
362
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12345.12300)).toBe('12345');
|
|
363
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12345.000)).toBe('12345');
|
|
364
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1200)).toBe('1200');
|
|
365
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1200.0)).toBe('1200');
|
|
366
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1200.0001)).toBe('1200');
|
|
367
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12)).toBe('12.00');
|
|
368
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12)).toBe('12.00');
|
|
369
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.0)).toBe('12.00');
|
|
370
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(12.00001)).toBe('12.00');
|
|
371
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(1.0)).toBe('1.000');
|
|
372
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.1)).toBe('0.1000');
|
|
373
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(0.0100001)).toBe('0.01000');
|
|
374
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345')).toBe('12345');
|
|
375
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345.12300')).toBe('12345');
|
|
376
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345.000')).toBe('12345');
|
|
377
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200')).toBe('1200');
|
|
378
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200.0')).toBe('1200');
|
|
379
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200.0001')).toBe('1200');
|
|
380
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12')).toBe('12.00');
|
|
381
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12')).toBe('12.00');
|
|
382
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12.0')).toBe('12.00');
|
|
383
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12.00001')).toBe('12.00');
|
|
384
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.0')).toBe('1.000');
|
|
385
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('0.1')).toBe('0.1000');
|
|
386
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('0.0100001')).toBe('0.01000');
|
|
387
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345|kg/s')).toBe('12345|kg/s');
|
|
388
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345.12300|kg/s')).toBe('12345|kg/s');
|
|
389
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12345.000|kg/s')).toBe('12345|kg/s');
|
|
390
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200|kg/s')).toBe('1200|kg/s');
|
|
391
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200.0|kg/s')).toBe('1200|kg/s');
|
|
392
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1200.0001|kg/s')).toBe('1200|kg/s');
|
|
393
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12|kg/s')).toBe('12.00|kg/s');
|
|
394
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12|kg/s')).toBe('12.00|kg/s');
|
|
395
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12.0|kg/s')).toBe('12.00|kg/s');
|
|
396
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('12.00001|kg/s')).toBe('12.00|kg/s');
|
|
397
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('1.0|kg/s')).toBe('1.000|kg/s');
|
|
398
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('0.1|kg/s')).toBe('0.1000|kg/s');
|
|
399
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('0.0100001|kg/s')).toBe('0.01000|kg/s');
|
|
400
|
-
});
|
|
401
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
402
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(null)).toBe(null);
|
|
403
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(NaN)).toBe(NaN);
|
|
404
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(undefined)).toBe(undefined);
|
|
405
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(Infinity)).toBe(Infinity);
|
|
406
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)(-Infinity)).toBe(-Infinity);
|
|
407
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('')).toBe('');
|
|
408
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('foobar')).toBe('foobar');
|
|
409
|
-
expect((0, rounding_1.roundByMagnitudeToFixed)('|m')).toBe('|m');
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
describe('roundByRange', () => {
|
|
413
|
-
test('rounds a number based on size in a range', () => {
|
|
414
|
-
expect((0, rounding_1.roundByRange)(1.23456789, 0, 10)).toBe(1.2346);
|
|
415
|
-
expect((0, rounding_1.roundByRange)('1.23456789', 0, 10)).toBe('1.2346');
|
|
416
|
-
expect((0, rounding_1.roundByRange)('1.23456789|m', 0, 10)).toBe('1.2346|m');
|
|
417
|
-
});
|
|
418
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
419
|
-
expect((0, rounding_1.roundByRange)(null, 0, 10)).toBe(null);
|
|
420
|
-
expect((0, rounding_1.roundByRange)(NaN, 0, 10)).toBe(NaN);
|
|
421
|
-
expect((0, rounding_1.roundByRange)(undefined, 0, 10)).toBe(undefined);
|
|
422
|
-
expect((0, rounding_1.roundByRange)(Infinity, 0, 10)).toBe(Infinity);
|
|
423
|
-
expect((0, rounding_1.roundByRange)(-Infinity, 0, 10)).toBe(-Infinity);
|
|
424
|
-
expect((0, rounding_1.roundByRange)('', 0, 10)).toBe('');
|
|
425
|
-
expect((0, rounding_1.roundByRange)('foobar', 0, 10)).toBe('foobar');
|
|
426
|
-
expect((0, rounding_1.roundByRange)('|m', 0, 10)).toBe('|m');
|
|
427
|
-
});
|
|
428
|
-
test('handles small numbers OW-17645', () => {
|
|
429
|
-
expect((0, rounding_1.roundByRange)(0.0000002, 0, 0.0000003)).toBe(0.0000002);
|
|
430
|
-
expect((0, rounding_1.roundByRange)('0.0000002', 0, 0.0000003)).toBe('0.0000002');
|
|
431
|
-
expect((0, rounding_1.roundByRange)('0.0000002|m', 0, 0.0000003)).toBe('0.0000002|m');
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
describe('roundToFixed', () => {
|
|
435
|
-
test('rounds numeric values to fixed precision', () => {
|
|
436
|
-
expect((0, rounding_1.roundToFixed)(1.1)).toBe('1.1000');
|
|
437
|
-
expect((0, rounding_1.roundToFixed)(12345678.12345678)).toBe('12345678.1235');
|
|
438
|
-
expect((0, rounding_1.roundToFixed)(1.12456e3)).toBe('1124.5600');
|
|
439
|
-
expect((0, rounding_1.roundToFixed)(0.016, 3)).toBe('0.016');
|
|
440
|
-
expect((0, rounding_1.roundToFixed)(0.016, 2)).toBe('0.02');
|
|
441
|
-
expect((0, rounding_1.roundToFixed)(0.016, 1)).toBe('0.0');
|
|
442
|
-
expect((0, rounding_1.roundToFixed)('1.12456e3')).toBe('1124.5600');
|
|
443
|
-
expect((0, rounding_1.roundToFixed)('1.12456e+3')).toBe('1124.5600');
|
|
444
|
-
expect((0, rounding_1.roundToFixed)('1.12456e-3')).toBe('0.0011');
|
|
445
|
-
expect((0, rounding_1.roundToFixed)('1.1')).toBe('1.1000');
|
|
446
|
-
expect((0, rounding_1.roundToFixed)('1.1|m')).toBe('1.1000|m');
|
|
447
|
-
});
|
|
448
|
-
test('handles bad / impossible inputs by returning input', () => {
|
|
449
|
-
expect((0, rounding_1.roundToFixed)(null)).toBe(null);
|
|
450
|
-
expect((0, rounding_1.roundToFixed)(NaN)).toBe(NaN);
|
|
451
|
-
expect((0, rounding_1.roundToFixed)(undefined)).toBe(undefined);
|
|
452
|
-
expect((0, rounding_1.roundToFixed)(Infinity)).toBe(Infinity);
|
|
453
|
-
expect((0, rounding_1.roundToFixed)(-Infinity)).toBe(-Infinity);
|
|
454
|
-
expect((0, rounding_1.roundToFixed)('')).toBe('');
|
|
455
|
-
expect((0, rounding_1.roundToFixed)('foobar')).toBe('foobar');
|
|
456
|
-
expect((0, rounding_1.roundToFixed)('|m')).toBe('|m');
|
|
457
|
-
});
|
|
458
|
-
test('handles small numbers OW-17645', () => {
|
|
459
|
-
expect((0, rounding_1.roundToFixed)(0.0000002, 9)).toBe('0.000000200');
|
|
460
|
-
expect((0, rounding_1.roundToFixed)('0.0000002', 9)).toBe('0.000000200');
|
|
461
|
-
expect((0, rounding_1.roundToFixed)('0.0000002|m', 9)).toBe('0.000000200|m');
|
|
462
|
-
});
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
describe('Deprecated rounding (only for comparing pre-existing implementations)', () => {
|
|
466
|
-
describe('roundByToPretty', () => {
|
|
467
|
-
test('rounds numbers based on the magnitude', () => {
|
|
468
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(1.345678910111213e-21)).toBe('1.346e-21');
|
|
469
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.0000000000000123456789)).toBe('1.235e-14');
|
|
470
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.00000000123456789)).toBe('1.235e-9');
|
|
471
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.0000123456789)).toBe('0.00001235');
|
|
472
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.000123456789)).toBe('0.0001235');
|
|
473
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.000123756789)).toBe('0.0001238');
|
|
474
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.00123456789)).toBe('0.001235');
|
|
475
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.0123456789)).toBe('0.01235');
|
|
476
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(0.123456789)).toBe('0.1235');
|
|
477
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(1.123456789)).toBe('1.123');
|
|
478
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(10.123456789)).toBe('10.12');
|
|
479
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(100.123456789)).toBe('100.1');
|
|
480
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(1000.123456789)).toBe('1000');
|
|
481
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(10000.123456789)).toBe('10000');
|
|
482
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(9999.123456789)).toBe('9999');
|
|
483
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(1000)).toBe('1000');
|
|
484
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(1.234567891010111213e21)).toBe('1.2345678910101111e+21');
|
|
485
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(123e21)).toBe('1.23e+23');
|
|
486
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(12.123456789)).toBe('12.12');
|
|
487
|
-
expect((0, deprecated_rounding_1.roundByToPretty)(8999.123456789)).toBe('8999');
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
describe('roundByAdjustDecimals', () => {
|
|
491
|
-
test('rounds numbers based on the magnitude', () => {
|
|
492
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(1.345678910111213e-21)).toBe('0.0000');
|
|
493
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.0000000000000123456789)).toBe('0.0000000');
|
|
494
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.00000000123456789)).toBe('0.000000001235');
|
|
495
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.0000123456789)).toBe(0.0000123);
|
|
496
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.000123456789)).toBe(0.000123);
|
|
497
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.000123756789)).toBe(0.000124);
|
|
498
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.00123456789)).toBe(0.00123);
|
|
499
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.0123456789)).toBe(0.0123);
|
|
500
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(0.123456789)).toBe(0.123);
|
|
501
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(1.123456789)).toBe(1.1235);
|
|
502
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(10.123456789)).toBe(10.1235);
|
|
503
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(100.123456789)).toBe(100.12);
|
|
504
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(1000.123456789)).toBe(1000.12);
|
|
505
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(10000.123456789)).toBe(10000.12);
|
|
506
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(1000)).toBe(1000);
|
|
507
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(1.234567891010111213e21)).toBe(1.2345678910101111e+21);
|
|
508
|
-
expect((0, deprecated_rounding_1.roundByAdjustDecimals)(123e21)).toBe(1.23e+23);
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
describe('roundByGetNumberOfDigitsToShow', () => {
|
|
512
|
-
test('rounds numbers based on the magnitude', () => {
|
|
513
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1.345678910111213e-21)).toBe(0);
|
|
514
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1.345678910111213e-4)).toBe(0.0001346);
|
|
515
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.0000000000000123456789)).toBe(1.235e-14);
|
|
516
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.00000000123456789)).toBe(1.235e-9);
|
|
517
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.0000123456789)).toBe(0.00001235);
|
|
518
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.000123456789)).toBe(0.0001235);
|
|
519
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.000123756789)).toBe(0.0001238);
|
|
520
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.00123456789)).toBe(0.001235);
|
|
521
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.0123456789)).toBe(0.01235);
|
|
522
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(0.123456789)).toBe(0.1235);
|
|
523
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1.123456789)).toBe(1.1235);
|
|
524
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(10.123456789)).toBe(10.1235);
|
|
525
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(100.123456789)).toBe(100.1235);
|
|
526
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1000.123456789)).toBe(1000.1235);
|
|
527
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(10000.123456789)).toBe(10000.1235);
|
|
528
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1000)).toBe(1000);
|
|
529
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(1.234567891010111213e21)).toBe(1.2345678910101111e+21);
|
|
530
|
-
expect((0, deprecated_rounding_1.roundByGetNumberOfDigitsToShow)(123e21)).toBe(1.23e+23);
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
describe('getNDecimals', () => {
|
|
534
|
-
test('rounds numbers based on the magnitude', () => {
|
|
535
|
-
expect((0, deprecated_rounding_1.getNDecimals)(0.000000123456789, 3)).toBe(1.23e-7);
|
|
536
|
-
expect((0, deprecated_rounding_1.getNDecimals)(0.000123456789, 3)).toBe(0.000123);
|
|
537
|
-
expect((0, deprecated_rounding_1.getNDecimals)(10000.123456789, 3)).toBe(10000.123);
|
|
538
|
-
expect((0, deprecated_rounding_1.getNDecimals)(10000.123456789, 7)).toBe(10000.1234568);
|
|
539
|
-
expect((0, deprecated_rounding_1.getNDecimals)(100000000000.123456789, 3)).toBe(100000000000.123);
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
//# sourceMappingURL=rounding.test.js.map
|