VictoriaMetrics/app/vmselect/promql/aggr_test.go
Aliaksandr Valialkin 388d020b7c
app/vmselect/promql: follow-up for ce4f26db02
- Document the bugfix at docs/CHANGELOG.md
- Filter out NaN values before sorting as suggested at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5509#discussion_r1447369218
- Revert unrelated changes in lib/filestream and lib/fs
- Use simpler test at app/vmselect/promql/exec_test.go

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5509
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5506
2024-01-16 02:55:08 +02:00

36 lines
916 B
Go

package promql
import (
"math"
"testing"
)
func TestModeNoNaNs(t *testing.T) {
f := func(prevValue float64, a []float64, expectedResult float64) {
t.Helper()
result := modeNoNaNs(prevValue, a)
if math.IsNaN(result) {
if !math.IsNaN(expectedResult) {
t.Fatalf("unexpected result; got %v; want %v", result, expectedResult)
}
return
}
if result != expectedResult {
t.Fatalf("unexpected result; got %v; want %v", result, expectedResult)
}
}
f(nan, nil, nan)
f(nan, []float64{123}, 123)
f(nan, []float64{1, 2, 3}, 1)
f(nan, []float64{1, 2, 2}, 2)
f(nan, []float64{1, 1, 2}, 1)
f(nan, []float64{1, 1, 1}, 1)
f(nan, []float64{1, 2, 2, 3}, 2)
f(nan, []float64{1, 1, 2, 2, 3, 3, 3}, 3)
f(1, []float64{2, 3, 4, 5}, 1)
f(1, []float64{2, 2}, 2)
f(1, []float64{2, 3, 3}, 3)
f(1, []float64{2, 4, 3, 4, 3, 4}, 4)
f(1, []float64{2, 3, 3, 4, 4}, 3)
f(1, []float64{4, 3, 2, 3, 4}, 3)
}