Skip to content

Commit

Permalink
test: add simple test to confirm scientific notation cutoff
Browse files Browse the repository at this point in the history
  • Loading branch information
bvotteler committed Feb 7, 2023
1 parent 9d25c5b commit 61ea1de
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/monetary.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Big, { BigSource, RoundingMode } from "big.js";
import { expect } from "chai";
import * as fc from "fast-check";
import { Polkadot } from "../src/currencies";

import { Currency, MonetaryAmount } from "../src/monetary";

Expand Down Expand Up @@ -69,6 +70,21 @@ describe("MonetaryAmount", () => {
})
);
});

it("should show full amount or scientific notation as expected", () => {
// expected cutoff is 39
const above = Big(1e39);
const below = above.sub(1);

const amountAbove = new MonetaryAmount(Polkadot, 0).withAtomicAmount(above);
const amountBelow = new MonetaryAmount(Polkadot, 0).withAtomicAmount(below);

expect(amountAbove.toString(true)).to.eq("1e+39");

// 39 times the '9' character
const expectedBelow = "9".repeat(39);
expect(amountBelow.toString(true)).to.eq(expectedBelow)
});
});

describe("toHuman", () => {
Expand Down

0 comments on commit 61ea1de

Please sign in to comment.