@keplr-wallet/unit 0.9.10-rc.0 → 0.9.11-rc.3
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/build/coin-pretty.d.ts +13 -3
- package/build/coin-pretty.js +36 -25
- package/build/coin-pretty.js.map +1 -1
- package/build/coin-pretty.spec.js +194 -9
- package/build/coin-pretty.spec.js.map +1 -1
- package/build/coin-utils.js +8 -4
- package/build/coin-utils.js.map +1 -1
- package/build/coin-utils.spec.js +16 -0
- package/build/coin-utils.spec.js.map +1 -1
- package/build/coin.js +1 -1
- package/build/coin.js.map +1 -1
- package/build/coin.spec.js +15 -0
- package/build/coin.spec.js.map +1 -1
- package/build/dec-utils.d.ts +8 -1
- package/build/dec-utils.js +22 -20
- package/build/dec-utils.js.map +1 -1
- package/build/dec-utils.spec.js +19 -0
- package/build/dec-utils.spec.js.map +1 -1
- package/build/decimal.d.ts +22 -9
- package/build/decimal.js +102 -29
- package/build/decimal.js.map +1 -1
- package/build/decimal.spec.js +296 -3
- package/build/decimal.spec.js.map +1 -1
- package/build/etc.d.ts +4 -0
- package/build/etc.js +66 -0
- package/build/etc.js.map +1 -0
- package/build/etc.spec.d.ts +1 -0
- package/build/etc.spec.js +66 -0
- package/build/etc.spec.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/int-pretty.d.ts +16 -4
- package/build/int-pretty.js +74 -36
- package/build/int-pretty.js.map +1 -1
- package/build/int-pretty.spec.js +261 -94
- package/build/int-pretty.spec.js.map +1 -1
- package/build/int.d.ts +17 -12
- package/build/int.js +69 -16
- package/build/int.js.map +1 -1
- package/build/int.spec.d.ts +1 -0
- package/build/int.spec.js +161 -0
- package/build/int.spec.js.map +1 -0
- package/build/price-pretty.d.ts +13 -3
- package/build/price-pretty.js +37 -26
- package/build/price-pretty.js.map +1 -1
- package/build/price-pretty.spec.js +59 -2
- package/build/price-pretty.spec.js.map +1 -1
- package/build/rate-pretty.d.ts +57 -0
- package/build/rate-pretty.js +128 -0
- package/build/rate-pretty.js.map +1 -0
- package/build/rate-pretty.spec.d.ts +1 -0
- package/build/rate-pretty.spec.js +38 -0
- package/build/rate-pretty.spec.js.map +1 -0
- package/package.json +3 -3
- package/src/coin-pretty.spec.ts +304 -11
- package/src/coin-pretty.ts +56 -29
- package/src/coin-utils.spec.ts +32 -0
- package/src/coin-utils.ts +12 -4
- package/src/coin.spec.ts +20 -0
- package/src/coin.ts +1 -1
- package/src/dec-utils.spec.ts +39 -0
- package/src/dec-utils.ts +25 -20
- package/src/decimal.spec.ts +361 -3
- package/src/decimal.ts +135 -56
- package/src/etc.spec.ts +73 -0
- package/src/etc.ts +73 -0
- package/src/index.ts +1 -0
- package/src/int-pretty.spec.ts +296 -101
- package/src/int-pretty.ts +87 -34
- package/src/int.spec.ts +212 -0
- package/src/int.ts +94 -26
- package/src/price-pretty.spec.ts +106 -2
- package/src/price-pretty.ts +50 -30
- package/src/rate-pretty.spec.ts +52 -0
- package/src/rate-pretty.ts +165 -0
package/src/int-pretty.spec.ts
CHANGED
@@ -3,82 +3,100 @@ import { Int } from "./int";
|
|
3
3
|
import { Dec } from "./decimal";
|
4
4
|
|
5
5
|
describe("Test IntPretty", () => {
|
6
|
-
it("Test
|
6
|
+
it("Test creation of IntPretty", () => {
|
7
|
+
expect(new IntPretty(new Dec("1.1")).toDec().equals(new Dec("1.1"))).toBe(
|
8
|
+
true
|
9
|
+
);
|
10
|
+
expect(new IntPretty(new Dec("1.1")).maxDecimals(2).toString()).toBe(
|
11
|
+
"1.10"
|
12
|
+
);
|
13
|
+
|
14
|
+
expect(new IntPretty("1.1").toDec().equals(new Dec("1.1"))).toBe(true);
|
15
|
+
expect(new IntPretty("1.1").maxDecimals(2).toString()).toBe("1.10");
|
16
|
+
|
17
|
+
expect(new IntPretty(1.1).toDec().equals(new Dec("1.1"))).toBe(true);
|
18
|
+
expect(new IntPretty(1.1).maxDecimals(2).toString()).toBe("1.10");
|
19
|
+
|
20
|
+
expect(new IntPretty(new Int(1)).toDec().equals(new Dec("1.0"))).toBe(true);
|
21
|
+
expect(new IntPretty(new Int(1)).maxDecimals(2).toString()).toBe("1.00");
|
22
|
+
});
|
23
|
+
|
24
|
+
it("Test the maxDecimals of IntPretty", () => {
|
7
25
|
const params: {
|
8
26
|
arg: Dec | Int;
|
9
|
-
|
27
|
+
maxDecimals: number;
|
10
28
|
dec: Dec;
|
11
29
|
str: string;
|
12
30
|
}[] = [
|
13
31
|
{
|
14
32
|
arg: new Int(0),
|
15
|
-
|
33
|
+
maxDecimals: 0,
|
16
34
|
dec: new Dec(0),
|
17
35
|
str: "0",
|
18
36
|
},
|
19
37
|
{
|
20
38
|
arg: new Dec(0),
|
21
|
-
|
39
|
+
maxDecimals: 0,
|
22
40
|
dec: new Dec(0),
|
23
41
|
str: "0",
|
24
42
|
},
|
25
43
|
{
|
26
44
|
arg: new Int(100),
|
27
|
-
|
45
|
+
maxDecimals: 0,
|
28
46
|
dec: new Dec(100),
|
29
47
|
str: "100",
|
30
48
|
},
|
31
49
|
{
|
32
50
|
arg: new Dec(100),
|
33
|
-
|
51
|
+
maxDecimals: 0,
|
34
52
|
dec: new Dec(100),
|
35
53
|
str: "100",
|
36
54
|
},
|
37
55
|
{
|
38
56
|
arg: new Dec("0.01"),
|
39
|
-
|
57
|
+
maxDecimals: 2,
|
40
58
|
dec: new Dec("0.01"),
|
41
59
|
str: "0.01",
|
42
60
|
},
|
43
61
|
{
|
44
62
|
arg: new Dec("-0.01"),
|
45
|
-
|
63
|
+
maxDecimals: 2,
|
46
64
|
dec: new Dec("-0.01"),
|
47
65
|
str: "-0.01",
|
48
66
|
},
|
49
67
|
{
|
50
68
|
arg: new Dec("1.01"),
|
51
|
-
|
69
|
+
maxDecimals: 2,
|
52
70
|
dec: new Dec("1.01"),
|
53
71
|
str: "1.01",
|
54
72
|
},
|
55
73
|
{
|
56
74
|
arg: new Dec("-1.01"),
|
57
|
-
|
75
|
+
maxDecimals: 2,
|
58
76
|
dec: new Dec("-1.01"),
|
59
77
|
str: "-1.01",
|
60
78
|
},
|
61
79
|
{
|
62
80
|
arg: new Dec("10.01"),
|
63
|
-
|
81
|
+
maxDecimals: 2,
|
64
82
|
dec: new Dec("10.01"),
|
65
83
|
str: "10.01",
|
66
84
|
},
|
67
85
|
{
|
68
86
|
arg: new Dec("-10.01"),
|
69
|
-
|
87
|
+
maxDecimals: 2,
|
70
88
|
dec: new Dec("-10.01"),
|
71
89
|
str: "-10.01",
|
72
90
|
},
|
73
91
|
{
|
74
92
|
arg: new Dec("10.0100"),
|
75
|
-
|
93
|
+
maxDecimals: 2,
|
76
94
|
dec: new Dec("10.01"),
|
77
95
|
str: "10.01",
|
78
96
|
},
|
79
97
|
{
|
80
98
|
arg: new Dec("-10.0100"),
|
81
|
-
|
99
|
+
maxDecimals: 2,
|
82
100
|
dec: new Dec("-10.01"),
|
83
101
|
str: "-10.01",
|
84
102
|
},
|
@@ -86,122 +104,178 @@ describe("Test IntPretty", () => {
|
|
86
104
|
|
87
105
|
for (const param of params) {
|
88
106
|
const pretty = new IntPretty(param.arg);
|
89
|
-
expect(pretty.options.
|
107
|
+
expect(pretty.options.maxDecimals).toBe(param.maxDecimals);
|
90
108
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
91
109
|
expect(pretty.toString()).toBe(param.str);
|
92
110
|
}
|
93
111
|
});
|
94
112
|
|
95
113
|
it("Test modifying the precision of IntPretty", () => {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
114
|
+
const tests: {
|
115
|
+
base: Dec;
|
116
|
+
delta: number;
|
117
|
+
right: boolean;
|
118
|
+
res: Dec;
|
119
|
+
resStr: string;
|
120
|
+
otherTest?: (int: IntPretty) => void;
|
121
|
+
}[] = [
|
122
|
+
{
|
123
|
+
base: new Dec("10.001"),
|
124
|
+
delta: 0,
|
125
|
+
right: false,
|
126
|
+
res: new Dec("10.001"),
|
127
|
+
resStr: "10.001",
|
128
|
+
otherTest: (int) => {
|
129
|
+
expect(int.maxDecimals(4).toString()).toBe("10.0010");
|
130
|
+
},
|
131
|
+
},
|
132
|
+
{
|
133
|
+
base: new Dec("10.001"),
|
134
|
+
delta: 1,
|
135
|
+
right: false,
|
136
|
+
res: new Dec("1.0001"),
|
137
|
+
resStr: "1.000",
|
138
|
+
otherTest: (int) => {
|
139
|
+
expect(int.maxDecimals(4).toString()).toBe("1.0001");
|
140
|
+
},
|
141
|
+
},
|
142
|
+
{
|
143
|
+
base: new Dec("10.001"),
|
144
|
+
delta: 1,
|
145
|
+
right: true,
|
146
|
+
res: new Dec("100.010"),
|
147
|
+
resStr: "100.010",
|
148
|
+
otherTest: (int) => {
|
149
|
+
expect(int.maxDecimals(4).toString()).toBe("100.0100");
|
150
|
+
},
|
151
|
+
},
|
152
|
+
{
|
153
|
+
base: new Dec("10.001"),
|
154
|
+
delta: 6,
|
155
|
+
right: true,
|
156
|
+
res: new Dec("10001000"),
|
157
|
+
resStr: "10,001,000.000",
|
158
|
+
},
|
159
|
+
{
|
160
|
+
base: new Dec("0"),
|
161
|
+
delta: 3,
|
162
|
+
right: false,
|
163
|
+
res: new Dec("0"),
|
164
|
+
resStr: "0",
|
165
|
+
},
|
166
|
+
{
|
167
|
+
base: new Dec("0"),
|
168
|
+
delta: 3,
|
169
|
+
right: true,
|
170
|
+
res: new Dec("0"),
|
171
|
+
resStr: "0",
|
172
|
+
},
|
173
|
+
{
|
174
|
+
base: new Dec("100.01"),
|
175
|
+
delta: 20,
|
176
|
+
right: true,
|
177
|
+
res: new Dec("10001000000000000000000"),
|
178
|
+
resStr: "10,001,000,000,000,000,000,000.00",
|
179
|
+
},
|
180
|
+
{
|
181
|
+
base: new Dec("100.01"),
|
182
|
+
delta: 20,
|
183
|
+
right: false,
|
184
|
+
res: new Dec("0.000000000000000001"),
|
185
|
+
resStr: "0.00",
|
186
|
+
otherTest: (int) => {
|
187
|
+
expect(int.trim(true).toString()).toBe("0");
|
188
|
+
},
|
189
|
+
},
|
190
|
+
];
|
110
191
|
|
111
|
-
|
112
|
-
|
113
|
-
expect(newPretty.toString()).toBe("100.010");
|
192
|
+
for (const test of tests) {
|
193
|
+
let pretty = new IntPretty(test.base);
|
114
194
|
|
115
|
-
|
116
|
-
|
117
|
-
|
195
|
+
if (test.right) {
|
196
|
+
pretty = pretty.moveDecimalPointRight(test.delta);
|
197
|
+
} else {
|
198
|
+
pretty = pretty.moveDecimalPointLeft(test.delta);
|
199
|
+
}
|
118
200
|
|
119
|
-
|
120
|
-
|
121
|
-
expect(newPretty.toString()).toBe("10,001,000.000");
|
201
|
+
expect(pretty.toDec().equals(test.res)).toBeTruthy();
|
202
|
+
expect(pretty.toString()).toBe(test.resStr);
|
122
203
|
|
123
|
-
|
124
|
-
|
125
|
-
|
204
|
+
if (test.otherTest) {
|
205
|
+
test.otherTest(pretty);
|
206
|
+
}
|
207
|
+
}
|
126
208
|
|
127
|
-
|
128
|
-
pretty.
|
129
|
-
}).not.toThrow();
|
209
|
+
for (const test of tests) {
|
210
|
+
let pretty = new IntPretty(test.base);
|
130
211
|
|
131
|
-
|
132
|
-
|
133
|
-
|
212
|
+
if (test.right) {
|
213
|
+
pretty = pretty.decreasePrecision(test.delta);
|
214
|
+
} else {
|
215
|
+
pretty = pretty.increasePrecision(test.delta);
|
216
|
+
}
|
134
217
|
|
135
|
-
|
136
|
-
pretty.
|
137
|
-
}).toThrow();
|
218
|
+
expect(pretty.toDec().equals(test.res)).toBeTruthy();
|
219
|
+
expect(pretty.toString()).toBe(test.resStr);
|
138
220
|
|
139
|
-
|
140
|
-
|
141
|
-
|
221
|
+
if (test.otherTest) {
|
222
|
+
test.otherTest(pretty);
|
223
|
+
}
|
224
|
+
}
|
142
225
|
});
|
143
226
|
|
144
227
|
it("Test the add calcutation of IntPretty", () => {
|
145
228
|
const params: {
|
146
229
|
base: Dec | Int;
|
147
230
|
target: Dec | Int;
|
148
|
-
precision: number;
|
149
231
|
dec: Dec;
|
150
232
|
str: string;
|
151
233
|
}[] = [
|
152
234
|
{
|
153
235
|
base: new Int(0),
|
154
236
|
target: new Int(0),
|
155
|
-
precision: 0,
|
156
237
|
dec: new Dec(0),
|
157
238
|
str: "0",
|
158
239
|
},
|
159
240
|
{
|
160
241
|
base: new Dec(0),
|
161
242
|
target: new Int(0),
|
162
|
-
precision: 0,
|
163
243
|
dec: new Dec(0),
|
164
244
|
str: "0",
|
165
245
|
},
|
166
246
|
{
|
167
247
|
base: new Int(0),
|
168
248
|
target: new Dec(0),
|
169
|
-
precision: 0,
|
170
249
|
dec: new Dec(0),
|
171
250
|
str: "0",
|
172
251
|
},
|
173
252
|
{
|
174
253
|
base: new Int(1),
|
175
254
|
target: new Dec(1),
|
176
|
-
precision: 0,
|
177
255
|
dec: new Dec(2),
|
178
256
|
str: "2",
|
179
257
|
},
|
180
258
|
{
|
181
259
|
base: new Int(1),
|
182
260
|
target: new Dec(-1),
|
183
|
-
precision: 0,
|
184
261
|
dec: new Dec(0),
|
185
262
|
str: "0",
|
186
263
|
},
|
187
264
|
{
|
188
265
|
base: new Int(100),
|
189
266
|
target: new Dec(-1),
|
190
|
-
precision: 0,
|
191
267
|
dec: new Dec("99"),
|
192
268
|
str: "99",
|
193
269
|
},
|
194
270
|
{
|
195
271
|
base: new Dec("100.001"),
|
196
272
|
target: new Dec(-1),
|
197
|
-
precision: 3,
|
198
273
|
dec: new Dec("99.001"),
|
199
274
|
str: "99.001",
|
200
275
|
},
|
201
276
|
{
|
202
277
|
base: new Dec("100.00100"),
|
203
278
|
target: new Dec("-1.001"),
|
204
|
-
precision: 0,
|
205
279
|
dec: new Dec("99"),
|
206
280
|
// Max decimals should be remain
|
207
281
|
str: "99.000",
|
@@ -209,7 +283,6 @@ describe("Test IntPretty", () => {
|
|
209
283
|
{
|
210
284
|
base: new Dec("100.00100"),
|
211
285
|
target: new Dec("-0.00100"),
|
212
|
-
precision: 0,
|
213
286
|
dec: new Dec("100"),
|
214
287
|
// Max decimals should be remain
|
215
288
|
str: "100.000",
|
@@ -217,7 +290,6 @@ describe("Test IntPretty", () => {
|
|
217
290
|
{
|
218
291
|
base: new Dec("0.00100"),
|
219
292
|
target: new Dec("-1.00100"),
|
220
|
-
precision: 0,
|
221
293
|
dec: new Dec("-1"),
|
222
294
|
// Max decimals should be remain
|
223
295
|
str: "-1.000",
|
@@ -225,7 +297,6 @@ describe("Test IntPretty", () => {
|
|
225
297
|
{
|
226
298
|
base: new Dec("100.00100"),
|
227
299
|
target: new Dec("1.01"),
|
228
|
-
precision: 3,
|
229
300
|
dec: new Dec("101.011"),
|
230
301
|
str: "101.011",
|
231
302
|
},
|
@@ -233,7 +304,6 @@ describe("Test IntPretty", () => {
|
|
233
304
|
|
234
305
|
for (const param of params) {
|
235
306
|
const pretty = new IntPretty(param.base).add(new IntPretty(param.target));
|
236
|
-
expect(pretty.options.precision).toBe(param.precision);
|
237
307
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
238
308
|
expect(pretty.toString()).toBe(param.str);
|
239
309
|
}
|
@@ -243,63 +313,54 @@ describe("Test IntPretty", () => {
|
|
243
313
|
const params: {
|
244
314
|
base: Dec | Int;
|
245
315
|
target: Dec | Int;
|
246
|
-
precision: number;
|
247
316
|
dec: Dec;
|
248
317
|
str: string;
|
249
318
|
}[] = [
|
250
319
|
{
|
251
320
|
base: new Int(0),
|
252
321
|
target: new Int(0),
|
253
|
-
precision: 0,
|
254
322
|
dec: new Dec(0),
|
255
323
|
str: "0",
|
256
324
|
},
|
257
325
|
{
|
258
326
|
base: new Dec(0),
|
259
327
|
target: new Int(0),
|
260
|
-
precision: 0,
|
261
328
|
dec: new Dec(0),
|
262
329
|
str: "0",
|
263
330
|
},
|
264
331
|
{
|
265
332
|
base: new Int(0),
|
266
333
|
target: new Dec(0),
|
267
|
-
precision: 0,
|
268
334
|
dec: new Dec(0),
|
269
335
|
str: "0",
|
270
336
|
},
|
271
337
|
{
|
272
338
|
base: new Int(1),
|
273
339
|
target: new Dec(1),
|
274
|
-
precision: 0,
|
275
340
|
dec: new Dec(0),
|
276
341
|
str: "0",
|
277
342
|
},
|
278
343
|
{
|
279
344
|
base: new Int(1),
|
280
345
|
target: new Dec(-1),
|
281
|
-
precision: 0,
|
282
346
|
dec: new Dec(2),
|
283
347
|
str: "2",
|
284
348
|
},
|
285
349
|
{
|
286
350
|
base: new Int(100),
|
287
351
|
target: new Dec(-1),
|
288
|
-
precision: 0,
|
289
352
|
dec: new Dec("101"),
|
290
353
|
str: "101",
|
291
354
|
},
|
292
355
|
{
|
293
356
|
base: new Dec("100.001"),
|
294
357
|
target: new Dec(-1),
|
295
|
-
precision: 3,
|
296
358
|
dec: new Dec("101.001"),
|
297
359
|
str: "101.001",
|
298
360
|
},
|
299
361
|
{
|
300
362
|
base: new Dec("100.00100"),
|
301
363
|
target: new Dec("1.001"),
|
302
|
-
precision: 0,
|
303
364
|
dec: new Dec("99"),
|
304
365
|
// Max decimals should be remain
|
305
366
|
str: "99.000",
|
@@ -307,7 +368,6 @@ describe("Test IntPretty", () => {
|
|
307
368
|
{
|
308
369
|
base: new Dec("100.00100"),
|
309
370
|
target: new Dec("0.00100"),
|
310
|
-
precision: 0,
|
311
371
|
dec: new Dec("100"),
|
312
372
|
// Max decimals should be remain
|
313
373
|
str: "100.000",
|
@@ -315,14 +375,12 @@ describe("Test IntPretty", () => {
|
|
315
375
|
{
|
316
376
|
base: new Dec("0.00100"),
|
317
377
|
target: new Dec("-1.00100"),
|
318
|
-
precision: 3,
|
319
378
|
dec: new Dec("1.002"),
|
320
379
|
str: "1.002",
|
321
380
|
},
|
322
381
|
{
|
323
382
|
base: new Dec("100.00100"),
|
324
383
|
target: new Dec("-1.01"),
|
325
|
-
precision: 3,
|
326
384
|
dec: new Dec("101.011"),
|
327
385
|
str: "101.011",
|
328
386
|
},
|
@@ -330,7 +388,6 @@ describe("Test IntPretty", () => {
|
|
330
388
|
|
331
389
|
for (const param of params) {
|
332
390
|
const pretty = new IntPretty(param.base).sub(new IntPretty(param.target));
|
333
|
-
expect(pretty.options.precision).toBe(param.precision);
|
334
391
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
335
392
|
expect(pretty.toString()).toBe(param.str);
|
336
393
|
}
|
@@ -340,63 +397,54 @@ describe("Test IntPretty", () => {
|
|
340
397
|
const params: {
|
341
398
|
base: Dec | Int;
|
342
399
|
target: Dec | Int;
|
343
|
-
precision: number;
|
344
400
|
dec: Dec;
|
345
401
|
str: string;
|
346
402
|
}[] = [
|
347
403
|
{
|
348
404
|
base: new Int(0),
|
349
405
|
target: new Int(0),
|
350
|
-
precision: 0,
|
351
406
|
dec: new Dec(0),
|
352
407
|
str: "0",
|
353
408
|
},
|
354
409
|
{
|
355
410
|
base: new Dec(0),
|
356
411
|
target: new Int(0),
|
357
|
-
precision: 0,
|
358
412
|
dec: new Dec(0),
|
359
413
|
str: "0",
|
360
414
|
},
|
361
415
|
{
|
362
416
|
base: new Int(0),
|
363
417
|
target: new Dec(0),
|
364
|
-
precision: 0,
|
365
418
|
dec: new Dec(0),
|
366
419
|
str: "0",
|
367
420
|
},
|
368
421
|
{
|
369
422
|
base: new Int(1),
|
370
423
|
target: new Dec(1),
|
371
|
-
precision: 0,
|
372
424
|
dec: new Dec(1),
|
373
425
|
str: "1",
|
374
426
|
},
|
375
427
|
{
|
376
428
|
base: new Int(1),
|
377
429
|
target: new Dec(-1),
|
378
|
-
precision: 0,
|
379
430
|
dec: new Dec(-1),
|
380
431
|
str: "-1",
|
381
432
|
},
|
382
433
|
{
|
383
434
|
base: new Int(100),
|
384
435
|
target: new Dec(-1),
|
385
|
-
precision: 0,
|
386
436
|
dec: new Dec("-100"),
|
387
437
|
str: "-100",
|
388
438
|
},
|
389
439
|
{
|
390
440
|
base: new Dec("100.001"),
|
391
441
|
target: new Dec(-1),
|
392
|
-
precision: 3,
|
393
442
|
dec: new Dec("-100.001"),
|
394
443
|
str: "-100.001",
|
395
444
|
},
|
396
445
|
{
|
397
446
|
base: new Dec("100.00100"),
|
398
447
|
target: new Dec("1.001"),
|
399
|
-
precision: 6,
|
400
448
|
dec: new Dec("100.101001"),
|
401
449
|
// Max decimals should be remain
|
402
450
|
str: "100.101",
|
@@ -404,7 +452,6 @@ describe("Test IntPretty", () => {
|
|
404
452
|
{
|
405
453
|
base: new Dec("100.00100"),
|
406
454
|
target: new Dec("0.00100"),
|
407
|
-
precision: 6,
|
408
455
|
dec: new Dec("0.100001"),
|
409
456
|
// Max decimals should be remain
|
410
457
|
str: "0.100",
|
@@ -412,7 +459,6 @@ describe("Test IntPretty", () => {
|
|
412
459
|
{
|
413
460
|
base: new Dec("100.00100"),
|
414
461
|
target: new Dec("-1.00100"),
|
415
|
-
precision: 6,
|
416
462
|
dec: new Dec("-100.101001"),
|
417
463
|
// Max decimals should be remain
|
418
464
|
str: "-100.101",
|
@@ -420,7 +466,6 @@ describe("Test IntPretty", () => {
|
|
420
466
|
{
|
421
467
|
base: new Dec("100.00100"),
|
422
468
|
target: new Dec("-0.00100"),
|
423
|
-
precision: 6,
|
424
469
|
dec: new Dec("-0.100001"),
|
425
470
|
// Max decimals should be remain
|
426
471
|
str: "-0.100",
|
@@ -429,7 +474,6 @@ describe("Test IntPretty", () => {
|
|
429
474
|
|
430
475
|
for (const param of params) {
|
431
476
|
const pretty = new IntPretty(param.base).mul(new IntPretty(param.target));
|
432
|
-
expect(pretty.options.precision).toBe(param.precision);
|
433
477
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
434
478
|
expect(pretty.toString()).toBe(param.str);
|
435
479
|
}
|
@@ -443,49 +487,42 @@ describe("Test IntPretty", () => {
|
|
443
487
|
const params: {
|
444
488
|
base: Dec | Int;
|
445
489
|
target: Dec | Int;
|
446
|
-
precision: number;
|
447
490
|
dec: Dec;
|
448
491
|
str: string;
|
449
492
|
}[] = [
|
450
493
|
{
|
451
494
|
base: new Int(1),
|
452
495
|
target: new Dec(1),
|
453
|
-
precision: 0,
|
454
496
|
dec: new Dec(1),
|
455
497
|
str: "1",
|
456
498
|
},
|
457
499
|
{
|
458
500
|
base: new Int(1),
|
459
501
|
target: new Dec(-1),
|
460
|
-
precision: 0,
|
461
502
|
dec: new Dec(-1),
|
462
503
|
str: "-1",
|
463
504
|
},
|
464
505
|
{
|
465
506
|
base: new Int(100),
|
466
507
|
target: new Dec(-1),
|
467
|
-
precision: 0,
|
468
508
|
dec: new Dec("-100"),
|
469
509
|
str: "-100",
|
470
510
|
},
|
471
511
|
{
|
472
512
|
base: new Dec("100.001"),
|
473
513
|
target: new Dec(-1),
|
474
|
-
precision: 3,
|
475
514
|
dec: new Dec("-100.001"),
|
476
515
|
str: "-100.001",
|
477
516
|
},
|
478
517
|
{
|
479
518
|
base: new Dec("300.00300"),
|
480
519
|
target: new Dec("3"),
|
481
|
-
precision: 3,
|
482
520
|
dec: new Dec("100.001"),
|
483
521
|
str: "100.001",
|
484
522
|
},
|
485
523
|
{
|
486
524
|
base: new Dec("100.00500"),
|
487
525
|
target: new Dec("0.02"),
|
488
|
-
precision: 2,
|
489
526
|
dec: new Dec("5000.25"),
|
490
527
|
// Max decimals should be remain
|
491
528
|
str: "5,000.250",
|
@@ -493,7 +530,6 @@ describe("Test IntPretty", () => {
|
|
493
530
|
{
|
494
531
|
base: new Dec("300.00300"),
|
495
532
|
target: new Dec("4"),
|
496
|
-
precision: 5,
|
497
533
|
dec: new Dec("75.00075"),
|
498
534
|
// Max decimals should be remain
|
499
535
|
str: "75.000",
|
@@ -502,7 +538,6 @@ describe("Test IntPretty", () => {
|
|
502
538
|
|
503
539
|
for (const param of params) {
|
504
540
|
const pretty = new IntPretty(param.base).quo(new IntPretty(param.target));
|
505
|
-
expect(pretty.options.precision).toBe(param.precision);
|
506
541
|
expect(pretty.toDec().equals(param.dec)).toBeTruthy();
|
507
542
|
expect(pretty.toString()).toBe(param.str);
|
508
543
|
}
|
@@ -525,4 +560,164 @@ describe("Test IntPretty", () => {
|
|
525
560
|
expect(pretty.maxDecimals(9).trim(true).toString()).toBe("0.0123456");
|
526
561
|
expect(pretty.shrink(true).toString()).toBe("0.0123456");
|
527
562
|
});
|
563
|
+
|
564
|
+
it("Test inequalitySymbol of IntPretty", () => {
|
565
|
+
const tests: {
|
566
|
+
base: IntPretty;
|
567
|
+
maxDecimals: number;
|
568
|
+
inequalitySymbolSeparator: string;
|
569
|
+
resStr: string;
|
570
|
+
}[] = [
|
571
|
+
{
|
572
|
+
base: new IntPretty(new Dec("0")),
|
573
|
+
maxDecimals: 3,
|
574
|
+
inequalitySymbolSeparator: " ",
|
575
|
+
resStr: "0.000",
|
576
|
+
},
|
577
|
+
{
|
578
|
+
base: new IntPretty(new Dec("-0")),
|
579
|
+
maxDecimals: 3,
|
580
|
+
inequalitySymbolSeparator: " ",
|
581
|
+
resStr: "0.000",
|
582
|
+
},
|
583
|
+
{
|
584
|
+
base: new IntPretty(new Dec("0.1")),
|
585
|
+
maxDecimals: 3,
|
586
|
+
inequalitySymbolSeparator: " ",
|
587
|
+
resStr: "0.100",
|
588
|
+
},
|
589
|
+
{
|
590
|
+
base: new IntPretty(new Dec("1234.123456")),
|
591
|
+
maxDecimals: 3,
|
592
|
+
inequalitySymbolSeparator: " ",
|
593
|
+
resStr: "1,234.123",
|
594
|
+
},
|
595
|
+
{
|
596
|
+
base: new IntPretty(new Dec("0.123456")),
|
597
|
+
maxDecimals: 3,
|
598
|
+
inequalitySymbolSeparator: " ",
|
599
|
+
resStr: "0.123",
|
600
|
+
},
|
601
|
+
{
|
602
|
+
base: new IntPretty(new Dec("0.123456")).moveDecimalPointLeft(2),
|
603
|
+
maxDecimals: 3,
|
604
|
+
inequalitySymbolSeparator: " ",
|
605
|
+
resStr: "0.001",
|
606
|
+
},
|
607
|
+
{
|
608
|
+
base: new IntPretty(new Dec("0.123456")).moveDecimalPointLeft(3),
|
609
|
+
maxDecimals: 3,
|
610
|
+
inequalitySymbolSeparator: " ",
|
611
|
+
resStr: "< 0.001",
|
612
|
+
},
|
613
|
+
{
|
614
|
+
base: new IntPretty(new Dec("0.123456")),
|
615
|
+
maxDecimals: 0,
|
616
|
+
inequalitySymbolSeparator: " ",
|
617
|
+
resStr: "< 1",
|
618
|
+
},
|
619
|
+
{
|
620
|
+
base: new IntPretty(new Dec("1.123456")),
|
621
|
+
maxDecimals: 0,
|
622
|
+
inequalitySymbolSeparator: " ",
|
623
|
+
resStr: "1",
|
624
|
+
},
|
625
|
+
{
|
626
|
+
base: new IntPretty(new Dec("0.0001")),
|
627
|
+
maxDecimals: 3,
|
628
|
+
inequalitySymbolSeparator: " ",
|
629
|
+
resStr: "< 0.001",
|
630
|
+
},
|
631
|
+
{
|
632
|
+
base: new IntPretty(new Dec("0.0001")),
|
633
|
+
maxDecimals: 3,
|
634
|
+
inequalitySymbolSeparator: "",
|
635
|
+
resStr: "<0.001",
|
636
|
+
},
|
637
|
+
{
|
638
|
+
base: new IntPretty(new Dec("0.001")),
|
639
|
+
maxDecimals: 3,
|
640
|
+
inequalitySymbolSeparator: " ",
|
641
|
+
resStr: "0.001",
|
642
|
+
},
|
643
|
+
{
|
644
|
+
base: new IntPretty(new Dec("-1234.123456")),
|
645
|
+
maxDecimals: 3,
|
646
|
+
inequalitySymbolSeparator: " ",
|
647
|
+
resStr: "-1,234.123",
|
648
|
+
},
|
649
|
+
{
|
650
|
+
base: new IntPretty(new Dec("-0.123456")),
|
651
|
+
maxDecimals: 3,
|
652
|
+
inequalitySymbolSeparator: " ",
|
653
|
+
resStr: "-0.123",
|
654
|
+
},
|
655
|
+
{
|
656
|
+
base: new IntPretty(new Dec("-0.0001")),
|
657
|
+
maxDecimals: 3,
|
658
|
+
inequalitySymbolSeparator: " ",
|
659
|
+
resStr: "> -0.001",
|
660
|
+
},
|
661
|
+
{
|
662
|
+
base: new IntPretty(new Dec("-0.0001")),
|
663
|
+
maxDecimals: 3,
|
664
|
+
inequalitySymbolSeparator: "",
|
665
|
+
resStr: ">-0.001",
|
666
|
+
},
|
667
|
+
{
|
668
|
+
base: new IntPretty(new Dec("-0.001")),
|
669
|
+
maxDecimals: 3,
|
670
|
+
inequalitySymbolSeparator: " ",
|
671
|
+
resStr: "-0.001",
|
672
|
+
},
|
673
|
+
{
|
674
|
+
base: new IntPretty(new Dec("-0.123456")),
|
675
|
+
maxDecimals: 0,
|
676
|
+
inequalitySymbolSeparator: " ",
|
677
|
+
resStr: "> -1",
|
678
|
+
},
|
679
|
+
{
|
680
|
+
base: new IntPretty(new Dec("-1.123456")),
|
681
|
+
maxDecimals: 0,
|
682
|
+
inequalitySymbolSeparator: " ",
|
683
|
+
resStr: "-1",
|
684
|
+
},
|
685
|
+
];
|
686
|
+
|
687
|
+
for (const test of tests) {
|
688
|
+
expect(
|
689
|
+
test.base
|
690
|
+
.maxDecimals(test.maxDecimals)
|
691
|
+
.inequalitySymbol(true)
|
692
|
+
.inequalitySymbolSeparator(test.inequalitySymbolSeparator)
|
693
|
+
.toString()
|
694
|
+
).toBe(test.resStr);
|
695
|
+
}
|
696
|
+
});
|
697
|
+
|
698
|
+
it("Test toStringWithSymbols() of IntPretty", () => {
|
699
|
+
expect(
|
700
|
+
new IntPretty(new Dec(-123.45)).toStringWithSymbols("$", "SUFFIX")
|
701
|
+
).toBe("-$123.45SUFFIX");
|
702
|
+
|
703
|
+
expect(
|
704
|
+
new IntPretty(new Dec(-123.45))
|
705
|
+
.maxDecimals(0)
|
706
|
+
.toStringWithSymbols("$", "SUFFIX")
|
707
|
+
).toBe("-$123SUFFIX");
|
708
|
+
|
709
|
+
expect(
|
710
|
+
new IntPretty(new Dec(-0.045))
|
711
|
+
.maxDecimals(1)
|
712
|
+
.inequalitySymbol(true)
|
713
|
+
.toStringWithSymbols("$", "SUFFIX")
|
714
|
+
).toBe("> -$0.1SUFFIX");
|
715
|
+
|
716
|
+
expect(
|
717
|
+
new IntPretty(new Dec(0.045))
|
718
|
+
.maxDecimals(1)
|
719
|
+
.inequalitySymbol(true)
|
720
|
+
.toStringWithSymbols("$", "SUFFIX")
|
721
|
+
).toBe("< $0.1SUFFIX");
|
722
|
+
});
|
528
723
|
});
|