03568c88e3
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package datascience
|
|
|
|
import "testing"
|
|
|
|
func TestPercentile(t *testing.T) {
|
|
t.Run("slice vacio retorna cero", func(t *testing.T) {
|
|
got := Percentile([]int64{}, 0.5)
|
|
if got != 0 {
|
|
t.Errorf("got %v, want 0", got)
|
|
}
|
|
})
|
|
|
|
t.Run("un solo elemento retorna ese elemento", func(t *testing.T) {
|
|
got := Percentile([]int64{42}, 0.5)
|
|
if got != 42 {
|
|
t.Errorf("got %v, want 42", got)
|
|
}
|
|
})
|
|
|
|
t.Run("p0 retorna minimo", func(t *testing.T) {
|
|
got := Percentile([]int64{10, 20, 30, 40, 50}, 0.0)
|
|
if got != 10 {
|
|
t.Errorf("got %v, want 10", got)
|
|
}
|
|
})
|
|
|
|
t.Run("p100 retorna maximo", func(t *testing.T) {
|
|
got := Percentile([]int64{10, 20, 30, 40, 50}, 1.0)
|
|
if got != 50 {
|
|
t.Errorf("got %v, want 50", got)
|
|
}
|
|
})
|
|
|
|
t.Run("p50 retorna mediana de cinco elementos", func(t *testing.T) {
|
|
got := Percentile([]int64{10, 20, 30, 40, 50}, 0.5)
|
|
if got != 30 {
|
|
t.Errorf("got %v, want 30", got)
|
|
}
|
|
})
|
|
|
|
t.Run("p90 de diez elementos usa idx int truncado", func(t *testing.T) {
|
|
// idx = int(9 * 0.9) = int(8.1) = 8 → sorted[8] = 9
|
|
got := Percentile([]int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0.9)
|
|
if got != 9 {
|
|
t.Errorf("got %v, want 9", got)
|
|
}
|
|
})
|
|
|
|
t.Run("p99 de slice pequeno usa idx truncado a cero", func(t *testing.T) {
|
|
// idx = int(1 * 0.99) = int(0.99) = 0 → sorted[0] = 100
|
|
got := Percentile([]int64{100, 200}, 0.99)
|
|
if got != 100 {
|
|
t.Errorf("got %v, want 100", got)
|
|
}
|
|
})
|
|
}
|