[go: nahoru, domu]

Skip to content

Commit

Permalink
test(multiply): test negative multiplications
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahdayan committed Feb 19, 2023
1 parent 6a10f52 commit 5b05403
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 deletions packages/dinero.js/src/api/__tests__/multiply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@ describe('multiply', () => {
it('multiplies positive Dinero objects', () => {
const d = dinero({ amount: 400, currency: USD });

const snapshot = toSnapshot(multiply(d, 4));

expect(snapshot).toEqual({
expect(toSnapshot(multiply(d, 4))).toEqual({
amount: 1600,
scale: 2,
currency: USD,
});
expect(toSnapshot(multiply(d, -1))).toEqual({
amount: -400,
scale: 2,
currency: USD,
});
});
it('multiplies negative Dinero objects', () => {
const d = dinero({ amount: -400, currency: USD });

expect(toSnapshot(multiply(d, 4))).toEqual({
amount: -1600,
scale: 2,
currency: USD,
});
expect(toSnapshot(multiply(d, 1))).toEqual({
amount: -400,
scale: 2,
currency: USD,
});
});
it('converts the multiplied amount to the safest scale', () => {
const d = dinero({ amount: 401, currency: USD });
Expand All @@ -44,13 +61,30 @@ describe('multiply', () => {
it('multiplies positive Dinero objects', () => {
const d = dinero({ amount: 400n, currency: bigintUSD });

const snapshot = toSnapshot(multiply(d, 4n));

expect(snapshot).toEqual({
expect(toSnapshot(multiply(d, 4n))).toEqual({
amount: 1600n,
scale: 2n,
currency: bigintUSD,
});
expect(toSnapshot(multiply(d, -1n))).toEqual({
amount: -400n,
scale: 2n,
currency: bigintUSD,
});
});
it('multiplies negative Dinero objects', () => {
const d = dinero({ amount: -400n, currency: bigintUSD });

expect(toSnapshot(multiply(d, 4n))).toEqual({
amount: -1600n,
scale: 2n,
currency: bigintUSD,
});
expect(toSnapshot(multiply(d, 1n))).toEqual({
amount: -400n,
scale: 2n,
currency: bigintUSD,
});
});
it('converts the multiplied amount to the safest scale', () => {
const d = dinero({ amount: 401n, currency: bigintUSD });
Expand All @@ -71,13 +105,30 @@ describe('multiply', () => {
it('multiplies positive Dinero objects', () => {
const d = dinero({ amount: new Big(400), currency: bigjsUSD });

const snapshot = toSnapshot(multiply(d, new Big(4)));

expect(snapshot).toEqual({
expect(toSnapshot(multiply(d, new Big(4)))).toEqual({
amount: new Big(1600),
scale: new Big(2),
currency: bigjsUSD,
});
expect(toSnapshot(multiply(d, new Big(-1)))).toEqual({
amount: new Big(-400),
scale: new Big(2),
currency: bigjsUSD,
});
});
it('multiplies negative Dinero objects', () => {
const d = dinero({ amount: new Big(-400), currency: bigjsUSD });

expect(toSnapshot(multiply(d, new Big(4)))).toEqual({
amount: new Big(-1600),
scale: new Big(2),
currency: bigjsUSD,
});
expect(toSnapshot(multiply(d, new Big(1)))).toEqual({
amount: new Big(-400),
scale: new Big(2),
currency: bigjsUSD,
});
});
it('converts the multiplied amount to the safest scale', () => {
const d = dinero({ amount: new Big(401), currency: bigjsUSD });
Expand Down

0 comments on commit 5b05403

Please sign in to comment.