Skip to content

Test Suite 2 — Aggregation functions

mchristegh edited this page Jul 10, 2026 · 1 revision
Harness function suite2() in test-scripts/test-harness.js
Checks 9 (the # column below reconciles)
Kind Synchronous

Proves every numeric aggregation function against known values, including the trimmed mean's named fallback. Each scenario builds a fresh node with the function under test and a trigger value of 10000 (so the latch never interferes), feeds one reading per source, and reads the aggregate back via a query snapshot.

Baseline config (applies unless a scenario says otherwise): plain numeric node — Above-mode, trigger 10000, quorum and staleness disabled, Emit aggregate on change only checked, heartbeat off, persistence off; aggregation function per scenario.

Traceability convention: the Check column is the harness's literal PASS/FAIL string — a failing line in the test output can be searched in this document verbatim. This document moves with the harness: a new, renamed, or removed check lands here in the same change.


2.1 Simple functions

One reading per source, aggregate read via query.

# Check Protects
1 mean of 10,20,30 Arithmetic mean over fresh sources (expected 20)
2 median odd count 10,90,20 Median with an odd count picks the middle value (20), robust to the 90 outlier
3 median even count 10,20,30,40 Median with an even count averages the two middle values (25)
4 min of 7,3,9 Min for worst-case-style automations (3)
5 max of 7,3,9 Max for worst-case-style automations (9)

2.2 Trimmed mean and its named fallback

Three sources, then only two.

# Check Protects
6 trimmed mean drops high+low (10,50,90 -> 50) Trimmed mean drops the single highest and lowest fresh value
7 trimmed mean reports its name msg.aggregation names the function actually used (trimmedmean)
8 trimmed mean <3 sources falls back to mean Below 3 fresh sources the node silently falls back to mean (10,50 → 30) — never fails, never goes silent
9 fallback is named in the envelope The fallback is honest: msg.aggregation reports mean(fallback), not trimmedmean

Clone this wiki locally