-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3.test.js
More file actions
27 lines (19 loc) · 838 Bytes
/
ex3.test.js
File metadata and controls
27 lines (19 loc) · 838 Bytes
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
'use strict';
const { createHandler } = require('./ex3');
function assert(condition, message) {
if (!condition) throw new Error(message || 'Assertion failed');
}
function makeLarge() {
// large payload: deterministic, no timing
return new Array(50_000).fill(0);
}
const h = createHandler(makeLarge);
// Behavior: still must compute using summary (length)
assert(h.handle(10) === 10 + 50_000, 'handle must use payload summary');
// Retention: should NOT retain the full payload strongly.
// We accept retaining only the summary number, so retainedSize should be "small".
assert(h.retainedSize() <= 8, 'handler must not retain full payload (retain only summary)');
// After release, retainedSize must be 0.
h.release();
assert(h.retainedSize() === 0, 'release must drop retained references');
console.log('ex3 tests passed');