You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
2.4 KiB

  1. // +build go1.6
  2. package humanize
  3. import (
  4. "math"
  5. "math/big"
  6. "testing"
  7. )
  8. func BenchmarkBigCommaf(b *testing.B) {
  9. for i := 0; i < b.N; i++ {
  10. Commaf(1234567890.83584)
  11. }
  12. }
  13. func TestBigCommafs(t *testing.T) {
  14. testList{
  15. {"0", BigCommaf(big.NewFloat(0)), "0"},
  16. {"10.11", BigCommaf(big.NewFloat(10.11)), "10.11"},
  17. {"100", BigCommaf(big.NewFloat(100)), "100"},
  18. {"1,000", BigCommaf(big.NewFloat(1000)), "1,000"},
  19. {"10,000", BigCommaf(big.NewFloat(10000)), "10,000"},
  20. {"100,000", BigCommaf(big.NewFloat(100000)), "100,000"},
  21. {"834,142.32", BigCommaf(big.NewFloat(834142.32)), "834,142.32"},
  22. {"10,000,000", BigCommaf(big.NewFloat(10000000)), "10,000,000"},
  23. {"10,100,000", BigCommaf(big.NewFloat(10100000)), "10,100,000"},
  24. {"10,010,000", BigCommaf(big.NewFloat(10010000)), "10,010,000"},
  25. {"10,001,000", BigCommaf(big.NewFloat(10001000)), "10,001,000"},
  26. {"123,456,789", BigCommaf(big.NewFloat(123456789)), "123,456,789"},
  27. {"maxf64", BigCommaf(big.NewFloat(math.MaxFloat64)), "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000"},
  28. {"minf64", BigCommaf(big.NewFloat(math.SmallestNonzeroFloat64)), "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465"},
  29. {"-123,456,789", BigCommaf(big.NewFloat(-123456789)), "-123,456,789"},
  30. {"-10,100,000", BigCommaf(big.NewFloat(-10100000)), "-10,100,000"},
  31. {"-10,010,000", BigCommaf(big.NewFloat(-10010000)), "-10,010,000"},
  32. {"-10,001,000", BigCommaf(big.NewFloat(-10001000)), "-10,001,000"},
  33. {"-10,000,000", BigCommaf(big.NewFloat(-10000000)), "-10,000,000"},
  34. {"-100,000", BigCommaf(big.NewFloat(-100000)), "-100,000"},
  35. {"-10,000", BigCommaf(big.NewFloat(-10000)), "-10,000"},
  36. {"-1,000", BigCommaf(big.NewFloat(-1000)), "-1,000"},
  37. {"-100.11", BigCommaf(big.NewFloat(-100.11)), "-100.11"},
  38. {"-10", BigCommaf(big.NewFloat(-10)), "-10"},
  39. }.validate(t)
  40. }