-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transform_methods.js
More file actions
82 lines (64 loc) · 1.98 KB
/
test_transform_methods.js
File metadata and controls
82 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import stream from 'node:stream';
console.log('=== Testing Transform Collection Methods ===\n');
let allResults = {
map: [],
filter: [],
drop: [],
take: [],
flatMap: []
};
// Test 1: map()
console.log('1. Testing map()...');
const readable1 = stream.Readable.from([1, 2, 3, 4, 5]);
const mapped = readable1.map(x => x * 2);
mapped.on('data', chunk => {
allResults.map.push(chunk);
});
mapped.on('end', () => {
console.log(' ✓ map() results:', allResults.map);
});
// Test 2: filter()
console.log('\n2. Testing filter()...');
const readable2 = stream.Readable.from([1, 2, 3, 4, 5, 6]);
const filtered = readable2.filter(x => x % 2 === 0);
filtered.on('data', chunk => {
allResults.filter.push(chunk);
});
filtered.on('end', () => {
console.log(' ✓ filter() results:', allResults.filter);
});
// Test 3: drop()
console.log('\n3. Testing drop()...');
const readable3 = stream.Readable.from(['a', 'b', 'c', 'd', 'e']);
const dropped = readable3.drop(2);
dropped.on('data', chunk => {
allResults.drop.push(chunk);
});
dropped.on('end', () => {
console.log(' ✓ drop(2) results:', allResults.drop);
});
// Test 4: take()
console.log('\n4. Testing take()...');
const readable4 = stream.Readable.from(['A', 'B', 'C', 'D', 'E']);
const taken = readable4.take(3);
taken.on('data', chunk => {
allResults.take.push(chunk);
});
taken.on('end', () => {
console.log(' ✓ take(3) results:', allResults.take);
});
// Test 5: flatMap()
console.log('\n5. Testing flatMap()...');
const readable5 = stream.Readable.from([1, 2, 3]);
const flatMapped = readable5.flatMap(x => [x, x * 2]);
flatMapped.on('data', chunk => {
allResults.flatMap.push(chunk);
});
flatMapped.on('end', () => {
console.log(' ✓ flatMap() results:', allResults.flatMap);
});
// Wait for all async operations
setTimeout(() => {
console.log('\n=== Tests Complete ===');
process.exit(0);
}, 500);