Skip to content

Commit 748661a

Browse files
committed
[Tests] truncate: cover BigInt inputs
The implementation already accepts BigInt (per the spec, `truncate` is a purely-mathematical operation that produces a mathematical integer for any BigInt input - the identity), but no test exercised that path. Adds five assertions covering 0n, ±5n, and arbitrary-precision ±10**29.
1 parent aaff938 commit 748661a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/methods/truncate.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,24 @@ module.exports = function (t, year, truncate) {
1919
t.equal(truncate(1.1), 1, '1.1 truncates to 1');
2020
t.equal(truncate(0), 0, '+0 truncates to +0');
2121
t.equal(truncate(-0), 0, '-0 truncates to +0');
22+
23+
t.test('has bigints', { skip: v.bigints.length === 0 }, function (st) {
24+
// BigInt support: integer-valued, so truncate is the identity, and
25+
// arbitrarily-large values are preserved without precision loss.
26+
st.equal(truncate(BigInt(0)), BigInt(0), '0n is unchanged');
27+
st.equal(truncate(BigInt(5)), BigInt(5), '5n is unchanged');
28+
st.equal(truncate(BigInt(-5)), BigInt(-5), '-5n is unchanged');
29+
st.equal(
30+
truncate(BigInt('123456789012345678901234567890')),
31+
BigInt('123456789012345678901234567890'),
32+
'arbitrary-precision BigInt is preserved'
33+
);
34+
st.equal(
35+
truncate(BigInt('-123456789012345678901234567890')),
36+
BigInt('-123456789012345678901234567890'),
37+
'arbitrary-precision negative BigInt is preserved'
38+
);
39+
40+
st.end();
41+
});
2242
};

0 commit comments

Comments
 (0)