//go:build linux || freebsd // +build linux freebsd package format import ( "testing" ) func TestBytes(t *testing.T) { tests := []struct { input int64 expected string }{ {0, "0 B"}, {1, "1 B"}, {999, "999 B"}, {1000, "1.0 KB"}, {1500, "1.5 KB"}, {1000000, "1.0 MB"}, {2500000, "2.5 MB"}, {1000000000, "1.0 GB"}, {1000000000000, "1.0 TB"}, {1000000000000000, "1.0 PB"}, {-1, "? B"}, } for _, tc := range tests { result := Bytes(tc.input) if result != tc.expected { t.Errorf("Bytes(%d) = %q, want %q", tc.input, result, tc.expected) } } } func TestSpeed(t *testing.T) { tests := []struct { input float64 expected string }{ {0, "0.0 B/s"}, {1, "1.0 B/s"}, {999, "999.0 B/s"}, {1000, "1.0 KB/s"}, {1500, "1.5 KB/s"}, {1000000, "1.0 MB/s"}, {1000000000, "1.0 GB/s"}, {1000000000000, "1.0 TB/s"}, {-1, "? B/s"}, } for _, tc := range tests { result := Speed(tc.input) if result != tc.expected { t.Errorf("Speed(%f) = %q, want %q", tc.input, result, tc.expected) } } }