-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10a4b5c
commit 81f3c38
Showing
4 changed files
with
138 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Decimal128 } from "../src/decimal128.mjs"; | ||
import { expectDecimal128 } from "./util.js"; | ||
|
||
describe("NaN", () => { | ||
test("does not work", () => { | ||
expect(() => new Decimal128("NaN").toBigInt()).toThrow(RangeError); | ||
}); | ||
}); | ||
|
||
describe("zero", () => { | ||
test("positive zero", () => { | ||
expect(new Decimal128("0").toBigInt()).toStrictEqual(0n); | ||
}); | ||
test("negative zero", () => { | ||
expect(new Decimal128("-0").toBigInt()).toStrictEqual(0n); | ||
}); | ||
}); | ||
|
||
describe("infinity", () => { | ||
test("positive", () => { | ||
expect(() => new Decimal128("Infinity").toBigInt()).toThrow(RangeError); | ||
}); | ||
test("negative", () => { | ||
expect(() => new Decimal128("-Infinity").toBigInt()).toThrow( | ||
RangeError | ||
); | ||
}); | ||
}); | ||
|
||
describe("non-integer", () => { | ||
test("throws", () => { | ||
expect(() => new Decimal128("1.2").toBigInt()).toThrow(RangeError); | ||
}); | ||
test("work with mathematical value (ignore trailing zeroes)", () => { | ||
expect(new Decimal128("1.00").toBigInt()).toStrictEqual(1n); | ||
}); | ||
}); | ||
|
||
describe("simple examples", () => { | ||
test("42", () => { | ||
expect(new Decimal128("42").toBigInt()).toStrictEqual(42n); | ||
}); | ||
test("-123", () => { | ||
expect(new Decimal128("-123").toBigInt()).toStrictEqual(-123n); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Decimal128 } from "../src/decimal128.mjs"; | ||
import { expectDecimal128 } from "./util.js"; | ||
|
||
describe("NaN", () => { | ||
test("works", () => { | ||
expect(new Decimal128("NaN").toNumber()).toStrictEqual(NaN); | ||
}); | ||
}); | ||
|
||
describe("zero", () => { | ||
test("positive zero", () => { | ||
expect(new Decimal128("0").toNumber()).toStrictEqual(0); | ||
}); | ||
test("negative zero", () => { | ||
expect(new Decimal128("-0").toNumber()).toStrictEqual(-0); | ||
}); | ||
}); | ||
|
||
describe("infinity", () => { | ||
test("positive infinity", () => { | ||
expect(new Decimal128("Infinity").toNumber()).toStrictEqual(Infinity); | ||
}); | ||
test("negative infinity", () => { | ||
expect(new Decimal128("-Infinity").toNumber()).toStrictEqual(-Infinity); | ||
}); | ||
}); | ||
|
||
describe("simple examples", () => { | ||
test("1.25", () => { | ||
expect(new Decimal128("1.25").toNumber()).toStrictEqual(1.25); | ||
}); | ||
test("0.1", () => { | ||
expect(new Decimal128("0.1").toNumber()).toStrictEqual(0.1); | ||
}); | ||
test("extreme precision", () => { | ||
expect( | ||
new Decimal128("0." + "0".repeat(100) + "1").toNumber() | ||
).toStrictEqual(1e-101); | ||
}); | ||
}); |