zatu
v0.0.9
Published
A simple test utility to run a functions against a set of test cases and log the results.
Downloads
55
Readme
ZATU
USAGE: You would need to define your function and test cases
object before calling the test function, as in your original prompt.
Example structure to run this utility:
import { assertEqual } from "zatu";
function isPrimeNumber(input) {
// Function implementation goes here
const n = Number(input);
if (!Number.isInteger(n) || n <= 1) return false;
if (n === 2) return true;
// ... rest of the logic
return true;
}
const examplePrimeNumbers = {
"0": false,
"1": false,
"2": true,
"4": false,
"7": true,
// ... rest of the test cases
}; // Your test cases
assertEqual(isPrimeNumber, examplePrimeNumbers);Dynamic Import
const importPkg = async url => await import(`data:text/javascript,${encodeURIComponent(await (await fetch(url)).text())}`);
const z = await importPkg("https://unpkg.com/zatu@latest/assertEqual");
z.assertEqual(isPrimeNumber, examplePrimeNumbers);Example Test Cases
z.assertEqual(fn, {
// Single value functions
"1": 1,
"5": 120,
// Boolean / primitive outputs
"1": false,
"2": true,
// Array input (single param)
"[1,2,3]": false,
"[1,1,2]": true,
// Tuple input (spread into multiple params)
'["anagram","nagaram"]': true,
'["rat","car"]': false,
// Objects
'{"name":"rahul","age":30}': true,
// Strings
'"hello"': 5,
'"abc"': 3,
// Mixed
"10": true,
"[1,2,3]": false,
'["a","b"]': true,
'{"x":1}': false,
"0": false,
// Nested arrays
'["eat","tea","tan","ate","nat","bat"]': [["eat","tea","ate"],["tan","nat"],["bat"]],
'["abc","bca","cab","bac","acb"]': [["abc","bca","cab","bac","acb"]],
'[]': []
});
