gytes_test.go 780 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package bytes
  2. import "testing"
  3. func TestGytes(t *testing.T) {
  4. // B
  5. b := Format(515)
  6. if b != "515 B" {
  7. t.Errorf("expected `515 B`, got %s", b)
  8. }
  9. // MB
  10. b = Format(13231323)
  11. if b != "13.23 MB" {
  12. t.Errorf("expected `13.23 MB`, got %s", b)
  13. }
  14. // Exact
  15. b = Format(1000 * 1000 * 1000)
  16. if b != "1.00 GB" {
  17. t.Errorf("expected `1.00 GB`, got %s", b)
  18. }
  19. // Binary prefix
  20. BinaryPrefix(true)
  21. b = Format(1323)
  22. if b != "1.29 KiB" {
  23. t.Errorf("expected `1.29 KiB`, got %s", b)
  24. }
  25. }
  26. func TestNew(t *testing.T) {
  27. g := New()
  28. b := g.Format(132313231323)
  29. if b != "132.31 GB" {
  30. t.Errorf("expected `132.31 GB`, got %s", b)
  31. }
  32. // Binary prefix
  33. g.BinaryPrefix(true)
  34. b = Format(1323132313231323)
  35. if b != "1.18 PiB" {
  36. t.Errorf("expected `1.18 PiB`, got %s", b)
  37. }
  38. }