package utility_test import ( "testing" "code.nonshy.com/nonshy/website/pkg/utility" ) func TestNumberFormat(t *testing.T) { var tests = []struct { In int64 Expect string }{ {0, "0"}, {1, "1"}, {10, "10"}, {15, "15"}, {92, "92"}, {100, "100"}, {101, "101"}, {150, "150"}, {200, "200"}, {404, "404"}, {867, "867"}, {990, "990"}, {999, "999"}, {1000, "1K"}, {1001, "1K"}, {1010, "1K"}, {1100, "1.1K"}, {1111, "1.1K"}, {1200, "1.2K"}, {1500, "1.5K"}, {1700, "1.7K"}, {1849, "1.8K"}, {1850, "1.9K"}, {1899, "1.9K"}, {1900, "1.9K"}, {12000, "12K"}, {12300, "12.3K"}, {900000, "900K"}, {900100, "900.1K"}, {999100, "999.1K"}, {999500, "999.5K"}, {999999, "1000K"}, // TODO: not ideal {1000000, "1M"}, {1001000, "1M"}, {1005000, "1M"}, {1010000, "1M"}, {1100000, "1.1M"}, {1200000, "1.2M"}, {1305000, "1.3M"}, {1350000, "1.4M"}, {1400000, "1.4M"}, {100000000, "100M"}, {990509000, "990.5M"}, {1000000000, "1B"}, } for _, test := range tests { actual := utility.FormatNumberShort(test.In) if actual != test.Expect { t.Errorf("Expected %d to be '%s' but got '%s'", test.In, test.Expect, actual) } } }