// format_test.dart — L1 数值格式化纯函数单测(支柱 3:纯逻辑、确定性、零依赖)。 import 'package:flutter_test/flutter_test.dart'; import 'package:pangolin_vpn/util/format.dart'; void main() { group('formatSpeed(字节/秒 → 数值+单位)', () { test('null → —/KB/s(未取到)', () { expect(formatSpeed(null), ('—', 'KB/s')); }); test('0 → 0 B/s', () { expect(formatSpeed(0), ('0', 'B/s')); }); test('< 1KB 用 B/s 且取整', () { expect(formatSpeed(512), ('512', 'B/s')); expect(formatSpeed(1023), ('1023', 'B/s')); }); test('KB/s 边界(1024)与一位小数', () { expect(formatSpeed(1024), ('1.0', 'KB/s')); expect(formatSpeed(1536), ('1.5', 'KB/s')); }); test('MB/s 边界(1024^2)', () { expect(formatSpeed(1024 * 1024), ('1.0', 'MB/s')); expect(formatSpeed(1024 * 1024 * 5 + 512 * 1024), ('5.5', 'MB/s')); }); test('GB/s 边界(1024^3)与两位小数', () { expect(formatSpeed(1024 * 1024 * 1024), ('1.00', 'GB/s')); expect(formatSpeed(2.5 * 1024 * 1024 * 1024), ('2.50', 'GB/s')); }); }); group('formatDuration(时长 → HH:MM:SS)', () { test('0 → 00:00:00', () { expect(formatDuration(Duration.zero), '00:00:00'); }); test('秒/分补零', () { expect(formatDuration(const Duration(seconds: 5)), '00:00:05'); expect(formatDuration(const Duration(minutes: 3, seconds: 9)), '00:03:09'); }); test('小时不封顶(对齐连接计时 01:04:59)', () { expect( formatDuration(const Duration(hours: 1, minutes: 4, seconds: 59)), '01:04:59', ); expect(formatDuration(const Duration(hours: 100)), '100:00:00'); }); test('分/秒取模 60(不溢出进位错乱)', () { expect(formatDuration(const Duration(minutes: 90)), '01:30:00'); }); }); }