blob: 33eb89b190eb5da2877247d73a4a8667bb737308 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { test, expect } from 'bun:test';
// formatBytes is an internal function in cache.ts
// This test verifies the expected behavior
function formatBytes(bytes: number): string {
return (bytes / (1024 * 1024)).toFixed(2);
}
test('formatBytes converts bytes to MB', () => {
expect(formatBytes(1024 * 1024)).toBe('1.00');
expect(formatBytes(2 * 1024 * 1024)).toBe('2.00');
expect(formatBytes(10.5 * 1024 * 1024)).toBe('10.50');
});
test('formatBytes rounds to 2 decimal places', () => {
expect(formatBytes(1024 * 1024 + 1)).toBe('1.00');
expect(formatBytes(1.234 * 1024 * 1024)).toBe('1.23');
});
test('formatBytes handles zero', () => {
expect(formatBytes(0)).toBe('0.00');
});
test('formatBytes handles small values', () => {
expect(formatBytes(512 * 1024)).toBe('0.50');
expect(formatBytes(1024)).toBe('0.00');
});
|