Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/utils/__tests__/price.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { compute24hPriceChange } from '../price.utils';

describe('compute24hPriceChange()', () => {
it('returns a positive percentage when the price increases', () => {
expect(compute24hPriceChange(120n, 100n)).toBe(20);
it('returns a positive percentage when the price increases (oldest 100, latest 150 → 50.00)', () => {
expect(compute24hPriceChange(150n, 100n)).toBe(50);
});

it('returns a negative percentage when the price decreases', () => {
expect(compute24hPriceChange(80n, 100n)).toBe(-20);
it('returns a negative percentage when the price decreases (oldest 200, latest 100 → -50.00)', () => {
expect(compute24hPriceChange(100n, 200n)).toBe(-50);
});

it('returns 0 when the price is unchanged', () => {
it('returns 0 when the price is unchanged (oldest 100, latest 100 → 0.00)', () => {
expect(compute24hPriceChange(100n, 100n)).toBe(0);
});

it('returns 0 when the previous price is zero', () => {
expect(compute24hPriceChange(100n, 0n)).toBe(0);
});

it('rounds long decimal values to exactly two decimal places', () => {
expect(compute24hPriceChange(101n, 3n)).toBe(3266.67);
it('rounds fractional result to two decimal places (oldest 3, latest 4 → 33.33)', () => {
expect(compute24hPriceChange(4n, 3n)).toBe(33.33);
});
});
Loading