Skip to content

Commit d65edcc

Browse files
committed
Add sum verification to tests
1 parent 91b3e62 commit d65edcc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

test/integration/v2/stream-data-types.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe("advanced stream tests", () => {
7474
const initialMemory = process.memoryUsage();
7575
let maxMemoryUsed = initialMemory.heapUsed;
7676
let rowCount = 0;
77+
let idSum = 0; // Track sum of id column for data integrity verification
7778

7879
// Create a JSON transform stream with minimal allocation
7980
const jsonTransform = new stream.Transform({
@@ -87,6 +88,11 @@ describe("advanced stream tests", () => {
8788
try {
8889
rowCount++;
8990

91+
// Add the id to our sum for data integrity verification
92+
const typedRow = row as Record<string, unknown>;
93+
const id = typedRow.id as number;
94+
idSum += id;
95+
9096
if (rowCount % 5000 === 0) {
9197
const currentMemory = process.memoryUsage();
9298
maxMemoryUsed = Math.max(maxMemoryUsed, currentMemory.heapUsed);
@@ -232,6 +238,10 @@ describe("advanced stream tests", () => {
232238
expect(rowCount).toBe(seriesNum);
233239
expect(processedChunks).toBeGreaterThan(0);
234240

241+
// Verify data integrity: sum of 1 to N should be N*(N+1)/2
242+
const expectedSum = (seriesNum * (seriesNum + 1)) / 2;
243+
expect(idSum).toBe(expectedSum);
244+
235245
// Verify the file was created and has content
236246
expect(fs.existsSync(tempFilePath)).toBe(true);
237247
const fileStats = fs.statSync(tempFilePath);

test/integration/v2/stream.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ describe("streams", () => {
177177
const initialMemory = process.memoryUsage();
178178
let maxMemoryUsed = initialMemory.heapUsed;
179179
let rowCount = 0;
180+
let idSum = 0;
180181

181182
// Process data with simple event handlers (like existing tests)
182-
data.on("data", () => {
183+
data.on("data", row => {
183184
rowCount++;
185+
idSum += row[0]; // Sum the id values for data integrity
184186

185187
// Track memory usage periodically
186188
if (rowCount % 50 === 0) {
@@ -197,6 +199,10 @@ describe("streams", () => {
197199

198200
// Verify the data was processed correctly
199201
expect(rowCount).toBe(1000000);
202+
203+
// Verify data integrity with sum check
204+
const expectedSum = (1000000 * 1000001) / 2; // Sum of 1 to 1,000,000
205+
expect(idSum).toBe(expectedSum);
200206

201207
// Memory usage should remain reasonable with proper streaming
202208
const memoryGrowth =

0 commit comments

Comments
 (0)