bytes_test.go 560 B

123456789101112131415161718192021222324252627282930
  1. package bytes
  2. import "testing"
  3. func TestFormat(t *testing.T) {
  4. // B
  5. f := Format(515)
  6. if f != "515 B" {
  7. t.Errorf("formatted bytes should be 515 B, found %s", f)
  8. }
  9. // MB
  10. f = Format(13231323)
  11. if f != "13.23 MB" {
  12. t.Errorf("formatted bytes should be 13.23 MB, found %s", f)
  13. }
  14. // Exact
  15. f = Format(1000 * 1000 * 1000)
  16. if f != "1.00 GB" {
  17. t.Errorf("formatted bytes should be 1.00 GB, found %s", f)
  18. }
  19. }
  20. func TestFormatB(t *testing.T) {
  21. f := FormatB(1323)
  22. if f != "1.29 KiB" {
  23. t.Errorf("formatted bytes should be 1.29 KiB, found %s", f)
  24. }
  25. }