Skip to content

Commit

Permalink
Add tests for -0 and high precision values (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvele authored Aug 5, 2023
1 parent 1f6af16 commit 251a31f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ test('roundTo()', t => {
t.is(roundTo(1262.48, -1), 1260);
t.is(roundTo(1262.48, -2), 1300);
t.is(roundTo(0.597 / 6, 3), 0.1);
t.is(roundTo(6.578040334659363e-10, 6), 0);
t.is(roundTo(-6.578040334659363e-10, 6), -0);
t.is(roundTo(0, 1), 0);
t.is(roundTo(-0, 1), 0);
});

test('roundToUp()', t => {
Expand All @@ -41,6 +45,10 @@ test('roundToUp()', t => {
t.is(roundToUp(-2.26, 2), -2.26);
t.is(roundToUp(-18.15, 2), -18.15);
t.is(roundToUp((0.1 + 0.2) * 10, 0), 3);
t.is(roundToUp(6.578040334659363e-10, 6), 0.000001);
t.is(roundToUp(-6.578040334659363e-10, 6), -0);
t.is(roundToUp(0, 1), 0);
t.is(roundToUp(-0, 1), 0);
});

test('roundToDown()', t => {
Expand All @@ -59,4 +67,8 @@ test('roundToDown()', t => {
t.is(roundToDown(2.26, 2), 2.26);
t.is(roundToDown(18.15, 2), 18.15);
t.is(roundToDown((0.1 + 0.7) * 10, 0), 8);
t.is(roundToDown(6.578040334659363e-10, 6), 0);
t.is(roundToDown(-6.578040334659363e-10, 6), -0.000001);
t.is(roundToDown(0, 1), 0);
t.is(roundToDown(-0, 1), 0);
});

0 comments on commit 251a31f

Please sign in to comment.