Intelligence, Advanced Charting & Trading Platform
test: define deterministic quality scoring
davoodmehraban89 committed
Oct 5, 2026 at 16:37 UTC
f9c1edb1ff4d93430dc9338fc39972f4b12dabbd
1 file changed
+20
packages/market-domain/test/quality-score.test.mjs
new
+20
@@ -0,0 +1,20 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { qualityScore } from '../src/quality-score.mjs';
4
+
5
+test('scores healthy fresh observations at 100', () => {
6
+ assert.equal(qualityScore({ state: 'GOOD', flags: [], ageRatio: 0.1 }), 100);
7
+});
8
+
9
+test('penalizes divergence and approaching staleness deterministically', () => {
10
+ const score = qualityScore({ state: 'DEGRADED', flags: ['PROVIDER_DIVERGENCE'], ageRatio: 0.8 });
11
+ assert.equal(score, 55);
12
+});
13
+
14
+test('caps stale observations below healthy presentation threshold', () => {
15
+ assert.ok(qualityScore({ state: 'STALE', flags: ['STALE_SOURCE'], ageRatio: 2 }) <= 30);
16
+});
17
+
18
+test('invalid observations always score zero', () => {
19
+ assert.equal(qualityScore({ state: 'INVALID', flags: ['NON_POSITIVE_PRICE'], ageRatio: 0 }), 0);
20
+});