(t *testing.T)
| 79 | } |
| 80 | |
| 81 | func TestStatVar_KnownVariance(t *testing.T) { |
| 82 | // Dataset: [2, 4, 4, 4, 5, 5, 7, 9] |
| 83 | // N=8, mean=5, population variance=4, population stddev=2 |
| 84 | // Sample variance = 32/7, sample stddev = sqrt(32/7) |
| 85 | values := []float64{2, 4, 4, 4, 5, 5, 7, 9} |
| 86 | var s StatVar |
| 87 | for _, v := range values { |
| 88 | s.Add(v) |
| 89 | } |
| 90 | |
| 91 | require.Equal(t, 8, s.Count(), "known: count should be 8") |
| 92 | assert.InDelta(t, 5.0, s.Mean(), 1e-9, "known: mean should be 5") |
| 93 | assert.InDelta(t, 32.0/7.0, s.SampleVariance(), 1e-9, "known: sample variance should be 32/7") |
| 94 | assert.InDelta(t, math.Sqrt(32.0/7.0), s.SampleStdDev(), 1e-9, "known: sample stddev should be sqrt(32/7)") |
| 95 | // Median of [2,4,4,4,5,5,7,9] → (4+5)/2 = 4.5 |
| 96 | assert.InDelta(t, 4.5, s.Median(), 1e-9, "known: median should be 4.5") |
| 97 | } |
| 98 | |
| 99 | func TestStatVar_NumericalStability(t *testing.T) { |
| 100 | // Test with large values close together (catastrophic cancellation case). |
nothing calls this directly
no test coverage detected