format_test.go 585 B

12345678910111213141516171819202122232425262728293031323334
  1. package format
  2. import (
  3. "testing"
  4. )
  5. func TestHumanNumber(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 := HumanNumber(tc.input)
  24. if result != tc.expected {
  25. t.Errorf("Expected %s, got %s", tc.expected, result)
  26. }
  27. })
  28. }
  29. }