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. Unlike4
// the per-function compile-run tests (tests/purrc/statistics_cr_test.cpp), this5
// drives a single cohesive program over ONE fixed dataset through EVERY6
// purr-callable statistics function and asserts its exact stdout, so the7
// 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.511
// (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"17
TEST(StdlibE2E, Statistics) {18
e2e::expect_e2e("statistics_sys", R"PURR(import io19
import statistics21
let xs = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]23
io.print(statistics.sum(xs))24
io.print(statistics.count(xs))25
io.print(statistics.mean(xs))26
io.print(statistics.pvariance(xs))27
io.print(statistics.pstdev(xs))28
io.print(statistics.variance(xs))29
io.print(statistics.stdev(xs))30
io.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");40
}