Skip to content

Commit 536753b

Browse files
algoflowsclaude
andcommitted
test(econify): add test for period-total count blocking in batch processing
- Tests Tourist Arrivals scenario (count + period-total) - Verifies value is only magnitude-scaled, not time-divided - Confirms explain metadata shows adjusted=false - All 460 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f8d55f6 commit 536753b

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

packages/econify/src/batch/temporal_aggregation_test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,45 @@ Deno.test("Batch: period-total allows time conversion", async () => {
5757
assertEquals(item.normalizedUnit, "USD millions per year");
5858
});
5959

60+
Deno.test("Batch: period-total BLOCKS time conversion for discrete types (count)", async () => {
61+
// Tourist Arrivals scenario: count + period-total should NOT be time-converted
62+
const items: BatchItem[] = [
63+
{
64+
id: "TOURIST_ARRIVALS",
65+
name: "Tourist Arrivals",
66+
value: 520394,
67+
unit: "Thousands",
68+
periodicity: "Quarterly",
69+
indicator_type: "count", // Discrete type
70+
temporal_aggregation: "period-total", // Total over quarter
71+
},
72+
];
73+
74+
const result = await processBatch(items, {
75+
toTimeScale: "month",
76+
toMagnitude: "ones",
77+
explain: true,
78+
});
79+
80+
assertEquals(result.successful.length, 1);
81+
const item = result.successful[0];
82+
83+
// Should ONLY apply magnitude scaling (thousands -> ones)
84+
// Should NOT divide by 3 (quarter -> month)
85+
assertEquals(item.normalized, 520394000); // 520394 * 1000, NOT ÷ 3
86+
assertEquals(item.normalizedUnit, "ones");
87+
88+
// Explain metadata should show adjusted=false
89+
assertExists(item.explain);
90+
assertExists(item.explain.periodicity);
91+
assertEquals(item.explain.periodicity.adjusted, false);
92+
assertEquals(item.explain.periodicity.factor, 1);
93+
assertEquals(
94+
item.explain.periodicity.description,
95+
"Time conversion blocked (count with period-total)",
96+
);
97+
});
98+
6099
Deno.test("Batch: period-rate allows time conversion", async () => {
61100
const items: BatchItem[] = [
62101
{

0 commit comments

Comments
 (0)