bytes_test.go 584 B

12345678910111213141516171819202122232425262728293031
  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 != "12.62 MB" {
  12. t.Errorf("formatted bytes should be 12.62 MB, found %s", f)
  13. }
  14. // Exact
  15. f = Format(1024 * 1024 * 1024)
  16. if f != "1.00 GB" {
  17. t.Errorf("formatted bytes should be 1.00 GB, found %s", f)
  18. }
  19. }
  20. func TestBinaryPrefix(t *testing.T) {
  21. BinaryPrefix(true)
  22. f := Format(1323)
  23. if f != "1.29 KiB" {
  24. t.Errorf("formatted bytes should be 1.29 KiB, found %s", f)
  25. }
  26. }