MCPcopy Create free account
hub / github.com/github/gh-aw / TestStatVar_KnownVariance

Function TestStatVar_KnownVariance

pkg/stats/statvar_test.go:81–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func 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
99func TestStatVar_NumericalStability(t *testing.T) {
100 // Test with large values close together (catastrophic cancellation case).

Callers

nothing calls this directly

Calls 6

AddMethod · 0.95
CountMethod · 0.95
MeanMethod · 0.95
SampleVarianceMethod · 0.95
SampleStdDevMethod · 0.95
MedianMethod · 0.95

Tested by

no test coverage detected