MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / runTests

Function runTests

libCacheSim-node/test.js:32–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32function runTests() {
33 let passed = 0;
34 let total = 0;
35
36 function test(description, testFn) {
37 total++;
38 log('blue', `\nTest: ${description}`);
39 try {
40 if (testFn()) {
41 passed++;
42 }
43 } catch (error) {
44 log('red', `✗ ${description} - Error: ${error.message}`);
45 }
46 }
47
48 log('yellow', '=== libCacheSim Node.js Bindings Test Suite ===\n');
49
50 // Test 1: Check if module loads correctly
51 test('Module loads correctly', () => {
52 return assert(typeof libCacheSim === 'object', 'libCacheSim module is an object') &&
53 assert(typeof libCacheSim.runSim === 'function', 'runSim function exists') &&
54 assert(typeof libCacheSim.runSimulation === 'function', 'runSimulation function exists') &&
55 assert(typeof libCacheSim.getSupportedAlgorithms === 'function', 'getSupportedAlgorithms function exists') &&
56 assert(typeof libCacheSim.getSupportedTraceTypes === 'function', 'getSupportedTraceTypes function exists');
57 });
58
59 // Test 2: Check supported algorithms
60 test('Get supported algorithms', () => {
61 const algorithms = libCacheSim.getSupportedAlgorithms();
62 return assert(Array.isArray(algorithms), 'Returns an array') &&
63 assert(algorithms.length > 0, 'Array is not empty') &&
64 assert(algorithms.includes('lru'), 'Includes LRU') &&
65 assert(algorithms.includes('s3fifo'), 'Includes S3-FIFO') &&
66 assert(algorithms.includes('sieve'), 'Includes Sieve');
67 });
68
69 // Test 3: Check supported trace types
70 test('Get supported trace types', () => {
71 const traceTypes = libCacheSim.getSupportedTraceTypes();
72 return assert(Array.isArray(traceTypes), 'Returns an array') &&
73 assert(traceTypes.length > 0, 'Array is not empty') &&
74 assert(traceTypes.includes('vscsi'), 'Includes VSCSI') &&
75 assert(traceTypes.includes('csv'), 'Includes CSV');
76 });
77
78 // Test 4: Run default simulation
79 test('Run default simulation', () => {
80 const result = libCacheSim.runSim();
81 return assert(typeof result === 'object', 'Returns an object') &&
82 assert(typeof result.totalRequests === 'number', 'Has totalRequests as number') &&
83 assert(typeof result.hits === 'number', 'Has hits as number') &&
84 assert(typeof result.misses === 'number', 'Has misses as number') &&
85 assert(typeof result.hitRatio === 'number', 'Has hitRatio as number') &&
86 assert(typeof result.missRatio === 'number', 'Has missRatio as number') &&
87 assert(result.totalRequests === result.hits + result.misses, 'Total requests equals hits + misses') &&
88 assert(Math.abs(result.hitRatio + result.missRatio - 1.0) < 0.0001, 'Hit ratio + miss ratio ≈ 1.0');
89 });

Callers 1

test.jsFile · 0.85

Calls 3

logFunction · 0.85
testFunction · 0.85
assertFunction · 0.85

Tested by

no test coverage detected