Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions pkg/stats/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,57 +135,3 @@ func TestSpec_PublicAPI_Median_EvenCount(t *testing.T) {
assert.InDelta(t, 2.5, sv.Median(), 1e-9,
"Median with even count should return the average of the two middle sorted values")
}

// TestSpec_PublicAPI_Sum validates that Sum returns the arithmetic sum of all
// observations as described in the package README.md.
//
// Specification: "Sum: Returns the arithmetic sum"
func TestSpec_PublicAPI_Sum(t *testing.T) {
var sv StatVar

assert.InDelta(t, 0.0, sv.Sum(), 1e-9, "Sum should return 0 for an empty StatVar")

sv.Add(10.0)
sv.Add(20.0)
sv.Add(30.0)

assert.InDelta(t, 60.0, sv.Sum(), 1e-9, "Sum should return the total of all observations")
}

// TestSpec_PublicAPI_Variance validates that Variance returns the population
// variance (N denominator) as described in the package README.md.
//
// Specification: "Variance: Returns population variance (N denominator)"
//
// Example: values [2,4,4,4,5,5,7,9] (N=8, mean=5, sum_sq_dev=32) → population variance = 32/8 = 4
func TestSpec_PublicAPI_Variance(t *testing.T) {
var sv StatVar

assert.InDelta(t, 0.0, sv.Variance(), 1e-9, "Variance should return 0 for an empty StatVar")

for _, v := range []float64{2, 4, 4, 4, 5, 5, 7, 9} {
sv.Add(v)
}

assert.InDelta(t, 4.0, sv.Variance(), 1e-9,
"Variance should use N (population) denominator: sum_sq_dev / N")
}

// TestSpec_PublicAPI_StdDev validates that StdDev returns the population
// standard deviation as described in the package README.md.
//
// Specification: "StdDev: Returns population standard deviation"
func TestSpec_PublicAPI_StdDev(t *testing.T) {
var sv StatVar

assert.InDelta(t, 0.0, sv.StdDev(), 1e-9, "StdDev should return 0 for an empty StatVar")

for _, v := range []float64{2, 4, 4, 4, 5, 5, 7, 9} {
sv.Add(v)
}

assert.InDelta(t, math.Sqrt(sv.Variance()), sv.StdDev(), 1e-9,
"StdDev should equal sqrt(Variance)")
assert.InDelta(t, 2.0, sv.StdDev(), 1e-9,
"StdDev of [2,4,4,4,5,5,7,9] should be 2 (population stddev)")
}
17 changes: 0 additions & 17 deletions pkg/stats/statvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ func (s *StatVar) Max() float64 {
return s.max
}

// Sum returns the arithmetic sum of all observations, or 0 if none.
func (s *StatVar) Sum() float64 { return s.sum }

// Mean returns the arithmetic mean of all observations, or 0 if none.
func (s *StatVar) Mean() float64 {
if s.count == 0 {
Expand All @@ -88,20 +85,6 @@ func (s *StatVar) Mean() float64 {
return s.mean
}

// Variance returns the population variance (divides by N). Returns 0 when no
// observations are present.
func (s *StatVar) Variance() float64 {
if s.count == 0 {
return 0
}
return s.m2 / float64(s.count)
}

// StdDev returns the population standard deviation (sqrt of Variance).
func (s *StatVar) StdDev() float64 {
return math.Sqrt(s.Variance())
}

// SampleVariance returns the sample variance with Bessel's correction (divides
// by N−1), giving an unbiased estimator when the observations are a random
// sample from a larger population. Returns 0 when fewer than two observations
Expand Down
Loading