47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { MemoryFormatter } from './MemoryFormatter';
|
|
|
|
describe('MemoryFormatter', () => {
|
|
describe('formatMB', () => {
|
|
it('should format bytes as MB with 1 decimal place', () => {
|
|
expect(MemoryFormatter.formatMB(1048576)).toBe('1.0MB');
|
|
expect(MemoryFormatter.formatMB(10485760)).toBe('10.0MB');
|
|
expect(MemoryFormatter.formatMB(104857600)).toBe('100.0MB');
|
|
});
|
|
|
|
it('should handle zero bytes', () => {
|
|
expect(MemoryFormatter.formatMB(0)).toBe('0.0MB');
|
|
});
|
|
|
|
it('should handle small values', () => {
|
|
expect(MemoryFormatter.formatMB(1024)).toBe('0.0MB');
|
|
expect(MemoryFormatter.formatMB(524288)).toBe('0.5MB');
|
|
});
|
|
|
|
it('should handle large values', () => {
|
|
expect(MemoryFormatter.formatMB(1073741824)).toBe('1024.0MB');
|
|
});
|
|
});
|
|
|
|
describe('formatKB', () => {
|
|
it('should format bytes as KB with 1 decimal place', () => {
|
|
expect(MemoryFormatter.formatKB(1024)).toBe('1.0KB');
|
|
expect(MemoryFormatter.formatKB(10240)).toBe('10.0KB');
|
|
expect(MemoryFormatter.formatKB(102400)).toBe('100.0KB');
|
|
});
|
|
|
|
it('should handle zero bytes', () => {
|
|
expect(MemoryFormatter.formatKB(0)).toBe('0.0KB');
|
|
});
|
|
|
|
it('should handle small values', () => {
|
|
expect(MemoryFormatter.formatKB(1)).toBe('0.0KB');
|
|
expect(MemoryFormatter.formatKB(512)).toBe('0.5KB');
|
|
});
|
|
|
|
it('should handle large values', () => {
|
|
expect(MemoryFormatter.formatKB(1048576)).toBe('1024.0KB');
|
|
});
|
|
});
|
|
});
|