chore: add various tests

This commit is contained in:
2025-12-13 14:04:32 -05:00
parent bc076a4f44
commit 8fd2aeb6a2
7 changed files with 226 additions and 7 deletions

View File

@@ -0,0 +1,22 @@
package formatters
import (
"testing"
"time"
)
func TestFormatDuration(t *testing.T) {
tests := []struct {
dur time.Duration
want string
}{
{0, "N/A"},
{22*24*time.Hour + 7*time.Hour + 39*time.Minute + 31*time.Second, "22d 7h 39m 31s"},
{5*time.Minute + 15*time.Second, "5m 15s"},
}
for _, tc := range tests {
if got := FormatDuration(tc.dur); got != tc.want {
t.Errorf("FormatDuration(%v) = %s, want %s", tc.dur, got, tc.want)
}
}
}

View File

@@ -0,0 +1,22 @@
package formatters
import (
"testing"
)
func TestFormatNumber(t *testing.T) {
tests := []struct {
input int64
want string
}{
{0, "0"},
{19823, "19.8k"},
{1500000, "1.50M"},
{-12345, "-12.3k"},
}
for _, tc := range tests {
if got := FormatNumber(tc.input); got != tc.want {
t.Errorf("FormatNumber(%d) = %s, want %s", tc.input, got, tc.want)
}
}
}