Files
tia-love/internal/ui/components/sparkline_test.go
T

25 lines
690 B
Go

package components
import "testing"
func TestSparkline(t *testing.T) {
// nol semua → level terendah
if got := Sparkline([]float64{0, 0, 0}, 10); got != "▁▁▁" {
t.Fatalf("nol: %q", got)
}
// maksimum di tengah → blok penuh di sana (3.5 dibulatkan ke atas → ▅)
got := Sparkline([]float64{0, 50, 100, 50, 0}, 10)
want := "▁▅█▅▁"
if got != want {
t.Fatalf("grafik: %q, mau %q", got, want)
}
// pemotongan ke w terakhir (data terbaru di kanan)
got = Sparkline([]float64{100, 0, 0, 0}, 3)
if got != "▁▁▁" {
t.Fatalf("potong: %q", got)
}
if Sparkline(nil, 5) != "" || Sparkline([]float64{1}, 0) != "" {
t.Fatal("kasus kosong harus \"\"")
}
}