Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics APIs #119

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Statistics APIs #119

wants to merge 6 commits into from

Conversation

nowsprinting
Copy link
Owner

@nowsprinting nowsprinting commented Jan 13, 2025

Overview

TestHelper.Statistics namespace provides utilities for statistical testing, including assertions for pseudo-random number generators (PRNG) and statistical summary tools.

Warning

  • This feature is experimental.
  • This feature is NOT statistical hypothesis testing tool.

Experiment and plot to character-based histogram

Usage:

[TestFixture]
public class MyStatisticalTest
{
    [Test]
    public void Histogram_2D6()
    {
        var sampleSpace = Experiment.Run(
            () => DiceGenerator.Roll(2, 6), // 2D6
            1 << 20); // 1,048,576 times

        Assert.That(sampleSpace.Max, Is.EqualTo(12));
        Assert.That(sampleSpace.Min, Is.EqualTo(2));

        var histogram = new Histogram<int>();
        histogram.Plot(sampleSpace);
        Debug.Log(histogram.GetSummary()); // Write to console
    }
}

Console output example:

Experimental and Statistical Summary:
  Sample size: 1,048,576
  Maximum: 12
  Minimum: 2
  Peak frequency: 174,554
  Valley frequency: 29,070
  Median: 87,490
  Mean: 95,325.09
  Histogram: ▁▂▃▅▆█▆▅▃▂▁
  (Each bar represents the frequency of values in equally spaced bins.)

TODO

  • Outputs pixel plot image
  • Outputs graphical histogram
  • Assert repeating-sequence
  • Assert repeating-sequence in lower bits
  • Assert probability distribution
  • Big-size sample support

@github-actions github-actions bot added the enhancement New feature or request label Jan 13, 2025

This comment has been minimized.

Copy link

Code Metrics Report

master (1894e86) #119 (d005a61) +/-
Coverage 78.8% 81.8% +3.0%
Code to Test Ratio 1:0.7 1:0.8 +0.1
Test Execution Time 3m46s 3m47s +1s
Details
  |                     | master (1894e86) | #119 (d005a61) |  +/-  |
  |---------------------|------------------|----------------|-------|
+ | Coverage            |            78.8% |          81.8% | +3.0% |
  |   Files             |               35 |             39 |    +4 |
  |   Lines             |             1067 |           1246 |  +179 |
+ |   Covered           |              841 |           1020 |  +179 |
+ | Code to Test Ratio  |            1:0.7 |          1:0.8 |  +0.1 |
  |   Code              |             1863 |           2108 |  +245 |
+ |   Test              |             1457 |           1885 |  +428 |
- | Test Execution Time |            3m46s |          3m47s |   +1s |

Code coverage of files in pull request scope (0.0% → 100.0%)

Files Coverage +/-
Runtime/Statistics/Experiment.cs 100.0% +100.0%
Runtime/Statistics/Histograms/Bin.cs 100.0% +100.0%
Runtime/Statistics/Histograms/Histogram.cs 100.0% +100.0%
Runtime/Statistics/SampleSpace.cs 100.0% +100.0%

Reported by octocov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant