MCPcopy Create free account
hub / github.com/github/gh-aw / TestFormatNumber

Function TestFormatNumber

pkg/console/render_test.go:330–381  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

328}
329
330func TestFormatNumber(t *testing.T) {
331 tests := []struct {
332 input int
333 expected string
334 }{
335 // Zero
336 {0, "0"},
337 // Small numbers (under 1000)
338 {5, "5"},
339 {42, "42"},
340 {999, "999"},
341 // Thousands (1k-999k)
342 {1000, "1.00k"}, // Under 10k: 2 decimal places
343 {1200, "1.20k"},
344 {1234, "1.23k"},
345 {9999, "10.00k"}, // 9999/1000 = 9.999 -> formats as 10.00k
346 {10000, "10.0k"}, // 10k-99k: 1 decimal place
347 {12000, "12.0k"},
348 {12300, "12.3k"},
349 {99999, "100.0k"}, // 99999/1000 = 99.999 -> formats as 100.0k
350 {100000, "100k"}, // 100k+: no decimal places
351 {123000, "123k"},
352 {999999, "1000k"}, // 999999/1000 = 999.999 -> formats as 1000k
353 // Millions (1M-999M)
354 {1000000, "1.00M"}, // Under 10M: 2 decimal places
355 {1200000, "1.20M"},
356 {1234567, "1.23M"},
357 {9999999, "10.00M"}, // 9999999/1000000 = 9.999999 -> formats as 10.00M
358 {10000000, "10.0M"}, // 10M-99M: 1 decimal place
359 {12000000, "12.0M"},
360 {12300000, "12.3M"},
361 {99999999, "100.0M"}, // 99999999/1000000 = 99.999999 -> formats as 100.0M
362 {100000000, "100M"}, // 100M+: no decimal places
363 {123000000, "123M"},
364 {999999999, "1000M"}, // 999999999/1000000 = 999.999999 -> formats as 1000M
365 // Billions (1B+)
366 {1000000000, "1.00B"}, // Under 10B: 2 decimal places
367 {1200000000, "1.20B"},
368 {1234567890, "1.23B"},
369 {9999999999, "10.00B"}, // 9999999999/1000000000 = 9.999999999 -> formats as 10.00B
370 {10000000000, "10.0B"}, // 10B-99B: 1 decimal place
371 {12000000000, "12.0B"},
372 {99999999999, "100.0B"}, // 99999999999/1000000000 = 99.999999999 -> formats as 100.0B
373 {100000000000, "100B"}, // 100B+: no decimal places
374 {123000000000, "123B"},
375 }
376
377 for _, test := range tests {
378 result := FormatNumber(test.input)
379 assert.Equal(t, test.expected, result, "FormatNumber(%d) mismatch", test.input)
380 }
381}
382
383// TestRenderStruct_PointerToStruct tests that pointer-to-struct fields are rendered as nested structs, not raw data
384func TestRenderStruct_PointerToStruct(t *testing.T) {

Callers

nothing calls this directly

Calls 1

FormatNumberFunction · 0.85

Tested by

no test coverage detected