cheatah
Source

tests/purrc/statistics_sys_test.cpp

1// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).
2// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.
3// System-level (whole-program) test for the `statistics` stdlib module. Unlike
4// the per-function compile-run tests (tests/purrc/statistics_cr_test.cpp), this
5// drives a single cohesive program over ONE fixed dataset through EVERY
6// purr-callable statistics function and asserts its exact stdout, so the
7// functions are exercised together against the same data.
8//
9// Fixed dataset {2,4,4,4,5,5,7,9}: sum 40, count 8, mean 5, pvariance 4,
10// pstdev 2, variance 32/7 (≈4.57143), stdev sqrt(32/7) (≈2.13809), median 4.5
11// (mean of the two middle values 4 and 5). Fully deterministic.
12//
13// Coverage — every function in stdlib/statistics/statistics.hpp:
14// sum, count, mean, pvariance, pstdev, variance, stdev, median.
15#include "e2e_harness.hpp"
17TEST(StdlibE2E, Statistics) {
18 e2e::expect_e2e("statistics_sys", R"PURR(import io
19import statistics
21let xs = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
23io.print(statistics.sum(xs))
24io.print(statistics.count(xs))
25io.print(statistics.mean(xs))
26io.print(statistics.pvariance(xs))
27io.print(statistics.pstdev(xs))
28io.print(statistics.variance(xs))
29io.print(statistics.stdev(xs))
30io.print(statistics.median(xs))
31)PURR",
32 "40\n"
33 "8\n"
34 "5\n"
35 "4\n"
36 "2\n"
37 "4.57143\n"
38 "2.13809\n"
39 "4.5\n");