Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit b7969d8

Browse files
authored
tests: Remove normalization in constructor (has no effect) (#75)
* tests: Remove normalization in constructor (has no effect) Also, add an example showing how to normalize a value
1 parent a199e67 commit b7969d8

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- division (`divide`)
99
- remainder (`remainder`)
1010
- rounding (`round`)
11-
- `toString`
11+
- `toString` emitting both decimal and exponential syntax (default is decimal)
1212

1313
## Implementation
1414

examples/normalize.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function normalize(d) {
2+
// Decimal128 object
3+
return d.toString({ normalize: true });
4+
}
5+
6+
export { normalize };

tests/add.test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ describe("addition", () => {
5858
describe("non-normalized", () => {
5959
test("one point zero plus one point zero", () => {
6060
expect(
61-
new Decimal128("1.0", { normalize: false })
62-
.add(new Decimal128("1.0", { normalize: false }), {
63-
normalize: false,
64-
})
61+
new Decimal128("1.0")
62+
.add(new Decimal128("1.0"))
6563
.toString({ normalize: false })
6664
).toStrictEqual("2.0");
6765
});
@@ -131,7 +129,7 @@ describe("examples from the General Decimal Arithmetic specification", () => {
131129
test("example one", () => {
132130
expect(
133131
new Decimal128("12")
134-
.add(new Decimal128("7.00", { normalize: false }))
132+
.add(new Decimal128("7.00"))
135133
.toString({ normalize: false })
136134
).toStrictEqual("19.00");
137135
});

tests/constructor.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe("constructor", () => {
130130
expect(val.toString()).toStrictEqual(s);
131131
});
132132
test("decimal number with trailing zero", () => {
133-
let val = new Decimal128("0.67890", { normalize: false });
133+
let val = new Decimal128("0.67890");
134134
expect(val.significand).toStrictEqual("67890");
135135
expect(val.exponent).toStrictEqual(-5);
136136
});

tests/multiply.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("multiplication", () => {
164164
describe("examples from the General Decimal Arithmetic specification", () => {
165165
test("example one", () => {
166166
expect(
167-
new Decimal128("1.20", { normalize: false })
167+
new Decimal128("1.20")
168168
.multiply(new Decimal128("3"))
169169
.toString({ normalize: false })
170170
).toStrictEqual("3.60");
@@ -190,7 +190,7 @@ describe("examples from the General Decimal Arithmetic specification", () => {
190190
// slightly modified because we have more precision
191191
expect(
192192
new Decimal128("654321")
193-
.multiply(new Decimal128("654321"), { normalize: false })
193+
.multiply(new Decimal128("654321"))
194194
.toString({ format: "exponential" })
195195
).toStrictEqual("4.28135971041E+11");
196196
});

tests/subtract.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe("examples from the General Decimal Arithmetic specification", () => {
142142
test("example two", () => {
143143
expect(
144144
new Decimal128("1.3")
145-
.subtract(new Decimal128("1.30", { normalize: false }))
145+
.subtract(new Decimal128("1.30"))
146146
.toString({ normalize: false })
147147
).toStrictEqual("0.00");
148148
});

0 commit comments

Comments
 (0)