Skip to content

[Bug]: StdDev applies the sample divisor outside the square root and truncates integer variance #1181

Description

@dwcullop

Please note we can't commit to any timeline.

Describe the bug 🐞

Restoring deleted standard-deviation coverage reveals a numeric defect. All five numeric implementations divide sqrt(sum of squared deviations) by n-1 rather than taking sqrt(variance/(n-1)). Two-item examples hide this because the divisor is one. Integer implementations additionally truncate the mean-square term before computing variance.

Step to reproduce

Add three equally spaced generated values in one cache or list edit. Their sample standard deviation must equal the spacing. Exercise int, long, float, double and decimal selectors. Also use integer data with a fractional mean and compare with the sample-variance formula.

Regression tests/checks:

StdDevFixture.Cache_ThreeEquallySpacedValues_ReportsTheirSpacing; StdDevFixture.List_ThreeEquallySpacedValues_ReportsTheirSpacing; StdDevFixture.IntegerValues_FractionalMean_PreservesFractionalVariance

Reproduction repository

https://github.com/reactivemarbles/DynamicData/tree/85ee49cfd54d8782c36ed137886d318e942345c4

Regression tests and fixes:
https://github.com/reactivemarbles/DynamicData/tree/u/dacullop/main/pr-1165-review

Expected behavior

Return sqrt(sum((value - mean)^2)/(n-1)), preserving fractional means/variance for integer inputs. Continue using the configured fallback for fewer than two items.

Screenshots 🖼️

N/A.

IDE

N/A; command-line reproduction.

Operating system

Windows.

Version

.NET SDK 10.0.401; net9.0 test target.

Device

N/A.

DynamicData Version

Main 10.0-preview at 85ee49c. The related 9.5 candidate is PR #1165 at 3d76872.

Additional information ℹ️

Twelve repository cases fail on unchanged main: expected 3, actual about 2.1213203435596424; fractional-mean expected 5.033222956847166, actual 3.570714214271425. Seventeen cases pass after correcting the expressions, including fallback controls.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions