format_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package format
  2. import (
  3. "testing"
  4. )
  5. func TestRoundedParameter(t *testing.T) {
  6. type testCase struct {
  7. input uint64
  8. expected string
  9. }
  10. testCases := []testCase{
  11. {0, "0"},
  12. {1000000, "1M"},
  13. {125000000, "125M"},
  14. {500500000, "500.50M"},
  15. {500550000, "500.55M"},
  16. {1000000000, "1B"},
  17. {2800000000, "2.8B"},
  18. {2850000000, "2.9B"},
  19. {1000000000000, "1000B"},
  20. }
  21. for _, tc := range testCases {
  22. t.Run(tc.expected, func(t *testing.T) {
  23. result := RoundedParameter(tc.input)
  24. if result != tc.expected {
  25. t.Errorf("Expected %s, got %s", tc.expected, result)
  26. }
  27. })
  28. }
  29. }
  30. func TestParameters(t *testing.T) {
  31. type testCase struct {
  32. input uint64
  33. expected string
  34. }
  35. testCases := []testCase{
  36. {26000000, "26.0M"},
  37. {26000000000, "26.0B"},
  38. {1000, "1.00K"},
  39. {1000000, "1.00M"},
  40. {1000000000, "1.00B"},
  41. {1000000000000, "1.00T"},
  42. {100, "100"},
  43. {206000000, "206M"},
  44. }
  45. for _, tc := range testCases {
  46. t.Run(tc.expected, func(t *testing.T) {
  47. result := Parameters(tc.input)
  48. if result != tc.expected {
  49. t.Errorf("Expected %s, got %s", tc.expected, result)
  50. }
  51. })
  52. }
  53. }