mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-07-18 05:45:46 +00:00
Compare commits
20 Commits
1dfaf490cd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6f8b6ad90 | ||
|
|
b552fc6f93 | ||
|
|
d5e4ee5f44 | ||
|
|
6c0f3f8e8c | ||
|
|
3531ba9742 | ||
| d881df7814 | |||
|
|
302f129522 | ||
| c2950d20e7 | |||
|
|
0d119317eb | ||
| 866e5c2bbb | |||
|
|
48dfa6cd44 | ||
| 0c2cd5e395 | |||
|
|
c263572691 | ||
| 49dadb5155 | |||
|
|
d4ae079fea | ||
| 3cd4fa5ca6 | |||
|
|
0819bbafd9 | ||
| 2d6858fdb4 | |||
|
|
e5f1b816d1 | ||
| 39d0a9f316 |
14
README
14
README
@@ -9,18 +9,20 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
|
||||
The following models are included in the benchmark run.
|
||||
|
||||
<!-- MODELS_START -->
|
||||
moonshotai/kimi-k3 EFF:medium
|
||||
openai/gpt-5.6-luna EFF:high
|
||||
x-ai/grok-4.5
|
||||
anthropic/claude-sonnet-5 EFF:high
|
||||
z-ai/glm-5.2
|
||||
moonshotai/kimi-k2.7-code
|
||||
anthropic/claude-fable-5
|
||||
anthropic/claude-opus-4.8 EFF:medium
|
||||
google/gemini-3.5-flash
|
||||
google/gemini-3.1-flash-lite
|
||||
openai/gpt-5.5 EFF:high
|
||||
deepseek/deepseek-v4-pro
|
||||
moonshotai/kimi-k2.6
|
||||
anthropic/claude-opus-4.7 EFF:medium
|
||||
z-ai/glm-5.1
|
||||
openai/gpt-5.4
|
||||
openai/gpt-5.3-codex
|
||||
google/gemini-3.1-pro-preview
|
||||
anthropic/claude-opus-4.6
|
||||
moonshotai/kimi-k2.5
|
||||
google/gemini-3-flash-preview TEMP:0.35
|
||||
deepseek/deepseek-v3.2
|
||||
<!-- MODELS_END -->
|
||||
|
||||
@@ -26,7 +26,13 @@ const apiCall = async (prompt, model, temp, effort) => {
|
||||
...(temp !== undefined && { temperature: temp }),
|
||||
...(effort && { reasoning: { effort } })
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${process.env.OPENROUTER_KEY}` } }
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.OPENROUTER_KEY}`,
|
||||
'HTTP-Referer': 'https://lynchmark.com',
|
||||
'X-Title': 'Lynchmark'
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!res.data.choices || !res.data.choices[0]) {
|
||||
console.error('API Response:', JSON.stringify(res.data, null, 2));
|
||||
|
||||
9
tests/10_scrypt_hash/outputs/anthropic_claude-fable-5.js
Normal file
9
tests/10_scrypt_hash/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const hashPassword = async (password, salt) => {
|
||||
const { scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm');
|
||||
const enc = new TextEncoder();
|
||||
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||
return [...hash].map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
};
|
||||
export default hashPassword;
|
||||
// Generation time: 5.733s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,9 @@
|
||||
const hashPassword = async (password, salt) => {
|
||||
const { scrypt } = await import("https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm");
|
||||
const enc = new TextEncoder();
|
||||
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||
return [...hash].map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
};
|
||||
export default hashPassword;
|
||||
// Generation time: 2.918s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,15 @@
|
||||
async function hashPassword(password, salt) {
|
||||
const { default: scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm');
|
||||
|
||||
const enc = new TextEncoder();
|
||||
const passBuf = enc.encode(password);
|
||||
const saltBuf = enc.encode(salt);
|
||||
|
||||
const N = 1024, r = 8, p = 1, dkLen = 32;
|
||||
const derivedKey = await scrypt(passBuf, saltBuf, N, r, p, dkLen);
|
||||
|
||||
return Array.from(derivedKey, b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 4.636s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,9 @@
|
||||
const hashPassword = async (password, salt) => {
|
||||
const { default: scrypt } = await import('https://esm.sh/scrypt-js');
|
||||
const enc = new TextEncoder();
|
||||
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||
return Array.from(hash, b => b.toString(16).padStart(2, '0')).join('');
|
||||
};
|
||||
export default hashPassword;
|
||||
// Generation time: 16.829s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,11 @@
|
||||
const SCRYPT_URL = "https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm";
|
||||
|
||||
async function hashPassword(password, salt) {
|
||||
const { scrypt } = await import(SCRYPT_URL);
|
||||
const enc = new TextEncoder();
|
||||
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||
return Array.from(hash, b => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 36.726s
|
||||
// Result: PASS
|
||||
15
tests/10_scrypt_hash/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
15
tests/10_scrypt_hash/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,15 @@
|
||||
async function hashPassword(password, salt) {
|
||||
const scryptModule = await import(
|
||||
"https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm"
|
||||
);
|
||||
const scrypt = scryptModule.default ?? scryptModule.scrypt;
|
||||
|
||||
const passwordBytes = new TextEncoder().encode(password);
|
||||
const saltBytes = new TextEncoder().encode(salt);
|
||||
const hash = await scrypt(passwordBytes, saltBytes, 1024, 8, 1, 32);
|
||||
|
||||
return Array.from(hash, byte => byte.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 8.694s
|
||||
// Result: FAIL
|
||||
10
tests/10_scrypt_hash/outputs/x-ai_grok-4.5.js
Normal file
10
tests/10_scrypt_hash/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,10 @@
|
||||
async function hashPassword(password,salt){
|
||||
const{default:scrypt}=await import("https://esm.sh/scrypt-js@3.0.1");
|
||||
const enc=new TextEncoder;
|
||||
const p=enc.encode(password),s=enc.encode(salt);
|
||||
const hash=await scrypt(p,s,1024,8,1,32);
|
||||
return Array.from(hash).map(b=>b.toString(16).padStart(2,"0")).join("")
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 22.963s
|
||||
// Result: FAIL
|
||||
9
tests/10_scrypt_hash/outputs/z-ai_glm-5.2.js
Normal file
9
tests/10_scrypt_hash/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const hashPassword = async (password, salt) => {
|
||||
const scrypt = (await import('https://esm.sh/scrypt-js')).default;
|
||||
const enc = new TextEncoder();
|
||||
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||
return [...hash].map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
};
|
||||
export default hashPassword;
|
||||
// Generation time: 21.621s
|
||||
// Result: FAIL
|
||||
12
tests/11_geospatial/outputs/anthropic_claude-fable-5.js
Normal file
12
tests/11_geospatial/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const analyzeGPS = async (readings, boundary) => {
|
||||
const turf = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
|
||||
const pts = readings
|
||||
.filter(r => turf.booleanPointInPolygon(turf.point(r.loc), boundary, {ignoreBoundary: true}))
|
||||
.sort((a, b) => a.ts - b.ts)
|
||||
.map(r => r.loc);
|
||||
if (pts.length < 2) return 0;
|
||||
return Math.round(turf.length(turf.lineString(pts), {units: 'kilometers'}) * 100) / 100;
|
||||
};
|
||||
export default analyzeGPS;
|
||||
// Generation time: 5.576s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,12 @@
|
||||
async function analyzeGPS(readings, boundary) {
|
||||
const turf = await import("https://cdn.skypack.dev/@turf/turf");
|
||||
const inside = readings
|
||||
.filter((r) => turf.booleanPointInPolygon(turf.point(r.loc), boundary))
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
if (inside.length < 2) return 0;
|
||||
const line = turf.lineString(inside.map((r) => r.loc));
|
||||
return Math.round(turf.length(line, { units: "kilometers" }) * 100) / 100;
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 2.996s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,17 @@
|
||||
async function analyzeGPS(readings, boundary) {
|
||||
const turf = await import('https://esm.sh/@turf/turf@6');
|
||||
|
||||
const valid = readings
|
||||
.filter(r => turf.booleanPointInPolygon(turf.point(r.loc), boundary))
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
|
||||
if (valid.length < 2) return 0;
|
||||
|
||||
const line = turf.lineString(valid.map(r => r.loc));
|
||||
const km = turf.length(line, { units: 'kilometers' });
|
||||
|
||||
return Math.round(km * 100) / 100;
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 4.282s
|
||||
// Result: PASS
|
||||
17
tests/11_geospatial/outputs/moonshotai_kimi-k2.7-code.js
Normal file
17
tests/11_geospatial/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const analyzeGPS = async (readings, boundary) => {
|
||||
const turf = await import('https://esm.sh/@turf/turf@7.2.0');
|
||||
|
||||
const valid = readings
|
||||
.filter(r => turf.booleanPointInPolygon(r.loc, boundary, { ignoreBoundary: true }))
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
|
||||
if (valid.length < 2) return 0;
|
||||
|
||||
const path = turf.lineString(valid.map(r => r.loc));
|
||||
const km = turf.length(path, { units: 'kilometers' });
|
||||
|
||||
return Math.round(km * 100) / 100;
|
||||
};
|
||||
export default analyzeGPS;
|
||||
// Generation time: 18.408s
|
||||
// Result: PASS
|
||||
13
tests/11_geospatial/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
13
tests/11_geospatial/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,13 @@
|
||||
async function analyzeGPS(readings, boundary) {
|
||||
if (!Array.isArray(readings) || readings.length < 2) return 0;
|
||||
const m = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
|
||||
const { booleanPointInPolygon: inside, lineString, length } = m.default ?? m;
|
||||
const coords = readings
|
||||
.filter(({ loc }) => loc && inside(loc, boundary, { ignoreBoundary: true }))
|
||||
.sort((a, b) => a.ts - b.ts)
|
||||
.map(({ loc }) => loc);
|
||||
return coords.length < 2 ? 0 : +length(lineString(coords), { units: 'kilometers' }).toFixed(2);
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 75.533s
|
||||
// Result: PASS
|
||||
27
tests/11_geospatial/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
27
tests/11_geospatial/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,27 @@
|
||||
let turfModule;
|
||||
|
||||
async function analyzeGPS(readings, boundary) {
|
||||
turfModule ||= import("https://cdn.jsdelivr.net/npm/@turf/turf@7.2.0/+esm");
|
||||
|
||||
const {
|
||||
point,
|
||||
lineString,
|
||||
length: pathLength,
|
||||
booleanPointInPolygon
|
||||
} = await turfModule;
|
||||
|
||||
const valid = readings
|
||||
.filter(({ loc }) =>
|
||||
booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true })
|
||||
)
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
|
||||
if (valid.length < 2) return 0;
|
||||
|
||||
const path = lineString(valid.map(({ loc }) => loc));
|
||||
|
||||
return Number(pathLength(path).toFixed(2));
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 12.391s
|
||||
// Result: PASS
|
||||
9
tests/11_geospatial/outputs/x-ai_grok-4.5.js
Normal file
9
tests/11_geospatial/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,9 @@
|
||||
async function analyzeGPS(readings,boundary){
|
||||
const{booleanPointInPolygon:i,lineString:l,length:e}=await import('https://esm.sh/@turf/turf@7.1.0');
|
||||
const v=readings.filter(r=>i(r.loc,boundary,{ignoreBoundary:true})).sort((a,b)=>a.ts-b.ts);
|
||||
if(v.length<2)return 0;
|
||||
return+e(l(v.map(r=>r.loc)),{units:'kilometers'}).toFixed(2)
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 14.349s
|
||||
// Result: PASS
|
||||
18
tests/11_geospatial/outputs/z-ai_glm-5.2.js
Normal file
18
tests/11_geospatial/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,18 @@
|
||||
async function analyzeGPS(readings, boundary) {
|
||||
const turf = await import('https://esm.sh/@turf/turf');
|
||||
const valid = readings
|
||||
.filter(r => turf.booleanPointInPolygon(turf.point(r.loc), boundary, { ignoreBoundary: true }))
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
|
||||
if (valid.length < 2) return 0;
|
||||
|
||||
const len = turf.length(
|
||||
turf.lineString(valid.map(r => r.loc)),
|
||||
{ units: 'kilometers' }
|
||||
);
|
||||
|
||||
return Math.round(len * 100) / 100;
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 28.608s
|
||||
// Result: PASS
|
||||
57
tests/12_mst_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
57
tests/12_mst_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,57 @@
|
||||
async function computeMST(tomlStr) {
|
||||
const [{ parse }, { default: Heap }, { default: table }] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/mnemonist/heap'),
|
||||
import('https://esm.sh/text-table'),
|
||||
]);
|
||||
|
||||
const { edges = [] } = parse(tomlStr);
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
const parent = new Map();
|
||||
const rank = new Map();
|
||||
|
||||
for (const e of edges) {
|
||||
heap.push(e);
|
||||
for (const n of [e.from, e.to]) {
|
||||
if (!parent.has(n)) {
|
||||
parent.set(n, n);
|
||||
rank.set(n, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const find = n => {
|
||||
while (parent.get(n) !== n) {
|
||||
parent.set(n, parent.get(parent.get(n)));
|
||||
n = parent.get(n);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
const union = (a, b) => {
|
||||
a = find(a);
|
||||
b = find(b);
|
||||
if (a === b) return false;
|
||||
if (rank.get(a) < rank.get(b)) [a, b] = [b, a];
|
||||
parent.set(b, a);
|
||||
if (rank.get(a) === rank.get(b)) rank.set(a, rank.get(a) + 1);
|
||||
return true;
|
||||
};
|
||||
|
||||
const rows = [['From', 'To', 'Weight']];
|
||||
const need = parent.size - 1;
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size && rows.length <= need) {
|
||||
const e = heap.pop();
|
||||
if (union(e.from, e.to)) {
|
||||
rows.push([e.from, e.to, String(e.weight)]);
|
||||
totalWeight += e.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return { table: table(rows), totalWeight };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 14.612s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,71 @@
|
||||
async function computeMST(toml) {
|
||||
const [{ parse }, mnemonist, textTableMod] = await Promise.all([
|
||||
import("https://esm.sh/smol-toml"),
|
||||
import("https://esm.sh/mnemonist"),
|
||||
import("https://esm.sh/text-table")
|
||||
]);
|
||||
|
||||
const Heap = mnemonist.Heap || mnemonist.default.Heap;
|
||||
const table = textTableMod.default || textTableMod;
|
||||
|
||||
const edges = parse(toml).edges || [];
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
const nodes = new Set();
|
||||
|
||||
for (const e of edges) {
|
||||
heap.push(e);
|
||||
nodes.add(e.from);
|
||||
nodes.add(e.to);
|
||||
}
|
||||
|
||||
const parent = new Map();
|
||||
const rank = new Map();
|
||||
for (const n of nodes) {
|
||||
parent.set(n, n);
|
||||
rank.set(n, 0);
|
||||
}
|
||||
|
||||
const find = x => {
|
||||
let r = x;
|
||||
while (parent.get(r) !== r) r = parent.get(r);
|
||||
while (parent.get(x) !== r) {
|
||||
const next = parent.get(x);
|
||||
parent.set(x, r);
|
||||
x = next;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
const union = (a, b) => {
|
||||
const ra = find(a), rb = find(b);
|
||||
if (ra === rb) return false;
|
||||
const da = rank.get(ra), db = rank.get(rb);
|
||||
if (da < db) parent.set(ra, rb);
|
||||
else if (da > db) parent.set(rb, ra);
|
||||
else {
|
||||
parent.set(rb, ra);
|
||||
rank.set(ra, da + 1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const rows = [];
|
||||
let totalWeight = 0;
|
||||
const need = Math.max(nodes.size - 1, 0);
|
||||
|
||||
while (heap.size && rows.length < need) {
|
||||
const e = heap.pop();
|
||||
if (union(e.from, e.to)) {
|
||||
rows.push([e.from, e.to, String(e.weight)]);
|
||||
totalWeight += e.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
table: table([["From", "To", "Weight"], ...rows]),
|
||||
totalWeight
|
||||
};
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 8.341s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,58 @@
|
||||
async function computeMST(tomlString) {
|
||||
const [{ parse }, { Heap }, { default: textTable }] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/mnemonist'),
|
||||
import('https://esm.sh/text-table'),
|
||||
]);
|
||||
|
||||
const { edges = [] } = parse(tomlString);
|
||||
if (!Array.isArray(edges) || edges.length === 0) {
|
||||
return { table: textTable([['From', 'To', 'Weight']]), totalWeight: 0 };
|
||||
}
|
||||
|
||||
class UnionFind {
|
||||
constructor(nodes) {
|
||||
this.parent = new Map(nodes.map(n => [n, n]));
|
||||
this.rank = new Map(nodes.map(n => [n, 0]));
|
||||
}
|
||||
find(x) {
|
||||
let p = this.parent.get(x);
|
||||
if (p !== x) { p = this.find(p); this.parent.set(x, p); }
|
||||
return p;
|
||||
}
|
||||
union(a, b) {
|
||||
let ra = this.find(a), rb = this.find(b);
|
||||
if (ra === rb) return false;
|
||||
const rkA = this.rank.get(ra), rkB = this.rank.get(rb);
|
||||
if (rkA < rkB) [ra, rb] = [rb, ra];
|
||||
this.parent.set(rb, ra);
|
||||
if (rkA === rkB) this.rank.set(ra, rkA + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
edges.forEach(e => heap.push(e));
|
||||
|
||||
const nodeSet = new Set();
|
||||
edges.forEach(({ from, to }) => { nodeSet.add(from); nodeSet.add(to); });
|
||||
|
||||
const uf = new UnionFind([...nodeSet]);
|
||||
const target = nodeSet.size - 1;
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size > 0 && mst.length < target) {
|
||||
const { from, to, weight } = heap.pop();
|
||||
if (uf.union(from, to)) {
|
||||
mst.push([from, to, String(weight)]);
|
||||
totalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
const rows = [['From', 'To', 'Weight'], ...mst];
|
||||
return { table: textTable(rows), totalWeight };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 24.146s
|
||||
// Result: PASS
|
||||
48
tests/12_mst_pipeline/outputs/moonshotai_kimi-k2.7-code.js
Normal file
48
tests/12_mst_pipeline/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const computeMST = async (toml) => {
|
||||
const [{ parse }, { Heap }, { default: table }] = await Promise.all([
|
||||
import("https://esm.sh/smol-toml"),
|
||||
import("https://esm.sh/mnemonist"),
|
||||
import("https://esm.sh/text-table")
|
||||
]);
|
||||
|
||||
const { edges = [] } = parse(toml);
|
||||
const nodes = [...new Set(edges.flatMap((e) => [e.from, e.to]))];
|
||||
|
||||
const parent = Object.fromEntries(nodes.map((n) => [n, n]));
|
||||
const rank = Object.fromEntries(nodes.map((n) => [n, 0]));
|
||||
|
||||
const find = (x) => (parent[x] === x ? x : (parent[x] = find(parent[x])));
|
||||
const union = (a, b) => {
|
||||
let ra = find(a);
|
||||
let rb = find(b);
|
||||
if (ra === rb) return false;
|
||||
if (rank[ra] < rank[rb]) [ra, rb] = [rb, ra];
|
||||
parent[rb] = ra;
|
||||
if (rank[ra] === rank[rb]) rank[ra]++;
|
||||
return true;
|
||||
};
|
||||
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
for (const e of edges) heap.push(e);
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size && mst.length < nodes.length - 1) {
|
||||
const e = heap.pop();
|
||||
if (union(e.from, e.to)) {
|
||||
mst.push([e.from, e.to, String(e.weight)]);
|
||||
totalWeight += e.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
table: table([["From", "To", "Weight"], ...mst]),
|
||||
totalWeight
|
||||
};
|
||||
};
|
||||
|
||||
self.computeMST = computeMST;
|
||||
export default computeMST;
|
||||
// Generation time: 37.889s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
const [{ parse }, m, { default: table }] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml@1'),
|
||||
import('https://esm.sh/mnemonist@0.39'),
|
||||
import('https://esm.sh/text-table@0.2')
|
||||
]);
|
||||
const { Heap } = m.default ?? m;
|
||||
|
||||
const { edges = [] } = parse(toml);
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
const parent = new Map(), rank = new Map();
|
||||
|
||||
const find = x => {
|
||||
const p = parent.get(x);
|
||||
return p === x ? x : (parent.set(x, find(p)), parent.get(x));
|
||||
};
|
||||
|
||||
for (const e of edges) {
|
||||
heap.push(e);
|
||||
for (const v of [e.from, e.to])
|
||||
if (!parent.has(v)) (parent.set(v, v), rank.set(v, 0));
|
||||
}
|
||||
|
||||
const rows = [['From', 'To', 'Weight']];
|
||||
let totalWeight = 0, need = parent.size - 1;
|
||||
|
||||
while (need-- > 0 && heap.size) {
|
||||
const { from, to, weight } = heap.pop();
|
||||
const a = find(from), b = find(to);
|
||||
if (a === b) continue;
|
||||
if (rank.get(a) < rank.get(b)) parent.set(a, b);
|
||||
else {
|
||||
parent.set(b, a);
|
||||
if (rank.get(a) === rank.get(b)) rank.set(a, rank.get(a) + 1);
|
||||
}
|
||||
rows.push([from, to, String(weight)]);
|
||||
totalWeight += weight;
|
||||
}
|
||||
|
||||
return { table: table(rows), totalWeight };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 107.250s
|
||||
// Result: FAIL
|
||||
105
tests/12_mst_pipeline/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
105
tests/12_mst_pipeline/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,105 @@
|
||||
async function computeMST(toml) {
|
||||
const [tomlModule, heapModule, tableModule] = await Promise.all([
|
||||
import("https://esm.sh/smol-toml@1.3.1"),
|
||||
import("https://esm.sh/mnemonist@0.40.3/heap"),
|
||||
import("https://esm.sh/text-table@0.2.0")
|
||||
]);
|
||||
|
||||
const parse = tomlModule.parse ?? tomlModule.default?.parse;
|
||||
const Heap = heapModule.default ?? heapModule.Heap;
|
||||
const textTable = tableModule.default ?? tableModule;
|
||||
|
||||
if (typeof parse !== "function" || typeof Heap !== "function" ||
|
||||
typeof textTable !== "function") {
|
||||
throw new Error("Failed to load required libraries");
|
||||
}
|
||||
|
||||
const config = parse(toml);
|
||||
const edges = config?.edges;
|
||||
|
||||
if (!Array.isArray(edges)) {
|
||||
throw new TypeError("TOML must contain an edges array");
|
||||
}
|
||||
|
||||
const nodes = new Set();
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
|
||||
for (const edge of edges) {
|
||||
const { from, to, weight } = edge ?? {};
|
||||
|
||||
if (typeof from !== "string" || typeof to !== "string" ||
|
||||
!from || !to || typeof weight !== "number" ||
|
||||
!Number.isFinite(weight)) {
|
||||
throw new TypeError("Each edge must have valid from, to, and weight fields");
|
||||
}
|
||||
|
||||
nodes.add(from);
|
||||
nodes.add(to);
|
||||
heap.push({ from, to, weight });
|
||||
}
|
||||
|
||||
const parent = new Map();
|
||||
const rank = new Map();
|
||||
|
||||
for (const node of nodes) {
|
||||
parent.set(node, node);
|
||||
rank.set(node, 0);
|
||||
}
|
||||
|
||||
const find = node => {
|
||||
let root = node;
|
||||
|
||||
while (parent.get(root) !== root) {
|
||||
root = parent.get(root);
|
||||
}
|
||||
|
||||
while (parent.get(node) !== node) {
|
||||
const next = parent.get(node);
|
||||
parent.set(node, root);
|
||||
node = next;
|
||||
}
|
||||
|
||||
return root;
|
||||
};
|
||||
|
||||
const union = (left, right) => {
|
||||
let leftRoot = find(left);
|
||||
let rightRoot = find(right);
|
||||
|
||||
if (leftRoot === rightRoot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rank.get(leftRoot) < rank.get(rightRoot)) {
|
||||
[leftRoot, rightRoot] = [rightRoot, leftRoot];
|
||||
}
|
||||
|
||||
parent.set(rightRoot, leftRoot);
|
||||
|
||||
if (rank.get(leftRoot) === rank.get(rightRoot)) {
|
||||
rank.set(leftRoot, rank.get(leftRoot) + 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size && mst.length < nodes.size - 1) {
|
||||
const edge = heap.pop();
|
||||
|
||||
if (union(edge.from, edge.to)) {
|
||||
mst.push([edge.from, edge.to, String(edge.weight)]);
|
||||
totalWeight += edge.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
table: textTable([["From", "To", "Weight"], ...mst]),
|
||||
totalWeight
|
||||
};
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 11.402s
|
||||
// Result: PASS
|
||||
36
tests/12_mst_pipeline/outputs/x-ai_grok-4.5.js
Normal file
36
tests/12_mst_pipeline/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,36 @@
|
||||
async function computeMST(t){
|
||||
const[{parse},H,{default:tt}]=await Promise.all([
|
||||
import('https://esm.sh/smol-toml@1.3.1'),
|
||||
import('https://esm.sh/mnemonist@0.39.8/heap'),
|
||||
import('https://esm.sh/text-table@0.2.0')
|
||||
]);
|
||||
const Heap=H.default;
|
||||
const d=parse(t);
|
||||
const es=d.edges||[];
|
||||
const ns=new Set;
|
||||
for(const e of es){ns.add(e.from);ns.add(e.to)}
|
||||
const n=ns.size;
|
||||
const h=new Heap((a,b)=>a.weight-b.weight);
|
||||
for(const e of es)h.push(e);
|
||||
const p={},r={};
|
||||
for(const x of ns){p[x]=x;r[x]=0}
|
||||
const f=x=>{if(p[x]!==x)p[x]=f(p[x]);return p[x]};
|
||||
const u=(x,y)=>{
|
||||
const px=f(x),py=f(y);
|
||||
if(px===py)return!1;
|
||||
if(r[px]<r[py])p[px]=py;
|
||||
else if(r[px]>r[py])p[py]=px;
|
||||
else{p[py]=px;r[px]++}
|
||||
return!0
|
||||
};
|
||||
const m=[];
|
||||
let w=0;
|
||||
while(m.length<n-1&&h.size){
|
||||
const e=h.pop();
|
||||
if(u(e.from,e.to)){m.push([e.from,e.to,String(e.weight)]);w+=e.weight}
|
||||
}
|
||||
return{table:tt([['From','To','Weight'],...m]),totalWeight:w}
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 15.793s
|
||||
// Result: PASS
|
||||
53
tests/12_mst_pipeline/outputs/z-ai_glm-5.2.js
Normal file
53
tests/12_mst_pipeline/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const computeMST = async (tomlStr) => {
|
||||
const { parse } = await import('https://esm.sh/smol-toml');
|
||||
const { Heap } = await import('https://esm.sh/mnemonist');
|
||||
const textTable = (await import('https://esm.sh/text-table')).default;
|
||||
|
||||
const config = parse(tomlStr);
|
||||
const edges = config.edges || [];
|
||||
|
||||
class UnionFind {
|
||||
constructor() { this.p = {}; this.r = {}; }
|
||||
add(n) { if (!(n in this.p)) { this.p[n] = n; this.r[n] = 0; } }
|
||||
find(n) { return this.p[n] === n ? n : (this.p[n] = this.find(this.p[n])); }
|
||||
union(a, b) {
|
||||
const ra = this.find(a), rb = this.find(b);
|
||||
if (ra === rb) return false;
|
||||
if (this.r[ra] < this.r[rb]) this.p[ra] = rb;
|
||||
else if (this.r[ra] > this.r[rb]) this.p[rb] = ra;
|
||||
else { this.p[rb] = ra; this.r[ra]++; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const uf = new UnionFind();
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
const nodes = new Set();
|
||||
|
||||
for (const e of edges) {
|
||||
nodes.add(e.from);
|
||||
nodes.add(e.to);
|
||||
uf.add(e.from);
|
||||
uf.add(e.to);
|
||||
heap.push(e);
|
||||
}
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
|
||||
while (heap.size && mst.length < nodes.size - 1) {
|
||||
const e = heap.pop();
|
||||
if (uf.union(e.from, e.to)) {
|
||||
mst.push([e.from, e.to, String(e.weight)]);
|
||||
totalWeight += e.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
table: textTable([['From', 'To', 'Weight'], ...mst]),
|
||||
totalWeight
|
||||
};
|
||||
};
|
||||
export default computeMST;
|
||||
// Generation time: 22.055s
|
||||
// Result: PASS
|
||||
24
tests/1_dijkstra/outputs/anthropic_claude-fable-5.js
Normal file
24
tests/1_dijkstra/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const findShortestPath = async (graph, start, end) => {
|
||||
const { default: PriorityQueue } = await import(
|
||||
'https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm'
|
||||
);
|
||||
const dist = { [start]: 0 };
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
|
||||
pq.queue([0, start]);
|
||||
while (pq.length) {
|
||||
const [d, node] = pq.dequeue();
|
||||
if (node === end) return d;
|
||||
if (d > (dist[node] ?? Infinity)) continue;
|
||||
for (const [next, w] of Object.entries(graph[node] ?? {})) {
|
||||
const nd = d + w;
|
||||
if (nd < (dist[next] ?? Infinity)) {
|
||||
dist[next] = nd;
|
||||
pq.queue([nd, next]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
};
|
||||
export default findShortestPath;
|
||||
// Generation time: 12.985s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,24 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import("https://esm.sh/js-priority-queue");
|
||||
const dist = {};
|
||||
for (const node in graph) dist[node] = Infinity;
|
||||
dist[start] = 0;
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.cost - b.cost });
|
||||
pq.queue({ node: start, cost: 0 });
|
||||
while (pq.length) {
|
||||
const { node, cost } = pq.dequeue();
|
||||
if (node === end) return cost;
|
||||
if (cost > dist[node]) continue;
|
||||
for (const next in graph[node]) {
|
||||
const nc = cost + graph[node][next];
|
||||
if (nc < dist[next]) {
|
||||
dist[next] = nc;
|
||||
pq.queue({ node: next, cost: nc });
|
||||
}
|
||||
}
|
||||
}
|
||||
return dist[end] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 5.506s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,34 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue@0.1.5');
|
||||
|
||||
if (!(start in graph) || !(end in graph)) return Infinity;
|
||||
|
||||
const dist = Object.fromEntries(Object.keys(graph).map(n => [n, Infinity]));
|
||||
dist[start] = 0;
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
|
||||
pq.queue({ node: start, dist: 0 });
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length > 0) {
|
||||
const { node, dist: d } = pq.dequeue();
|
||||
if (visited.has(node)) continue;
|
||||
visited.add(node);
|
||||
|
||||
if (node === end) return d;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) {
|
||||
const newDist = d + weight;
|
||||
if (newDist < dist[neighbor]) {
|
||||
dist[neighbor] = newDist;
|
||||
pq.queue({ node: neighbor, dist: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dist[end];
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 10.596s
|
||||
// Result: PASS
|
||||
22
tests/1_dijkstra/outputs/moonshotai_kimi-k2.7-code.js
Normal file
22
tests/1_dijkstra/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const findShortestPath = async (graph, start, end) => {
|
||||
const {default: PQ} = await import('https://esm.sh/js-priority-queue');
|
||||
const dist = new Map([[start, 0]]);
|
||||
const pq = new PQ({comparator: (a, b) => a[1] - b[1]});
|
||||
pq.queue([start, 0]);
|
||||
while (pq.length) {
|
||||
const [u, d] = pq.dequeue();
|
||||
if (u === end) return d;
|
||||
if (d > (dist.get(u) ?? Infinity)) continue;
|
||||
for (const [v, w] of Object.entries(graph[u] || {})) {
|
||||
const nd = d + w;
|
||||
if (nd < (dist.get(v) ?? Infinity)) {
|
||||
dist.set(v, nd);
|
||||
pq.queue([v, nd]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
};
|
||||
export default findShortestPath;
|
||||
// Generation time: 42.886s
|
||||
// Result: PASS
|
||||
29
tests/1_dijkstra/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
29
tests/1_dijkstra/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,29 @@
|
||||
let pqLib;
|
||||
|
||||
const loadPriorityQueue = () =>
|
||||
pqLib ??= import('https://esm.sh/js-priority-queue@0.1.5')
|
||||
.catch(() => import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm'));
|
||||
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await loadPriorityQueue();
|
||||
const dist = new Map([[start, 0]]);
|
||||
const heap = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
heap.queue([start, 0]);
|
||||
|
||||
while (heap.length) {
|
||||
const [node, d] = heap.dequeue();
|
||||
if (node === end) return d;
|
||||
if (d > (dist.get(node) ?? Infinity)) continue;
|
||||
for (const [next, w] of Object.entries(graph[node] ?? {})) {
|
||||
const nd = d + w;
|
||||
if (nd < (dist.get(next) ?? Infinity)) {
|
||||
dist.set(next, nd);
|
||||
heap.queue([next, nd]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 122.554s
|
||||
// Result: PASS
|
||||
57
tests/1_dijkstra/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
57
tests/1_dijkstra/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,57 @@
|
||||
let priorityQueueModule;
|
||||
|
||||
async function findShortestPath(graph, start, end) {
|
||||
if (!graph || typeof graph !== "object" || Array.isArray(graph)) {
|
||||
throw new TypeError("graph must be an object");
|
||||
}
|
||||
|
||||
priorityQueueModule ??= import(
|
||||
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm"
|
||||
);
|
||||
|
||||
const module = await priorityQueueModule;
|
||||
const PriorityQueue = module.default ?? module.PriorityQueue;
|
||||
|
||||
if (typeof PriorityQueue !== "function") {
|
||||
throw new TypeError("PriorityQueue could not be loaded");
|
||||
}
|
||||
|
||||
const queue = new PriorityQueue({
|
||||
comparator: (a, b) => a.distance - b.distance
|
||||
});
|
||||
const distances = new Map([[start, 0]]);
|
||||
|
||||
queue.queue({ node: start, distance: 0 });
|
||||
|
||||
while (queue.length) {
|
||||
const { node, distance } = queue.dequeue();
|
||||
|
||||
if (distance !== distances.get(node)) continue;
|
||||
if (node === end) return distance;
|
||||
|
||||
const edges = Object.hasOwn(graph, node) ? graph[node] : undefined;
|
||||
if (edges === undefined) continue;
|
||||
|
||||
if (!edges || typeof edges !== "object" || Array.isArray(edges)) {
|
||||
throw new TypeError(`Invalid edges for node: ${node}`);
|
||||
}
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(edges)) {
|
||||
if (!Number.isFinite(weight) || weight < 0) {
|
||||
throw new RangeError("Edge weights must be finite and non-negative");
|
||||
}
|
||||
|
||||
const nextDistance = distance + weight;
|
||||
|
||||
if (nextDistance < (distances.get(neighbor) ?? Infinity)) {
|
||||
distances.set(neighbor, nextDistance);
|
||||
queue.queue({ node: neighbor, distance: nextDistance });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 30.835s
|
||||
// Result: PASS
|
||||
26
tests/1_dijkstra/outputs/x-ai_grok-4.5.js
Normal file
26
tests/1_dijkstra/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
|
||||
const dist = {};
|
||||
for (const node of Object.keys(graph)) dist[node] = Infinity;
|
||||
dist[start] = 0;
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
pq.queue([start, 0]);
|
||||
const visited = new Set();
|
||||
while (pq.length) {
|
||||
const [u, cost] = pq.dequeue();
|
||||
if (visited.has(u)) continue;
|
||||
visited.add(u);
|
||||
if (u === end) return cost;
|
||||
for (const [v, weight] of Object.entries(graph[u] || {})) {
|
||||
const alt = cost + weight;
|
||||
if (alt < (dist[v] ?? Infinity)) {
|
||||
dist[v] = alt;
|
||||
pq.queue([v, alt]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 22.841s
|
||||
// Result: PASS
|
||||
24
tests/1_dijkstra/outputs/z-ai_glm-5.2.js
Normal file
24
tests/1_dijkstra/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,24 @@
|
||||
async function findShortestPath(g, s, e) {
|
||||
const { default: PQ } = await import('https://esm.sh/js-priority-queue');
|
||||
const d = { [s]: 0 };
|
||||
const q = new PQ({ comparator: (a, b) => a.p - b.p });
|
||||
q.queue({ n: s, p: 0 });
|
||||
|
||||
while (q.length) {
|
||||
const { n, p } = q.dequeue();
|
||||
if (n === e) return p;
|
||||
if (p > (d[n] ?? Infinity)) continue;
|
||||
|
||||
for (const m in g[n]) {
|
||||
const w = p + g[n][m];
|
||||
if (w < (d[m] ?? Infinity)) {
|
||||
d[m] = w;
|
||||
q.queue({ n: m, p: w });
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 45.601s
|
||||
// Result: PASS
|
||||
18
tests/2_convex_hull/outputs/anthropic_claude-fable-5.js
Normal file
18
tests/2_convex_hull/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const findConvexHull = async points => {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
const pts = uniqWith(sortBy(points, ['x', 'y']), isEqual);
|
||||
if (pts.length < 3) return pts;
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const build = list => {
|
||||
const hull = [];
|
||||
for (const p of list) {
|
||||
while (hull.length > 1 && cross(hull.at(-2), hull.at(-1), p) <= 0) hull.pop();
|
||||
hull.push(p);
|
||||
}
|
||||
return hull.slice(0, -1);
|
||||
};
|
||||
return [...build(pts), ...build([...pts].reverse())];
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 14.047s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,29 @@
|
||||
const findConvexHull = async (points) => {
|
||||
const { default: _ } = await import("https://cdn.skypack.dev/lodash");
|
||||
|
||||
const pts = _.sortBy(
|
||||
_.uniqBy(points, (p) => `${p.x},${p.y}`),
|
||||
["x", "y"]
|
||||
);
|
||||
|
||||
if (pts.length < 3) return pts;
|
||||
|
||||
const cross = (o, a, b) =>
|
||||
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const build = (arr) => {
|
||||
const h = [];
|
||||
for (const p of arr) {
|
||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0)
|
||||
h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
h.pop();
|
||||
return h;
|
||||
};
|
||||
|
||||
return [...build(pts), ...build([...pts].reverse())];
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 4.735s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,25 @@
|
||||
async function findConvexHull(points) {
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash-es/lodash.js');
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const pts = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
||||
if (pts.length < 3) return pts;
|
||||
|
||||
const build = (arr) => {
|
||||
const hull = [];
|
||||
for (const p of arr) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) hull.pop();
|
||||
hull.push(p);
|
||||
}
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = build(pts);
|
||||
const upper = build([...pts].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 9.472s
|
||||
// Result: PASS
|
||||
29
tests/2_convex_hull/outputs/moonshotai_kimi-k2.7-code.js
Normal file
29
tests/2_convex_hull/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,29 @@
|
||||
let l;
|
||||
|
||||
export const findConvexHull = async p => {
|
||||
if (!Array.isArray(p)) throw new TypeError("points must be an array");
|
||||
if (p.length < 2) return [...p];
|
||||
|
||||
l = l || import("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm");
|
||||
const { sortBy: m, uniqWith: u } = await l;
|
||||
|
||||
const q = u(m(p, [o => o.x, o => o.y]), (a, b) => a.x === b.x && a.y === b.y);
|
||||
const n = q.length;
|
||||
if (n < 4) return q;
|
||||
|
||||
const c = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const h = [];
|
||||
|
||||
for (let i = 0; i < n; h.push(q[i++]))
|
||||
while (h.length > 1 && c(h[h.length - 2], h[h.length - 1], q[i]) <= 0) h.pop();
|
||||
|
||||
const t = h.length + 1;
|
||||
for (let i = n - 1; i >= 0; h.push(q[i--]))
|
||||
while (h.length > t && c(h[h.length - 2], h[h.length - 1], q[i]) <= 0) h.pop();
|
||||
|
||||
h.pop();
|
||||
return h;
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 26.432s
|
||||
// Result: FAIL
|
||||
31
tests/2_convex_hull/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
31
tests/2_convex_hull/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,31 @@
|
||||
async function findConvexHull(points) {
|
||||
if (!Array.isArray(points) || points.some(p => !p || !Number.isFinite(p.x) || !Number.isFinite(p.y))) {
|
||||
throw new TypeError('findConvexHull expects an array of finite {x, y} points');
|
||||
}
|
||||
|
||||
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
|
||||
const ps = uniqWith(
|
||||
sortBy(points.map(({ x, y }) => ({ x, y })), ['x', 'y']),
|
||||
(a, b) => a.x === b.x && a.y === b.y
|
||||
);
|
||||
|
||||
if (ps.length < 3) return ps;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const half = q => {
|
||||
const h = [];
|
||||
for (const p of q) {
|
||||
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const lo = half(ps);
|
||||
const hi = half([...ps].reverse());
|
||||
|
||||
return [...lo.slice(0, -1), ...hi.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 96.201s
|
||||
// Result: PASS
|
||||
56
tests/2_convex_hull/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
56
tests/2_convex_hull/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,56 @@
|
||||
async function findConvexHull(points) {
|
||||
if (!Array.isArray(points)) {
|
||||
throw new TypeError("Points must be an array");
|
||||
}
|
||||
|
||||
if (points.some(point =>
|
||||
!point ||
|
||||
typeof point !== "object" ||
|
||||
!Number.isFinite(point.x) ||
|
||||
!Number.isFinite(point.y)
|
||||
)) {
|
||||
throw new TypeError("Each point must contain finite numeric x and y values");
|
||||
}
|
||||
|
||||
const { sortBy, uniqBy } = await import(
|
||||
"https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js"
|
||||
);
|
||||
|
||||
const sorted = sortBy(
|
||||
uniqBy(points, ({ x, y }) => `${x}\0${y}`),
|
||||
["x", "y"]
|
||||
);
|
||||
|
||||
if (sorted.length < 3) {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
const cross = (a, b, c) =>
|
||||
(b.x - a.x) * (c.y - a.y) -
|
||||
(b.y - a.y) * (c.x - a.x);
|
||||
|
||||
const buildHalf = sequence => {
|
||||
const half = [];
|
||||
|
||||
for (const point of sequence) {
|
||||
while (
|
||||
half.length > 1 &&
|
||||
cross(half[half.length - 2], half[half.length - 1], point) <= 0
|
||||
) {
|
||||
half.pop();
|
||||
}
|
||||
|
||||
half.push(point);
|
||||
}
|
||||
|
||||
return half;
|
||||
};
|
||||
|
||||
const lower = buildHalf(sorted);
|
||||
const upper = buildHalf(sorted.slice().reverse());
|
||||
|
||||
return lower.slice(0, -1).concat(upper.slice(0, -1));
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 21.094s
|
||||
// Result: PASS
|
||||
22
tests/2_convex_hull/outputs/x-ai_grok-4.5.js
Normal file
22
tests/2_convex_hull/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,22 @@
|
||||
async function findConvexHull(points){
|
||||
const{sortBy,uniqWith}=await import("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm");
|
||||
points=uniqWith(points,(a,b)=>a.x===b.x&&a.y===b.y);
|
||||
points=sortBy(points,["x","y"]);
|
||||
if(points.length<=2)return points;
|
||||
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
let lower=[];
|
||||
for(const p of points){
|
||||
while(lower.length>=2&&cross(lower.at(-2),lower.at(-1),p)<=0)lower.pop();
|
||||
lower.push(p);
|
||||
}
|
||||
let upper=[];
|
||||
for(let i=points.length-1;i>=0;i--){
|
||||
const p=points[i];
|
||||
while(upper.length>=2&&cross(upper.at(-2),upper.at(-1),p)<=0)upper.pop();
|
||||
upper.push(p);
|
||||
}
|
||||
return lower.slice(0,-1).concat(upper.slice(0,-1));
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 37.988s
|
||||
// Result: PASS
|
||||
24
tests/2_convex_hull/outputs/z-ai_glm-5.2.js
Normal file
24
tests/2_convex_hull/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,24 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import('https://esm.sh/lodash');
|
||||
if (points.length < 3) return _.uniqWith(points, _.isEqual);
|
||||
|
||||
const pts = _.sortBy(points, ['x', 'y']);
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const build = (arr) => {
|
||||
const h = [];
|
||||
for (const p of arr) {
|
||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const lower = build(pts);
|
||||
const upper = build([...pts].reverse());
|
||||
|
||||
return _.uniqWith([...lower, ...upper], _.isEqual);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 54.184s
|
||||
// Result: PASS
|
||||
46
tests/3_signal_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
46
tests/3_signal_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const analyzeSignal = async yamlStr => {
|
||||
const [yaml, math, ndarray, fft, DOMPurify] = (await Promise.all(
|
||||
['js-yaml', 'mathjs', 'ndarray', 'ndarray-fft', 'dompurify']
|
||||
.map(pkg => import(`https://esm.sh/${pkg}`))
|
||||
)).map(m => m.default ?? m);
|
||||
|
||||
const { sampleRate, duration, components } = yaml.load(yamlStr);
|
||||
const N = sampleRate * duration;
|
||||
|
||||
const signal = Array.from({ length: N }, (_, i) => {
|
||||
const t = i / sampleRate;
|
||||
return components.reduce(
|
||||
(sum, { frequency, amplitude }) =>
|
||||
sum + amplitude * math.sin(2 * math.pi * frequency * t),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
||||
const real = ndarray(new Float64Array(signal));
|
||||
const imag = ndarray(new Float64Array(N));
|
||||
fft(1, real, imag);
|
||||
|
||||
const peaks = [];
|
||||
for (let k = 0; k <= N / 2; k++) {
|
||||
const magnitude = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
|
||||
if (magnitude > 0.1) {
|
||||
peaks.push({
|
||||
frequencyHz: Math.round(k * sampleRate / N),
|
||||
magnitude: Math.round(magnitude * 100) / 100
|
||||
});
|
||||
}
|
||||
}
|
||||
peaks.sort((a, b) => b.magnitude - a.magnitude);
|
||||
|
||||
const rows = peaks
|
||||
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`)
|
||||
.join('');
|
||||
const html = DOMPurify.sanitize(
|
||||
`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`
|
||||
);
|
||||
|
||||
return { peaks, html, signalLength: N };
|
||||
};
|
||||
export default analyzeSignal;
|
||||
// Generation time: 16.968s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,65 @@
|
||||
const CDN = {
|
||||
yaml: "https://cdn.jsdelivr.net/npm/js-yaml/+esm",
|
||||
math: "https://cdn.jsdelivr.net/npm/mathjs/+esm",
|
||||
ndarray: "https://cdn.jsdelivr.net/npm/ndarray/+esm",
|
||||
fft: "https://cdn.jsdelivr.net/npm/ndarray-fft/+esm",
|
||||
purify: "https://cdn.jsdelivr.net/npm/dompurify/+esm"
|
||||
};
|
||||
|
||||
const def = m => m.default ?? m;
|
||||
|
||||
export async function analyzeSignal(yamlStr) {
|
||||
const [yamlMod, math, ndMod, fftMod, purifyMod] = await Promise.all([
|
||||
import(CDN.yaml),
|
||||
import(CDN.math),
|
||||
import(CDN.ndarray),
|
||||
import(CDN.fft),
|
||||
import(CDN.purify)
|
||||
]);
|
||||
|
||||
const yaml = def(yamlMod);
|
||||
const ndarray = def(ndMod);
|
||||
const fft = def(fftMod);
|
||||
const DOMPurify = def(purifyMod);
|
||||
|
||||
const cfg = yaml.load(yamlStr);
|
||||
const { sampleRate, duration, components = [] } = cfg;
|
||||
const N = sampleRate * duration;
|
||||
|
||||
const signal = Array.from({ length: N }, (_, i) => {
|
||||
const t = i / sampleRate;
|
||||
return components.reduce(
|
||||
(s, { amplitude, frequency }) =>
|
||||
s + amplitude * math.sin(2 * math.pi * frequency * t),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
||||
const real = ndarray(new Float64Array(signal), [N]);
|
||||
const imag = ndarray(new Float64Array(N), [N]);
|
||||
fft(1, real, imag);
|
||||
|
||||
const half = N / 2;
|
||||
const peaks = [];
|
||||
for (let k = 0; k <= half; k++) {
|
||||
const mag = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half;
|
||||
if (mag > 0.1)
|
||||
peaks.push({
|
||||
frequencyHz: Math.round((k * sampleRate) / N),
|
||||
magnitude: Math.round(mag * 100) / 100
|
||||
});
|
||||
}
|
||||
peaks.sort((a, b) => b.magnitude - a.magnitude);
|
||||
|
||||
const rows = peaks
|
||||
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`)
|
||||
.join("");
|
||||
const html = DOMPurify.sanitize(
|
||||
`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`
|
||||
);
|
||||
|
||||
return { peaks, html, signalLength: N };
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 11.820s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,60 @@
|
||||
async function analyzeSignal(yamlString) {
|
||||
const [
|
||||
{ default: yaml },
|
||||
{ default: math },
|
||||
{ default: ndarray },
|
||||
{ default: fft },
|
||||
{ default: DOMPurify },
|
||||
] = await Promise.all([
|
||||
import('https://esm.sh/js-yaml@4'),
|
||||
import('https://esm.sh/mathjs@12'),
|
||||
import('https://esm.sh/ndarray@1'),
|
||||
import('https://esm.sh/ndarray-fft@1'),
|
||||
import('https://esm.sh/dompurify@3'),
|
||||
]);
|
||||
|
||||
const config = yaml.load(yamlString);
|
||||
const { sampleRate, duration, components } = config;
|
||||
const N = sampleRate * duration;
|
||||
|
||||
const signal = Array.from({ length: N }, (_, i) => {
|
||||
const t = i / sampleRate;
|
||||
return components.reduce(
|
||||
(sum, { frequency, amplitude }) =>
|
||||
sum + amplitude * math.sin(2 * math.pi * frequency * t),
|
||||
0
|
||||
);
|
||||
});
|
||||
|
||||
const real = ndarray(new Float64Array(signal));
|
||||
const imag = ndarray(new Float64Array(N));
|
||||
fft(1, real, imag);
|
||||
|
||||
const half = N / 2;
|
||||
const magnitude = Array.from({ length: half + 1 }, (_, k) => {
|
||||
const re = real.get(k);
|
||||
const im = imag.get(k);
|
||||
return math.sqrt(re * re + im * im) / half;
|
||||
});
|
||||
|
||||
const peaks = magnitude
|
||||
.map((mag, k) => ({ frequencyHz: (k * sampleRate) / N, magnitude: mag }))
|
||||
.filter(({ magnitude }) => magnitude > 0.1)
|
||||
.sort((a, b) => b.magnitude - a.magnitude)
|
||||
.map(({ frequencyHz, magnitude }) => ({
|
||||
frequencyHz: Math.round(frequencyHz),
|
||||
magnitude: Math.round(magnitude * 100) / 100,
|
||||
}));
|
||||
|
||||
const rows = peaks
|
||||
.map(({ frequencyHz, magnitude }) => `<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`)
|
||||
.join('');
|
||||
|
||||
const rawHtml = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`;
|
||||
const html = DOMPurify.sanitize(rawHtml);
|
||||
|
||||
return { peaks, html, signalLength: N };
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 8.829s
|
||||
// Result: FAIL
|
||||
46
tests/3_signal_pipeline/outputs/moonshotai_kimi-k2.7-code.js
Normal file
46
tests/3_signal_pipeline/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const analyzeSignal = async (yamlString) => {
|
||||
const [yaml, mathMod, ndarrayMod, fftMod, domMod] = await Promise.all([
|
||||
import('https://esm.sh/js-yaml@4.1.0'),
|
||||
import('https://esm.sh/mathjs@11.11.0'),
|
||||
import('https://esm.sh/ndarray'),
|
||||
import('https://esm.sh/ndarray-fft'),
|
||||
import('https://esm.sh/dompurify@3.0.3')
|
||||
]);
|
||||
const math = mathMod.default;
|
||||
const ndarray = ndarrayMod.default;
|
||||
const fft = fftMod.default;
|
||||
const DOMPurify = domMod.default(window);
|
||||
const { sampleRate, duration, components } = yaml.load(yamlString);
|
||||
const N = sampleRate * duration;
|
||||
const half = N / 2;
|
||||
const signal = new Array(N);
|
||||
for (let i = 0; i < N; i++) {
|
||||
const t = i / sampleRate;
|
||||
let s = 0;
|
||||
for (const { frequency, amplitude } of components) {
|
||||
s += amplitude * math.sin(2 * math.pi * frequency * t);
|
||||
}
|
||||
signal[i] = s;
|
||||
}
|
||||
const real = ndarray(new Float64Array(signal));
|
||||
const imag = ndarray(new Float64Array(N));
|
||||
fft(1, real, imag);
|
||||
const magnitude = [];
|
||||
for (let k = 0; k <= half; k++) {
|
||||
magnitude[k] = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half;
|
||||
}
|
||||
const peaks = magnitude
|
||||
.map((m, k) => ({
|
||||
frequencyHz: Math.round(k * sampleRate / N),
|
||||
magnitude: Math.round(m * 100) / 100
|
||||
}))
|
||||
.filter(p => p.magnitude > 0.1)
|
||||
.sort((a, b) => b.magnitude - a.magnitude);
|
||||
const html = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${peaks
|
||||
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`)
|
||||
.join('')}</table>`;
|
||||
return { peaks, html: DOMPurify.sanitize(html), signalLength: N };
|
||||
};
|
||||
export default analyzeSignal;
|
||||
// Generation time: 83.104s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,57 @@
|
||||
const CDN = [
|
||||
'https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm',
|
||||
'https://cdn.jsdelivr.net/npm/mathjs@13/+esm',
|
||||
'https://cdn.jsdelivr.net/npm/ndarray@1.0.19/+esm',
|
||||
'https://cdn.jsdelivr.net/npm/ndarray-fft@1.0.3/+esm',
|
||||
'https://cdn.jsdelivr.net/npm/dompurify@3.1.6/+esm'
|
||||
];
|
||||
|
||||
let libs;
|
||||
const loadLibs = () => (libs ??= Promise.all(CDN.map((u) => import(u))));
|
||||
const pick = (m, k) => (m?.[k] !== undefined ? m : m?.default ?? m);
|
||||
|
||||
async function analyzeSignal(yamlString) {
|
||||
if (typeof yamlString !== 'string') throw new TypeError('analyzeSignal expects a YAML string');
|
||||
|
||||
const [yamlM, mathM, ndM, fftM, dpM] = await loadLibs();
|
||||
const { load } = pick(yamlM, 'load');
|
||||
const math = pick(mathM, 'sin');
|
||||
const ndarray = ndM?.default ?? ndM;
|
||||
const fft = fftM?.default ?? fftM;
|
||||
const DOMPurify = dpM?.default ?? dpM;
|
||||
|
||||
const { sampleRate, duration, components = [] } = load(yamlString);
|
||||
const N = sampleRate * duration;
|
||||
if (!Number.isInteger(N) || N < 2 || (N & (N - 1))) {
|
||||
throw new RangeError(`sampleRate * duration must be a power of two >= 2 (got ${N})`);
|
||||
}
|
||||
|
||||
const data = new Float64Array(N);
|
||||
for (let i = 0; i < N; i++) {
|
||||
const t = i / sampleRate;
|
||||
data[i] = components.reduce((s, { frequency: f, amplitude: a }) => s + a * math.sin(2 * math.pi * f * t), 0);
|
||||
}
|
||||
|
||||
const real = ndarray(data, [N]);
|
||||
const imag = ndarray(new Float64Array(N), [N]);
|
||||
fft(1, real, imag);
|
||||
|
||||
const half = N >> 1;
|
||||
const peaks = Array.from({ length: half + 1 }, (_, k) => ({
|
||||
k,
|
||||
m: math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half
|
||||
}))
|
||||
.filter(({ m }) => m > 0.1)
|
||||
.sort((a, b) => b.m - a.m)
|
||||
.map(({ k, m }) => ({ frequencyHz: Math.round(k * sampleRate / N), magnitude: +m.toFixed(2) }));
|
||||
|
||||
const rows = peaks.map(({ frequencyHz, magnitude }) => `<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`).join('');
|
||||
const html = DOMPurify.sanitize(`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`);
|
||||
|
||||
return { peaks, html, signalLength: N };
|
||||
}
|
||||
|
||||
globalThis.analyzeSignal = analyzeSignal;
|
||||
export default analyzeSignal;
|
||||
// Generation time: 203.454s
|
||||
// Result: PASS
|
||||
132
tests/3_signal_pipeline/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
132
tests/3_signal_pipeline/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,132 @@
|
||||
async function analyzeSignal(yamlString) {
|
||||
const [
|
||||
yamlModule,
|
||||
mathModule,
|
||||
ndarrayModule,
|
||||
fftModule,
|
||||
purifierModule
|
||||
] = await Promise.all([
|
||||
import('https://esm.sh/js-yaml@4.1.0'),
|
||||
import('https://esm.sh/mathjs@13.2.0'),
|
||||
import('https://esm.sh/ndarray@1.0.19'),
|
||||
import('https://esm.sh/ndarray-fft@1.0.0'),
|
||||
import('https://esm.sh/dompurify@3.2.4')
|
||||
]);
|
||||
|
||||
if (typeof yamlString !== 'string') {
|
||||
throw new TypeError('yamlString must be a string');
|
||||
}
|
||||
|
||||
const yaml = yamlModule.default ?? yamlModule;
|
||||
const ndarray = ndarrayModule.default ?? ndarrayModule.ndarray ?? ndarrayModule;
|
||||
const fft = fftModule.default ?? fftModule.fft ?? fftModule;
|
||||
const DOMPurify = purifierModule.default ??
|
||||
purifierModule.DOMPurify ??
|
||||
purifierModule;
|
||||
|
||||
const math = mathModule.default?.sin
|
||||
? mathModule.default
|
||||
: typeof mathModule.create === 'function' && mathModule.all
|
||||
? mathModule.create(mathModule.all)
|
||||
: mathModule;
|
||||
|
||||
const config = yaml.load(yamlString);
|
||||
|
||||
if (
|
||||
!config ||
|
||||
Array.isArray(config) ||
|
||||
typeof config !== 'object'
|
||||
) {
|
||||
throw new TypeError('YAML must describe an object');
|
||||
}
|
||||
|
||||
const { sampleRate, duration, components } = config;
|
||||
|
||||
if (!Number.isFinite(sampleRate) || sampleRate <= 0) {
|
||||
throw new RangeError('sampleRate must be a positive number');
|
||||
}
|
||||
|
||||
if (!Number.isFinite(duration) || duration <= 0) {
|
||||
throw new RangeError('duration must be a positive number');
|
||||
}
|
||||
|
||||
if (!Array.isArray(components)) {
|
||||
throw new TypeError('components must be an array');
|
||||
}
|
||||
|
||||
const N = sampleRate * duration;
|
||||
|
||||
if (!Number.isSafeInteger(N) || N < 2) {
|
||||
throw new RangeError('sampleRate * duration must be an integer of at least 2');
|
||||
}
|
||||
|
||||
const signalComponents = components.map(component => {
|
||||
if (!component || typeof component !== 'object') {
|
||||
throw new TypeError('Each component must be an object');
|
||||
}
|
||||
|
||||
const { frequency, amplitude } = component;
|
||||
|
||||
if (!Number.isFinite(frequency) || !Number.isFinite(amplitude)) {
|
||||
throw new TypeError('Component frequency and amplitude must be numbers');
|
||||
}
|
||||
|
||||
return { frequency, amplitude };
|
||||
});
|
||||
|
||||
const signal = new Float64Array(N);
|
||||
|
||||
for (let i = 0; i < N; i++) {
|
||||
const t = i / sampleRate;
|
||||
|
||||
for (const { frequency, amplitude } of signalComponents) {
|
||||
signal[i] += amplitude *
|
||||
math.sin(2 * math.pi * frequency * t);
|
||||
}
|
||||
}
|
||||
|
||||
const real = ndarray(signal, [N]);
|
||||
const imag = ndarray(new Float64Array(N), [N]);
|
||||
|
||||
fft(1, real, imag);
|
||||
|
||||
const ranked = [];
|
||||
|
||||
for (let k = 0; k <= N / 2; k++) {
|
||||
const magnitude =
|
||||
math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
|
||||
|
||||
if (magnitude > 0.1) {
|
||||
ranked.push({
|
||||
frequencyHz: k * sampleRate / N,
|
||||
magnitude
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ranked.sort((a, b) => b.magnitude - a.magnitude);
|
||||
|
||||
const peaks = ranked.map(({ frequencyHz, magnitude }) => ({
|
||||
frequencyHz: Math.round(frequencyHz),
|
||||
magnitude: Math.round(magnitude * 100) / 100
|
||||
}));
|
||||
|
||||
const rows = peaks
|
||||
.map(({ frequencyHz, magnitude }) =>
|
||||
`<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`
|
||||
)
|
||||
.join('');
|
||||
|
||||
const html = DOMPurify.sanitize(
|
||||
`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`
|
||||
);
|
||||
|
||||
return {
|
||||
peaks,
|
||||
html,
|
||||
signalLength: N
|
||||
};
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 51.151s
|
||||
// Result: FAIL
|
||||
26
tests/3_signal_pipeline/outputs/x-ai_grok-4.5.js
Normal file
26
tests/3_signal_pipeline/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async function analyzeSignal(y){
|
||||
const[m1,m2,m3,m4,m5]=await Promise.all([
|
||||
import('https://esm.sh/js-yaml'),
|
||||
import('https://esm.sh/mathjs'),
|
||||
import('https://esm.sh/ndarray'),
|
||||
import('https://esm.sh/ndarray-fft'),
|
||||
import('https://esm.sh/dompurify')
|
||||
]);
|
||||
const yaml=m1.default,math=m2.default,nd=m3.default,fft=m4.default,DP=m5.default;
|
||||
const c=yaml.load(y),{sampleRate:sr,duration:d,components:cs}=c,N=sr*d;
|
||||
const s=Array.from({length:N},(_,i)=>cs.reduce((a,{frequency:f,amplitude:A})=>a+A*math.sin(2*math.pi*f*i/sr),0));
|
||||
const re=nd(s),im=nd(new Float64Array(N));
|
||||
fft(1,re,im);
|
||||
const mag=[],h=N/2;
|
||||
for(let k=0;k<=h;k++)mag[k]=math.sqrt(re.get(k)**2+im.get(k)**2)/h;
|
||||
const peaks=[];
|
||||
for(let k=0;k<=h;k++)if(mag[k]>0.1)peaks.push({frequencyHz:Math.round(k*sr/N),magnitude:+mag[k].toFixed(2)});
|
||||
peaks.sort((a,b)=>b.magnitude-a.magnitude);
|
||||
let htm='<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>';
|
||||
for(const p of peaks)htm+=`<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`;
|
||||
htm+='</table>';
|
||||
return{peaks,html:DP.sanitize(htm),signalLength:N}
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 30.792s
|
||||
// Result: FAIL
|
||||
43
tests/3_signal_pipeline/outputs/z-ai_glm-5.2.js
Normal file
43
tests/3_signal_pipeline/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,43 @@
|
||||
async function analyzeSignal(yamlStr) {
|
||||
const [{ default: yaml }, { default: math }, { default: ndarray }, { default: fft }, { default: DOMPurify }] = await Promise.all([
|
||||
import('https://esm.sh/js-yaml'),
|
||||
import('https://esm.sh/mathjs'),
|
||||
import('https://esm.sh/ndarray'),
|
||||
import('https://esm.sh/ndarray-fft'),
|
||||
import('https://esm.sh/dompurify')
|
||||
]);
|
||||
|
||||
const { sampleRate, duration, components } = yaml.load(yamlStr);
|
||||
const N = sampleRate * duration;
|
||||
const signal = new Float64Array(N);
|
||||
|
||||
for (let i = 0; i < N; i++) {
|
||||
const t = i / sampleRate;
|
||||
signal[i] = components.reduce((s, c) => s + c.amplitude * math.sin(2 * math.pi * c.frequency * t), 0);
|
||||
}
|
||||
|
||||
const real = ndarray(signal, [N]);
|
||||
const imag = ndarray(new Float64Array(N), [N]);
|
||||
fft(1, real, imag);
|
||||
|
||||
const peaks = [];
|
||||
for (let k = 0; k <= N / 2; k++) {
|
||||
const mag = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
|
||||
if (mag > 0.1) {
|
||||
peaks.push({
|
||||
frequencyHz: Math.round(k * sampleRate / N),
|
||||
magnitude: parseFloat(mag.toFixed(2))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
peaks.sort((a, b) => b.magnitude - a.magnitude);
|
||||
|
||||
const rows = peaks.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`).join('');
|
||||
const html = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`;
|
||||
|
||||
return { peaks, html: DOMPurify.sanitize(html), signalLength: N };
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 34.195s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,51 @@
|
||||
const load = name => import(`https://esm.sh/${name}`);
|
||||
|
||||
async function hexchain(tomlString) {
|
||||
const [
|
||||
{ parse },
|
||||
{ default: seedrandom },
|
||||
ss,
|
||||
{ default: Ajv },
|
||||
{ default: table },
|
||||
{ default: DOMPurify }
|
||||
] = await Promise.all(
|
||||
['smol-toml', 'seedrandom', 'simple-statistics', 'ajv', 'text-table', 'dompurify'].map(load)
|
||||
);
|
||||
|
||||
const config = parse(tomlString);
|
||||
const ajv = new Ajv();
|
||||
const schema = {
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
};
|
||||
|
||||
if (!ajv.validate(schema, config)) return { valid: false, errors: ajv.errorsText() };
|
||||
|
||||
const rng = new seedrandom(config.seed);
|
||||
const nums = Array.from({ length: config.count }, () => rng());
|
||||
const round6 = x => Math.round(x * 1e6) / 1e6;
|
||||
const [mean, stddev, median] = [ss.mean, ss.standardDeviation, ss.median].map(f => round6(f(nums)));
|
||||
|
||||
const ascii = table([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: DOMPurify.sanitize(`<pre class="stats">${ascii}</pre>`),
|
||||
count: config.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 14.324s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,67 @@
|
||||
const CDN = "https://esm.sh/";
|
||||
|
||||
const hexchain = async (toml) => {
|
||||
const [
|
||||
{ parse },
|
||||
{ default: seedrandom },
|
||||
ss,
|
||||
{ default: Ajv },
|
||||
{ default: table },
|
||||
{ default: DOMPurify }
|
||||
] = await Promise.all([
|
||||
import(`${CDN}smol-toml`),
|
||||
import(`${CDN}seedrandom`),
|
||||
import(`${CDN}simple-statistics`),
|
||||
import(`${CDN}ajv`),
|
||||
import(`${CDN}text-table`),
|
||||
import(`${CDN}dompurify`)
|
||||
]);
|
||||
|
||||
const config = parse(toml);
|
||||
|
||||
const schema = {
|
||||
type: "object",
|
||||
required: ["seed", "count", "label"],
|
||||
properties: {
|
||||
seed: { type: "string" },
|
||||
count: { type: "integer", minimum: 1, maximum: 10000 },
|
||||
label: { type: "string", minLength: 1 }
|
||||
}
|
||||
};
|
||||
|
||||
const ajv = new Ajv();
|
||||
if (!ajv.validate(schema, config))
|
||||
return { valid: false, errors: ajv.errorsText() };
|
||||
|
||||
const rng = new seedrandom(config.seed);
|
||||
const nums = Array.from({ length: config.count }, () => rng());
|
||||
|
||||
const r = (n) => Math.round(n * 1e6) / 1e6;
|
||||
const mean = r(ss.mean(nums));
|
||||
const stddev = r(ss.standardDeviation(nums));
|
||||
const median = r(ss.median(nums));
|
||||
|
||||
const tableString = table([
|
||||
["Stat", "Value"],
|
||||
["mean", String(mean)],
|
||||
["stddev", String(stddev)],
|
||||
["median", String(median)]
|
||||
]);
|
||||
|
||||
const sanitized = DOMPurify.sanitize(
|
||||
`<pre class="stats">${tableString}</pre>`
|
||||
);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: sanitized,
|
||||
count: config.count
|
||||
};
|
||||
};
|
||||
|
||||
export { hexchain };
|
||||
export default hexchain;
|
||||
// Generation time: 8.247s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,73 @@
|
||||
const CDN = {
|
||||
toml: 'https://esm.sh/smol-toml@1',
|
||||
seedrandom: 'https://esm.sh/seedrandom@3',
|
||||
stats: 'https://esm.sh/simple-statistics@7',
|
||||
ajv: 'https://esm.sh/ajv@8',
|
||||
table: 'https://esm.sh/text-table@1',
|
||||
dompurify: 'https://esm.sh/dompurify@3',
|
||||
};
|
||||
|
||||
const SCHEMA = {
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 },
|
||||
},
|
||||
};
|
||||
|
||||
const round6 = n => Math.round(n * 1e6) / 1e6;
|
||||
|
||||
async function hexchain(tomlStr) {
|
||||
const [{ parse }, seedrandomMod, ss, AjvMod, tableMod, DOMPurify] = await Promise.all([
|
||||
import(CDN.toml),
|
||||
import(CDN.seedrandom),
|
||||
import(CDN.stats),
|
||||
import(CDN.ajv),
|
||||
import(CDN.table),
|
||||
import(CDN.dompurify),
|
||||
]);
|
||||
|
||||
const seedrandom = seedrandomMod.default;
|
||||
const Ajv = AjvMod.default;
|
||||
const table = tableMod.default;
|
||||
const purify = DOMPurify.default ?? DOMPurify;
|
||||
|
||||
const config = parse(tomlStr);
|
||||
|
||||
const ajv = new Ajv();
|
||||
const validate = ajv.compile(SCHEMA);
|
||||
if (!validate(config)) {
|
||||
return { valid: false, errors: ajv.errorsText(validate.errors) };
|
||||
}
|
||||
|
||||
const rng = new seedrandom(config.seed);
|
||||
const numbers = Array.from({ length: config.count }, () => rng());
|
||||
|
||||
const mean = round6(ss.mean(numbers));
|
||||
const stddev = round6(ss.standardDeviation(numbers));
|
||||
const median = round6(ss.median(numbers));
|
||||
|
||||
const rows = [
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)],
|
||||
];
|
||||
const tableStr = table(rows);
|
||||
|
||||
const rawHtml = `<pre class="stats">${tableStr}</pre>`;
|
||||
const sanitizedHtml = purify.sanitize(rawHtml);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: sanitizedHtml,
|
||||
count: config.count,
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 10.215s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,58 @@
|
||||
const hexchain = async (toml) => {
|
||||
const [tm, sd, ss, am, tt, pm] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/seedrandom'),
|
||||
import('https://esm.sh/simple-statistics'),
|
||||
import('https://esm.sh/ajv'),
|
||||
import('https://esm.sh/text-table'),
|
||||
import('https://esm.sh/dompurify')
|
||||
]);
|
||||
|
||||
const parse = tm.parse;
|
||||
const seedrandom = sd.default;
|
||||
const Ajv = am.default;
|
||||
const table = tt.default;
|
||||
const DOMPurify = pm.default;
|
||||
|
||||
const config = parse(toml);
|
||||
const schema = {
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
};
|
||||
|
||||
const ajv = new Ajv();
|
||||
if (!ajv.validate(schema, config)) return { valid: false, errors: ajv.errorsText() };
|
||||
|
||||
const rng = seedrandom(config.seed);
|
||||
const nums = Array.from({ length: config.count }, rng);
|
||||
const round = (x) => Math.round(x * 1e6) / 1e6;
|
||||
|
||||
const mean = round(ss.mean(nums));
|
||||
const stddev = round(ss.standardDeviation(nums));
|
||||
const median = round(ss.median(nums));
|
||||
|
||||
const tbl = table([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
const clean = DOMPurify.sanitize('<pre class="stats">' + tbl + '</pre>');
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: clean,
|
||||
count: config.count
|
||||
};
|
||||
};
|
||||
export default hexchain;
|
||||
// Generation time: 69.982s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,49 @@
|
||||
const CDN = 'https://esm.sh/';
|
||||
|
||||
async function hexchain(toml) {
|
||||
const [tomlM, seedM, ssM, ajvM, ttM, dpM] = await Promise.all(
|
||||
['smol-toml@1', 'seedrandom@3', 'simple-statistics@7', 'ajv@8', 'text-table@0.2', 'dompurify@3']
|
||||
.map(p => import(CDN + p))
|
||||
);
|
||||
|
||||
const config = tomlM.parse(toml);
|
||||
const ajv = new ajvM.default();
|
||||
const valid = ajv.validate({
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
}, config);
|
||||
if (!valid) return { valid: false, errors: ajv.errorsText() };
|
||||
|
||||
const rng = new seedM.default(config.seed);
|
||||
const nums = Array.from({ length: config.count }, () => rng());
|
||||
const r6 = x => Math.round(x * 1e6) / 1e6;
|
||||
const mean = r6(ssM.mean(nums));
|
||||
const stddev = r6(ssM.standardDeviation(nums));
|
||||
const median = r6(ssM.median(nums));
|
||||
|
||||
const table = ttM.default([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
const dp = dpM.default ?? dpM;
|
||||
const purify = dp.sanitize ? dp : dp(window);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: purify.sanitize('<pre class="stats">' + table + '</pre>'),
|
||||
count: config.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 84.644s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,63 @@
|
||||
async function hexchain(toml) {
|
||||
const [
|
||||
{ parse },
|
||||
{ default: seedrandom },
|
||||
{ mean, standardDeviation, median },
|
||||
{ default: Ajv },
|
||||
{ default: textTable },
|
||||
{ default: DOMPurify }
|
||||
] = await Promise.all([
|
||||
import("https://esm.sh/smol-toml@1.3.1"),
|
||||
import("https://esm.sh/seedrandom@3.0.5"),
|
||||
import("https://esm.sh/simple-statistics@7.8.8"),
|
||||
import("https://esm.sh/ajv@8.17.1"),
|
||||
import("https://esm.sh/text-table@0.2.0"),
|
||||
import("https://esm.sh/dompurify@3.2.4")
|
||||
]);
|
||||
|
||||
const config = parse(toml);
|
||||
const ajv = new Ajv();
|
||||
const schema = {
|
||||
type: "object",
|
||||
required: ["seed", "count", "label"],
|
||||
properties: {
|
||||
seed: { type: "string" },
|
||||
count: { type: "integer", minimum: 1, maximum: 10000 },
|
||||
label: { type: "string", minLength: 1 }
|
||||
}
|
||||
};
|
||||
|
||||
if (!ajv.validate(schema, config)) {
|
||||
return { valid: false, errors: ajv.errorsText() };
|
||||
}
|
||||
|
||||
const rng = new seedrandom(config.seed);
|
||||
const numbers = Array.from({ length: config.count }, () => rng());
|
||||
const stats = {
|
||||
mean: Number(mean(numbers).toFixed(6)),
|
||||
stddev: Number(standardDeviation(numbers).toFixed(6)),
|
||||
median: Number(median(numbers).toFixed(6))
|
||||
};
|
||||
|
||||
const tableString = textTable([
|
||||
["Stat", "Value"],
|
||||
["mean", String(stats.mean)],
|
||||
["stddev", String(stats.stddev)],
|
||||
["median", String(stats.median)]
|
||||
]);
|
||||
|
||||
const table = DOMPurify.sanitize(
|
||||
`<pre class="stats">${tableString}</pre>`
|
||||
);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats,
|
||||
table,
|
||||
count: config.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 13.622s
|
||||
// Result: PASS
|
||||
23
tests/4_hexchain_pipeline/outputs/x-ai_grok-4.5.js
Normal file
23
tests/4_hexchain_pipeline/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,23 @@
|
||||
async function hexchain(t){
|
||||
const[{parse},sr,ss,Ajv,tt,DP]=await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/seedrandom').then(m=>m.default),
|
||||
import('https://esm.sh/simple-statistics'),
|
||||
import('https://esm.sh/ajv').then(m=>m.default),
|
||||
import('https://esm.sh/text-table').then(m=>m.default),
|
||||
import('https://esm.sh/dompurify').then(m=>m.default)
|
||||
]);
|
||||
const c=parse(t);
|
||||
const a=new Ajv();
|
||||
const s={type:'object',required:['seed','count','label'],properties:{seed:{type:'string'},count:{type:'integer',minimum:1,maximum:10000},label:{type:'string',minLength:1}}};
|
||||
if(!a.validate(s,c))return{valid:false,errors:a.errorsText()};
|
||||
const r=sr(c.seed),n=[];
|
||||
for(let i=0;i<c.count;i++)n.push(r());
|
||||
const mean=+ss.mean(n).toFixed(6),stddev=+ss.standardDeviation(n).toFixed(6),median=+ss.median(n).toFixed(6);
|
||||
const tab=tt([['Stat','Value'],['mean',String(mean)],['stddev',String(stddev)],['median',String(median)]]);
|
||||
const html=DP.sanitize(`<pre class="stats">${tab}</pre>`);
|
||||
return{valid:true,label:c.label,stats:{mean,stddev,median},table:html,count:c.count};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 6.554s
|
||||
// Result: PASS
|
||||
25
tests/4_hexchain_pipeline/outputs/z-ai_glm-5.2.js
Normal file
25
tests/4_hexchain_pipeline/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const hexchain = async (t) => {
|
||||
const [{ parse }, { default: R }, S, { default: A }, { default: T }, { default: D }] = await Promise.all([
|
||||
import('https://esm.run/smol-toml'),
|
||||
import('https://esm.run/seedrandom'),
|
||||
import('https://esm.run/simple-statistics'),
|
||||
import('https://esm.run/ajv'),
|
||||
import('https://esm.run/text-table'),
|
||||
import('https://esm.run/dompurify')
|
||||
]);
|
||||
const c = parse(t);
|
||||
const s = { type:'object', required:['seed','count','label'], properties:{ seed:{type:'string'}, count:{type:'integer',minimum:1,maximum:10000}, label:{type:'string',minLength:1} } };
|
||||
const a = new A();
|
||||
if (!a.validate(s, c)) return { valid:false, errors: a.errorsText() };
|
||||
const r = R(c.seed);
|
||||
const n = Array.from({ length: c.count }, r);
|
||||
const m = +S.mean(n).toFixed(6);
|
||||
const d = +S.standardDeviation(n).toFixed(6);
|
||||
const e = +S.median(n).toFixed(6);
|
||||
const tb = T([['Stat','Value'],['mean',m.toFixed(6)],['stddev',d.toFixed(6)],['median',e.toFixed(6)]]);
|
||||
const h = D.sanitize(`<pre class="stats">${tb}</pre>`);
|
||||
return { valid:true, label:c.label, stats:{ mean:m, stddev:d, median:e }, table:h, count:c.count };
|
||||
};
|
||||
export default hexchain;
|
||||
// Generation time: 76.627s
|
||||
// Result: PASS
|
||||
13
tests/5_markdown_parser/outputs/anthropic_claude-fable-5.js
Normal file
13
tests/5_markdown_parser/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,13 @@
|
||||
let markedPromise;
|
||||
|
||||
const loadMarked = () =>
|
||||
markedPromise ??= import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm');
|
||||
|
||||
async function parseMarkdown(markdown) {
|
||||
if (typeof markdown !== 'string') throw new TypeError('parseMarkdown expects a string');
|
||||
const { marked } = await loadMarked();
|
||||
return marked.parse(markdown, { gfm: true, async: true });
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 10.393s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,9 @@
|
||||
const parseMarkdown = async (md = "") => {
|
||||
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/+esm");
|
||||
return marked.parse(md, { gfm: true, breaks: true });
|
||||
};
|
||||
|
||||
|
||||
export default parseMarkdown;
|
||||
// Generation time: 6.625s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,14 @@
|
||||
async function parseMarkdown(markdown) {
|
||||
const [{ marked }, DOMPurify] = await Promise.all([
|
||||
import('https://esm.sh/marked@12'),
|
||||
import('https://esm.sh/dompurify@3').then(m => m.default),
|
||||
]);
|
||||
|
||||
marked.setOptions({ gfm: true, breaks: true });
|
||||
|
||||
const rawHtml = marked.parse(markdown ?? '');
|
||||
return DOMPurify.sanitize(rawHtml);
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 4.740s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,7 @@
|
||||
const parseMarkdown = async (md) => {
|
||||
const { default: MarkdownIt } = await import('https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/+esm');
|
||||
return MarkdownIt({ html: false, linkify: true }).render(md);
|
||||
};
|
||||
export default parseMarkdown;
|
||||
// Generation time: 18.711s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,15 @@
|
||||
let libs;
|
||||
|
||||
const load = () => libs ??= Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/dompurify@3.1.5/+esm'),
|
||||
]).then(([{ marked }, { default: purify }]) => ({ marked, purify }));
|
||||
|
||||
async function parseMarkdown(md) {
|
||||
const { marked, purify } = await load();
|
||||
const html = marked.parse(String(md ?? ''), { gfm: true });
|
||||
return purify.sanitize(html, { USE_PROFILES: { html: true } });
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 40.071s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,21 @@
|
||||
let dependencies;
|
||||
|
||||
const loadDependencies = () =>
|
||||
dependencies ??= Promise.all([
|
||||
import("https://esm.sh/marked@15.0.12"),
|
||||
import("https://esm.sh/dompurify@3.2.6")
|
||||
]);
|
||||
|
||||
async function parseMarkdown(markdown) {
|
||||
if (typeof markdown !== "string") {
|
||||
throw new TypeError("Markdown must be a string");
|
||||
}
|
||||
|
||||
const [{ marked }, { default: DOMPurify }] = await loadDependencies();
|
||||
const html = marked.parse(markdown, { gfm: true });
|
||||
|
||||
return DOMPurify.sanitize(html);
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 13.055s
|
||||
// Result: PASS
|
||||
7
tests/5_markdown_parser/outputs/x-ai_grok-4.5.js
Normal file
7
tests/5_markdown_parser/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,7 @@
|
||||
async function parseMarkdown(s){
|
||||
const{marked}=await import('https://cdn.jsdelivr.net/npm/marked@13.0.3/lib/marked.esm.js')
|
||||
return marked.parse(s)
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 6.585s
|
||||
// Result: PASS
|
||||
7
tests/5_markdown_parser/outputs/z-ai_glm-5.2.js
Normal file
7
tests/5_markdown_parser/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const parseMarkdown = async (md) => {
|
||||
const { marked } = await import('https://esm.sh/marked');
|
||||
return marked.parse(md);
|
||||
};
|
||||
export default parseMarkdown;
|
||||
// Generation time: 17.682s
|
||||
// Result: PASS
|
||||
23
tests/6_csv_processor/outputs/anthropic_claude-fable-5.js
Normal file
23
tests/6_csv_processor/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { default: Papa } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { data } = Papa.parse(csv.trim(), { header: true, skipEmptyLines: true });
|
||||
const groups = new Map();
|
||||
|
||||
for (const row of data) {
|
||||
if (row[filterColumn] != filterValue) continue;
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
const g = groups.get(key) ?? { sum: 0, count: 0 };
|
||||
g.sum += val;
|
||||
g.count++;
|
||||
groups.set(key, g);
|
||||
}
|
||||
|
||||
return [...groups].map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'sum' ? sum : operation === 'avg' ? sum / count : count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
// Generation time: 14.656s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,29 @@
|
||||
const processCSV = async (csv, config) => {
|
||||
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
|
||||
const [{ default: Papa }, { default: _ }] = await Promise.all([
|
||||
import("https://esm.sh/papaparse@5.4.1"),
|
||||
import("https://esm.sh/lodash-es@4.17.21")
|
||||
]);
|
||||
|
||||
const { data } = Papa.parse(csv.trim(), { header: true, skipEmptyLines: true });
|
||||
const num = v => {
|
||||
const n = Number(v);
|
||||
return isNaN(n) ? 0 : n;
|
||||
};
|
||||
|
||||
const filtered = data.filter(r => r[filterColumn] == filterValue);
|
||||
const groups = _.groupBy(filtered, r => r[groupBy]);
|
||||
|
||||
return _.map(groups, (rows, key) => {
|
||||
const vals = rows.map(r => num(r[aggregateColumn]));
|
||||
const sum = _.sum(vals);
|
||||
const result =
|
||||
operation === "sum" ? sum :
|
||||
operation === "avg" ? sum / rows.length :
|
||||
rows.length;
|
||||
return { [groupBy]: key, result };
|
||||
});
|
||||
};
|
||||
export default processCSV;
|
||||
// Generation time: 6.170s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,29 @@
|
||||
async function processCSV(csvString, config) {
|
||||
const { filterColumn, filterValue, groupBy: groupCol, aggregateColumn, operation } = config;
|
||||
|
||||
const [{ default: Papa }, { groupBy }] = await Promise.all([
|
||||
import('https://esm.sh/papaparse@5.4.1'),
|
||||
import('https://esm.sh/lodash-es@4.17.21'),
|
||||
]);
|
||||
|
||||
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue);
|
||||
|
||||
const groups = groupBy(filtered, row => row[groupCol]);
|
||||
|
||||
return Object.entries(groups).map(([key, rows]) => {
|
||||
const values = rows.map(row => Number(row[aggregateColumn]) || 0);
|
||||
const sum = values.reduce((acc, v) => acc + v, 0);
|
||||
|
||||
const result =
|
||||
operation === 'sum' ? sum :
|
||||
operation === 'avg' ? sum / values.length :
|
||||
values.length;
|
||||
|
||||
return { [groupCol]: key, result };
|
||||
});
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 8.882s
|
||||
// Result: PASS
|
||||
36
tests/6_csv_processor/outputs/moonshotai_kimi-k2.7-code.js
Normal file
36
tests/6_csv_processor/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const processCSV = async (csv, {
|
||||
filterColumn: f,
|
||||
filterValue: v,
|
||||
groupBy: g,
|
||||
aggregateColumn: a,
|
||||
operation: o
|
||||
}) => {
|
||||
const [{ default: P }, { groupBy: G }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
]);
|
||||
|
||||
const N = x => {
|
||||
const y = Number(x);
|
||||
return Number.isFinite(y) ? y : 0;
|
||||
};
|
||||
|
||||
const rows = P.parse(csv, { header: true, skipEmptyLines: true }).data;
|
||||
const groups = G(rows.filter(r => r[f] == v), r => r[g]);
|
||||
|
||||
return Object.entries(groups).map(([k, list]) => {
|
||||
let result = 0;
|
||||
|
||||
if (o === 'count') {
|
||||
result = list.length;
|
||||
} else {
|
||||
const total = list.reduce((s, r) => s + N(r[a]), 0);
|
||||
result = o === 'avg' ? total / list.length : total;
|
||||
}
|
||||
|
||||
return { [g]: k, result };
|
||||
});
|
||||
};
|
||||
export default processCSV;
|
||||
// Generation time: 38.066s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,21 @@
|
||||
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
|
||||
const [{ default: Papa }, { groupBy: group, sumBy }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
]);
|
||||
const num = r => +r[aggregateColumn] || 0;
|
||||
const ops = {
|
||||
sum: rs => sumBy(rs, num),
|
||||
avg: rs => sumBy(rs, num) / rs.length,
|
||||
count: rs => rs.length
|
||||
};
|
||||
if (!ops[operation]) throw new Error(`Unsupported operation: ${operation}`);
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
return Object.entries(group(data.filter(r => r[filterColumn] == filterValue), groupBy))
|
||||
.map(([key, rows]) => ({ [groupBy]: key, result: ops[operation](rows) }));
|
||||
}
|
||||
|
||||
|
||||
export default processCSV;
|
||||
// Generation time: 79.891s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,73 @@
|
||||
const dependencies = Promise.all([
|
||||
import("https://cdn.jsdelivr.net/npm/papaparse@5.4.3/+esm"),
|
||||
import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm")
|
||||
]);
|
||||
|
||||
async function processCSV(csv, config) {
|
||||
if (typeof csv !== "string") throw new TypeError("csv must be a string");
|
||||
if (!config || typeof config !== "object") {
|
||||
throw new TypeError("config must be an object");
|
||||
}
|
||||
|
||||
const {
|
||||
filterColumn,
|
||||
filterValue,
|
||||
groupBy,
|
||||
aggregateColumn,
|
||||
operation
|
||||
} = config;
|
||||
|
||||
if (![filterColumn, groupBy, aggregateColumn].every(
|
||||
value => typeof value === "string"
|
||||
)) {
|
||||
throw new TypeError("Column names must be strings");
|
||||
}
|
||||
|
||||
if (!["sum", "avg", "count"].includes(operation)) {
|
||||
throw new RangeError("operation must be sum, avg, or count");
|
||||
}
|
||||
|
||||
const [parserModule, utilityModule] = await dependencies;
|
||||
const Papa = parserModule.default ?? parserModule;
|
||||
const _ = utilityModule.default ?? utilityModule;
|
||||
|
||||
const parsed = Papa.parse(csv, {
|
||||
header: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
if (parsed.errors.length) {
|
||||
throw new Error(
|
||||
parsed.errors.map(error => error.message).join("; ")
|
||||
);
|
||||
}
|
||||
|
||||
const rows = _.filter(
|
||||
parsed.data,
|
||||
row => row[filterColumn] == filterValue
|
||||
);
|
||||
|
||||
const groups = _.groupBy(rows, groupBy);
|
||||
|
||||
const toNumber = value => {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number : 0;
|
||||
};
|
||||
|
||||
return Object.values(groups).map(group => {
|
||||
const total = operation === "count"
|
||||
? group.length
|
||||
: group.reduce(
|
||||
(sum, row) => sum + toNumber(row[aggregateColumn]),
|
||||
0
|
||||
);
|
||||
|
||||
return {
|
||||
[groupBy]: group[0][groupBy],
|
||||
result: operation === "avg" ? total / group.length : total
|
||||
};
|
||||
});
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 22.212s
|
||||
// Result: FAIL
|
||||
4
tests/6_csv_processor/outputs/x-ai_grok-4.5.js
Normal file
4
tests/6_csv_processor/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,4 @@
|
||||
async function processCSV(c,g){const{filterColumn:f,filterValue:v,groupBy:b,aggregateColumn:a,operation:o}=g;const P=(await import('https://esm.sh/papaparse')).default;const L=(await import('https://esm.sh/lodash')).default;const{data:d}=P.parse(c,{header:1,skipEmptyLines:1});const r=L.filter(d,x=>x[f]==v);const m=L.groupBy(r,b);return Object.entries(m).map(([k,s])=>{let e;if(o=='count')e=s.length;else{const n=s.map(x=>{const t=+x[a];return isNaN(t)?0:t});const u=n.reduce((p,q)=>p+q,0);e=o=='sum'?u:u/n.length}return{[b]:k,result:e}})}
|
||||
export default processCSV;
|
||||
// Generation time: 17.149s
|
||||
// Result: PASS
|
||||
21
tests/6_csv_processor/outputs/z-ai_glm-5.2.js
Normal file
21
tests/6_csv_processor/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const processCSV = async (csv, c) => {
|
||||
const Papa = (await import('https://esm.run/papaparse@5')).default;
|
||||
const { data } = Papa.parse(csv, { header: true });
|
||||
|
||||
return Object.values(
|
||||
data.reduce((acc, r) => {
|
||||
if (r[c.filterColumn] != c.filterValue) return acc;
|
||||
const k = r[c.groupBy];
|
||||
acc[k] ??= { [c.groupBy]: k, sum: 0, count: 0 };
|
||||
acc[k].sum += Number(r[c.aggregateColumn]) || 0;
|
||||
acc[k].count++;
|
||||
return acc;
|
||||
}, {})
|
||||
).map(g => ({
|
||||
[c.groupBy]: g[c.groupBy],
|
||||
result: c.operation === 'count' ? g.count : c.operation === 'sum' ? g.sum : g.sum / g.count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
// Generation time: 31.429s
|
||||
// Result: PASS
|
||||
42
tests/7_scheduler/outputs/anthropic_claude-fable-5.js
Normal file
42
tests/7_scheduler/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const findAvailableSlots = async (calendarA, calendarB, { durationMinutes, searchRange, workHours }) => {
|
||||
const { DateTime, Interval } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
|
||||
|
||||
const utc = s => DateTime.fromISO(s, { zone: 'utc' });
|
||||
const parseHM = s => s.split(':').map(Number);
|
||||
|
||||
const range = Interval.fromDateTimes(utc(searchRange.start), utc(searchRange.end));
|
||||
const busy = Interval.merge(
|
||||
[...calendarA, ...calendarB].map(({ start, end }) => Interval.fromDateTimes(utc(start), utc(end)))
|
||||
);
|
||||
const free = range.difference(...busy);
|
||||
|
||||
const [wsH, wsM] = parseHM(workHours.start);
|
||||
const [weH, weM] = parseHM(workHours.end);
|
||||
const slots = [];
|
||||
|
||||
for (const period of free) {
|
||||
let day = period.start.startOf('day');
|
||||
while (day < period.end) {
|
||||
const workWindow = Interval.fromDateTimes(
|
||||
day.set({ hour: wsH, minute: wsM }),
|
||||
day.set({ hour: weH, minute: weM })
|
||||
);
|
||||
const window = period.intersection(workWindow);
|
||||
if (window) {
|
||||
let cursor = window.start;
|
||||
let next = cursor.plus({ minutes: durationMinutes });
|
||||
while (next <= window.end) {
|
||||
slots.push({ start: cursor.toISO(), end: next.toISO() });
|
||||
cursor = next;
|
||||
next = cursor.plus({ minutes: durationMinutes });
|
||||
}
|
||||
}
|
||||
day = day.plus({ days: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
};
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 20.786s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,53 @@
|
||||
async function findAvailableSlots(cal1, cal2, constraints) {
|
||||
const { DateTime } = await import('https://cdn.skypack.dev/luxon');
|
||||
const { durationMinutes: dur, searchRange, workHours } = constraints;
|
||||
const opt = { zone: 'utc' };
|
||||
const toDT = s => DateTime.fromISO(s, opt);
|
||||
const rs = toDT(searchRange.start), re = toDT(searchRange.end);
|
||||
const [wsH, wsM] = workHours.start.split(':').map(Number);
|
||||
const [weH, weM] = workHours.end.split(':').map(Number);
|
||||
|
||||
const busy = [...cal1, ...cal2]
|
||||
.map(b => [toDT(b.start), toDT(b.end)])
|
||||
.filter(([s, e]) => e > s)
|
||||
.sort((a, b) => a[0] - b[0]);
|
||||
|
||||
const merged = [];
|
||||
for (const [s, e] of busy) {
|
||||
const last = merged[merged.length - 1];
|
||||
if (last && s <= last[1]) {
|
||||
if (e > last[1]) last[1] = e;
|
||||
} else merged.push([s, e]);
|
||||
}
|
||||
|
||||
const slots = [];
|
||||
for (let day = rs.startOf('day'); day < re; day = day.plus({ days: 1 })) {
|
||||
const ws = day.set({ hour: wsH, minute: wsM, second: 0, millisecond: 0 });
|
||||
const we = day.set({ hour: weH, minute: weM, second: 0, millisecond: 0 });
|
||||
const winS = ws > rs ? ws : rs;
|
||||
const winE = we < re ? we : re;
|
||||
if (winS >= winE) continue;
|
||||
|
||||
const free = [];
|
||||
let cur = winS;
|
||||
for (const [bs, be] of merged) {
|
||||
if (be <= cur || bs >= winE) continue;
|
||||
if (bs > cur) free.push([cur, bs]);
|
||||
if (be > cur) cur = be;
|
||||
if (cur >= winE) break;
|
||||
}
|
||||
if (cur < winE) free.push([cur, winE]);
|
||||
|
||||
for (const [fs, fe] of free) {
|
||||
let start = fs;
|
||||
for (let nxt; (nxt = start.plus({ minutes: dur })) <= fe; start = nxt) {
|
||||
slots.push({ start: start.toUTC().toISO(), end: nxt.toUTC().toISO() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots.sort((a, b) => (a.start < b.start ? -1 : 1));
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 22.608s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,62 @@
|
||||
async function findAvailableSlots(calendarA, calendarB, constraints) {
|
||||
const { parseISO, addMinutes, addDays, startOfDay, max, min } =
|
||||
await import('https://esm.sh/date-fns@3');
|
||||
|
||||
const toRange = c => ({ start: parseISO(c.start), end: parseISO(c.end) });
|
||||
|
||||
const busy = [...calendarA, ...calendarB]
|
||||
.map(toRange)
|
||||
.sort((a, b) => a.start - b.start);
|
||||
|
||||
const merged = [];
|
||||
for (const slot of busy) {
|
||||
const last = merged[merged.length - 1];
|
||||
if (last && slot.start <= last.end) last.end = max([last.end, slot.end]);
|
||||
else merged.push({ ...slot });
|
||||
}
|
||||
|
||||
const searchStart = parseISO(constraints.searchRange.start);
|
||||
const searchEnd = parseISO(constraints.searchRange.end);
|
||||
const duration = constraints.durationMinutes;
|
||||
|
||||
const free = [];
|
||||
let cursor = searchStart;
|
||||
for (const b of merged) {
|
||||
if (b.start >= searchEnd) break;
|
||||
if (b.end <= searchStart) continue;
|
||||
if (b.start > cursor) free.push({ start: cursor, end: min([b.start, searchEnd]) });
|
||||
cursor = max([cursor, b.end]);
|
||||
}
|
||||
if (cursor < searchEnd) free.push({ start: cursor, end: searchEnd });
|
||||
|
||||
const [wsH, wsM] = constraints.workHours.start.split(':').map(Number);
|
||||
const [weH, weM] = constraints.workHours.end.split(':').map(Number);
|
||||
|
||||
const slots = [];
|
||||
for (const period of free) {
|
||||
let dayStart = startOfDay(period.start);
|
||||
|
||||
while (dayStart < period.end) {
|
||||
const y = dayStart.getUTCFullYear(), m = dayStart.getUTCMonth(), d = dayStart.getUTCDate();
|
||||
const workStart = new Date(Date.UTC(y, m, d, wsH, wsM));
|
||||
const workEnd = new Date(Date.UTC(y, m, d, weH, weM));
|
||||
|
||||
const windowStart = max([workStart, period.start]);
|
||||
const windowEnd = min([workEnd, period.end]);
|
||||
|
||||
let slotStart = windowStart;
|
||||
while (addMinutes(slotStart, duration) <= windowEnd) {
|
||||
const slotEnd = addMinutes(slotStart, duration);
|
||||
slots.push({ start: slotStart.toISOString(), end: slotEnd.toISOString() });
|
||||
slotStart = slotEnd;
|
||||
}
|
||||
|
||||
dayStart = addDays(dayStart, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 26.434s
|
||||
// Result: PASS
|
||||
54
tests/7_scheduler/outputs/moonshotai_kimi-k2.7-code.js
Normal file
54
tests/7_scheduler/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const luxonP = import('https://esm.sh/luxon@3.4.4');
|
||||
|
||||
const findAvailableSlots = async (a, b, c) => {
|
||||
const { DateTime, Duration } = await luxonP;
|
||||
if (c.durationMinutes <= 0) return [];
|
||||
|
||||
const u = s => DateTime.fromISO(s, { zone: 'utc' });
|
||||
const hm = s => { const [h, m] = s.split(':'); return +h * 60 + +m; };
|
||||
|
||||
const D = Duration.fromObject({ days: 1 });
|
||||
const z = Duration.fromObject({ minutes: c.durationMinutes });
|
||||
const w0 = hm(c.workHours.start);
|
||||
const w1 = hm(c.workHours.end);
|
||||
const rng = { s: u(c.searchRange.start), e: u(c.searchRange.end) };
|
||||
|
||||
const busy = [...a, ...b]
|
||||
.map(x => ({ s: u(x.start), e: u(x.end) }))
|
||||
.filter(x => +x.s < +x.e)
|
||||
.sort((x, y) => +x.s - +y.s || +x.e - +y.e);
|
||||
|
||||
const mrg = [];
|
||||
for (const x of busy) {
|
||||
const l = mrg[mrg.length - 1];
|
||||
if (l && +x.s <= +l.e) l.e = DateTime.max(l.e, x.e);
|
||||
else mrg.push({ s: x.s, e: x.e });
|
||||
}
|
||||
|
||||
const free = [];
|
||||
let cur = rng.s;
|
||||
for (const x of mrg) {
|
||||
if (x.s > cur) free.push({ s: DateTime.max(cur, rng.s), e: DateTime.min(x.s, rng.e) });
|
||||
cur = DateTime.max(cur, x.e);
|
||||
if (cur >= rng.e) break;
|
||||
}
|
||||
if (cur < rng.e) free.push({ s: cur, e: rng.e });
|
||||
|
||||
const slots = [];
|
||||
for (const x of free) {
|
||||
if (x.s >= x.e) continue;
|
||||
for (let d = x.s.startOf('day'); d <= x.e; d = d.plus(D)) {
|
||||
const i = DateTime.max(x.s, d.plus({ minutes: w0 }), rng.s);
|
||||
const j = DateTime.min(x.e, d.plus({ minutes: w1 }), rng.e);
|
||||
for (let t = i; j >= t.plus(z); t = t.plus(z)) {
|
||||
const v = t.plus(z);
|
||||
slots.push({ start: t.toJSDate().toISOString(), end: v.toJSDate().toISOString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
};
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 173.316s
|
||||
// Result: PASS
|
||||
64
tests/7_scheduler/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
64
tests/7_scheduler/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,64 @@
|
||||
export async function findAvailableSlots(calendar1, calendar2, constraints) {
|
||||
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
|
||||
const utc = (s) => DateTime.fromISO(s, { zone: 'utc' });
|
||||
const { durationMinutes, searchRange, workHours } = constraints;
|
||||
const rs = utc(searchRange.start);
|
||||
const re = utc(searchRange.end);
|
||||
|
||||
const busy = [...calendar1, ...calendar2]
|
||||
.map(({ start, end }) => [utc(start), utc(end)])
|
||||
.filter(([s, e]) => e > s)
|
||||
.sort((a, b) => a[0] - b[0]);
|
||||
|
||||
const merged = [];
|
||||
for (const [s, e] of busy) {
|
||||
const last = merged.at(-1);
|
||||
if (last && s <= last[1]) last[1] = e > last[1] ? e : last[1];
|
||||
else merged.push([s, e]);
|
||||
}
|
||||
|
||||
const free = [];
|
||||
let cur = rs;
|
||||
for (const [s, e] of merged) {
|
||||
const bs = s < rs ? rs : s;
|
||||
const be = e > re ? re : e;
|
||||
if (be <= rs || bs >= re) continue;
|
||||
if (bs > cur) free.push([cur, bs]);
|
||||
if (be > cur) cur = be;
|
||||
}
|
||||
if (cur < re) free.push([cur, re]);
|
||||
|
||||
const [sh, sm] = workHours.start.split(':').map(Number);
|
||||
const [eh, em] = workHours.end.split(':').map(Number);
|
||||
const windows = [];
|
||||
for (let d = rs.startOf('day'); d < re; d = d.plus({ days: 1 })) {
|
||||
const ws = d.plus({ hours: sh, minutes: sm });
|
||||
let we = d.plus({ hours: eh, minutes: em });
|
||||
if (we <= ws) we = we.plus({ days: 1 });
|
||||
const s = ws > rs ? ws : rs;
|
||||
const e = we < re ? we : re;
|
||||
if (s < e) windows.push([s, e]);
|
||||
}
|
||||
|
||||
const dur = { minutes: durationMinutes };
|
||||
const iso = (d) => d.toISO({ suppressMilliseconds: true });
|
||||
const slots = [];
|
||||
for (const [fs, fe] of free) {
|
||||
for (const [ws, we] of windows) {
|
||||
if (we <= fs) continue;
|
||||
if (ws >= fe) break;
|
||||
let t = fs > ws ? fs : ws;
|
||||
const end = fe < we ? fe : we;
|
||||
while (true) {
|
||||
const n = t.plus(dur);
|
||||
if (n > end) break;
|
||||
slots.push({ start: iso(t), end: iso(n) });
|
||||
t = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 113.083s
|
||||
// Result: PASS
|
||||
194
tests/7_scheduler/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
194
tests/7_scheduler/outputs/openai_gpt-5.6-luna EFF_high.js
Normal file
@@ -0,0 +1,194 @@
|
||||
async function findAvailableSlots(calendarA, calendarB, constraints) {
|
||||
const { parseISO, isValid } = await import(
|
||||
"https://cdn.jsdelivr.net/npm/date-fns@4.1.0/+esm"
|
||||
);
|
||||
|
||||
const minute = 60000;
|
||||
const day = 1440 * minute;
|
||||
|
||||
const instant = (value, label) => {
|
||||
if (typeof value !== "string") {
|
||||
throw new TypeError(`${label} must be an ISO date string`);
|
||||
}
|
||||
|
||||
const dateOnly = /^\d{4}-\d{2}-\d{2}$/.test(value);
|
||||
const hasZone = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(value);
|
||||
const normalized = dateOnly
|
||||
? `${value}T00:00:00Z`
|
||||
: hasZone
|
||||
? value
|
||||
: `${value}Z`;
|
||||
const date = parseISO(normalized);
|
||||
|
||||
if (!isValid(date)) {
|
||||
throw new RangeError(`${label} is not a valid ISO date string`);
|
||||
}
|
||||
|
||||
return date.getTime();
|
||||
};
|
||||
|
||||
const clock = (value, label) => {
|
||||
if (value === "24:00") return day;
|
||||
|
||||
const match = typeof value === "string"
|
||||
? /^(\d{2}):(\d{2})$/.exec(value)
|
||||
: null;
|
||||
|
||||
if (
|
||||
!match ||
|
||||
Number(match[1]) > 23 ||
|
||||
Number(match[2]) > 59
|
||||
) {
|
||||
throw new RangeError(`${label} must use HH:mm format`);
|
||||
}
|
||||
|
||||
return (Number(match[1]) * 60 + Number(match[2])) * minute;
|
||||
};
|
||||
|
||||
if (!constraints || typeof constraints !== "object") {
|
||||
throw new TypeError("constraints must be an object");
|
||||
}
|
||||
|
||||
const { durationMinutes, searchRange, workHours } = constraints;
|
||||
|
||||
if (!Number.isFinite(durationMinutes) || durationMinutes <= 0) {
|
||||
throw new RangeError("durationMinutes must be a positive number");
|
||||
}
|
||||
|
||||
const duration = durationMinutes * minute;
|
||||
|
||||
if (!Number.isSafeInteger(duration)) {
|
||||
throw new RangeError("durationMinutes must resolve to whole milliseconds");
|
||||
}
|
||||
|
||||
if (!searchRange || typeof searchRange !== "object") {
|
||||
throw new TypeError("searchRange must be an object");
|
||||
}
|
||||
|
||||
if (!workHours || typeof workHours !== "object") {
|
||||
throw new TypeError("workHours must be an object");
|
||||
}
|
||||
|
||||
const range = {
|
||||
start: instant(searchRange.start, "searchRange.start"),
|
||||
end: instant(searchRange.end, "searchRange.end")
|
||||
};
|
||||
|
||||
if (range.start >= range.end) {
|
||||
throw new RangeError("searchRange.start must be before searchRange.end");
|
||||
}
|
||||
|
||||
const workStart = clock(workHours.start, "workHours.start");
|
||||
const workEnd = clock(workHours.end, "workHours.end");
|
||||
|
||||
if (workStart >= workEnd) {
|
||||
throw new RangeError("workHours.start must be before workHours.end");
|
||||
}
|
||||
|
||||
const readCalendar = (calendar, label) => {
|
||||
if (!Array.isArray(calendar)) {
|
||||
throw new TypeError(`${label} must be an array`);
|
||||
}
|
||||
|
||||
return calendar
|
||||
.map((slot, index) => {
|
||||
if (!slot || typeof slot !== "object") {
|
||||
throw new TypeError(`${label}[${index}] must be an object`);
|
||||
}
|
||||
|
||||
const start = instant(slot.start, `${label}[${index}].start`);
|
||||
const end = instant(slot.end, `${label}[${index}].end`);
|
||||
|
||||
if (start >= end) {
|
||||
throw new RangeError(
|
||||
`${label}[${index}].start must be before ${label}[${index}].end`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
start: Math.max(start, range.start),
|
||||
end: Math.min(end, range.end)
|
||||
};
|
||||
})
|
||||
.filter(slot => slot.start < slot.end);
|
||||
};
|
||||
|
||||
const busy = [
|
||||
...readCalendar(calendarA, "calendarA"),
|
||||
...readCalendar(calendarB, "calendarB")
|
||||
].sort((a, b) => a.start - b.start || a.end - b.end);
|
||||
|
||||
const merged = [];
|
||||
|
||||
for (const slot of busy) {
|
||||
const last = merged[merged.length - 1];
|
||||
|
||||
if (!last || slot.start > last.end) {
|
||||
merged.push({ ...slot });
|
||||
} else {
|
||||
last.end = Math.max(last.end, slot.end);
|
||||
}
|
||||
}
|
||||
|
||||
const result = [];
|
||||
const addSlots = (start, end) => {
|
||||
for (
|
||||
let cursor = start;
|
||||
cursor + duration <= end;
|
||||
cursor += duration
|
||||
) {
|
||||
result.push({
|
||||
start: new Date(cursor).toISOString(),
|
||||
end: new Date(cursor + duration).toISOString()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const firstDay = new Date(range.start);
|
||||
firstDay.setUTCHours(0, 0, 0, 0);
|
||||
|
||||
let busyIndex = 0;
|
||||
|
||||
for (
|
||||
let dayStart = firstDay.getTime();
|
||||
dayStart < range.end;
|
||||
dayStart += day
|
||||
) {
|
||||
const windowStart = Math.max(range.start, dayStart + workStart);
|
||||
const windowEnd = Math.min(range.end, dayStart + workEnd);
|
||||
|
||||
if (windowStart >= windowEnd) continue;
|
||||
|
||||
while (
|
||||
busyIndex < merged.length &&
|
||||
merged[busyIndex].end <= windowStart
|
||||
) {
|
||||
busyIndex++;
|
||||
}
|
||||
|
||||
let cursor = windowStart;
|
||||
|
||||
for (
|
||||
let index = busyIndex;
|
||||
index < merged.length && merged[index].start < windowEnd;
|
||||
index++
|
||||
) {
|
||||
const blocked = merged[index];
|
||||
|
||||
if (blocked.start > cursor) {
|
||||
addSlots(cursor, Math.min(blocked.start, windowEnd));
|
||||
}
|
||||
|
||||
cursor = Math.max(cursor, blocked.end);
|
||||
|
||||
if (cursor >= windowEnd) break;
|
||||
}
|
||||
|
||||
addSlots(cursor, windowEnd);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 80.821s
|
||||
// Result: PASS
|
||||
50
tests/7_scheduler/outputs/x-ai_grok-4.5.js
Normal file
50
tests/7_scheduler/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,50 @@
|
||||
async function findAvailableSlots(c1,c2,ct){
|
||||
const{DateTime:D,Interval:I}=await import('https://cdn.jsdelivr.net/npm/luxon@3.4.4/+esm');
|
||||
const p=s=>D.fromISO(s,{zone:'utc'});
|
||||
const{durationMinutes:dm,searchRange:{start:rss,end:ree},workHours:{start:wss,end:wee}}=ct;
|
||||
const rS=p(rss),rE=p(ree);
|
||||
const[wh,wm]=wss.split(':').map(Number),[eh,em]=wee.split(':').map(Number);
|
||||
let bs=[];
|
||||
for(const c of[c1,c2])for(const s of c)bs.push(I.fromDateTimes(p(s.start),p(s.end)));
|
||||
bs.sort((a,b)=>a.start-b.start);
|
||||
const mg=[];
|
||||
for(const iv of bs){
|
||||
if(!mg.length||mg[mg.length-1].end<iv.start)mg.push(iv);
|
||||
else{const l=mg[mg.length-1];mg[mg.length-1]=I.fromDateTimes(l.start,D.max(l.end,iv.end));}
|
||||
}
|
||||
const fs=[];
|
||||
let cur=rS;
|
||||
for(const b of mg){
|
||||
if(b.end<=cur)continue;
|
||||
if(b.start>cur){const fe=D.min(b.start,rE);if(fe>cur)fs.push(I.fromDateTimes(cur,fe));}
|
||||
cur=D.max(cur,b.end);if(cur>=rE)break;
|
||||
}
|
||||
if(cur<rE)fs.push(I.fromDateTimes(cur,rE));
|
||||
const ws=[];
|
||||
let dy=rS.startOf('day');
|
||||
const ld=rE.startOf('day');
|
||||
while(dy<=ld){
|
||||
const wS=dy.set({hour:wh,minute:wm,second:0,millisecond:0});
|
||||
const wE=dy.set({hour:eh,minute:em,second:0,millisecond:0});
|
||||
const wi=I.fromDateTimes(wS,wE).intersection(I.fromDateTimes(rS,rE));
|
||||
if(wi&&!wi.isEmpty())ws.push(wi);
|
||||
dy=dy.plus({days:1});
|
||||
}
|
||||
const av=[];
|
||||
for(const f of fs)for(const w of ws){const i=f.intersection(w);if(i&&!i.isEmpty())av.push(i);}
|
||||
av.sort((a,b)=>a.start-b.start);
|
||||
const sl=[];
|
||||
for(const a of av){
|
||||
let st=a.start;
|
||||
for(;;){
|
||||
const en=st.plus({minutes:dm});
|
||||
if(en>a.end)break;
|
||||
sl.push({start:st.toISO(),end:en.toISO()});
|
||||
st=en;
|
||||
}
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 44.730s
|
||||
// Result: PASS
|
||||
62
tests/7_scheduler/outputs/z-ai_glm-5.2.js
Normal file
62
tests/7_scheduler/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,62 @@
|
||||
async function findAvailableSlots(cal1, cal2, c) {
|
||||
const { DateTime } = await import('https://esm.sh/luxon@3');
|
||||
const s = DateTime.fromISO(c.searchRange.start, { zone: 'utc' });
|
||||
const e = DateTime.fromISO(c.searchRange.end, { zone: 'utc' });
|
||||
|
||||
let work = [];
|
||||
let cur = s;
|
||||
const [wSH, wSM] = c.workHours.start.split(':').map(Number);
|
||||
const [wEH, wEM] = c.workHours.end.split(':').map(Number);
|
||||
|
||||
while (cur < e) {
|
||||
const ws = cur.set({ hour: wSH, minute: wSM, second: 0, millisecond: 0 });
|
||||
const we = cur.set({ hour: wEH, minute: wEM, second: 0, millisecond: 0 });
|
||||
if (we > ws) work.push({ start: ws, end: we });
|
||||
cur = cur.plus({ days: 1 }).set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
||||
}
|
||||
|
||||
const busy = [...cal1, ...cal2]
|
||||
.map(b => ({
|
||||
start: DateTime.fromISO(b.start, { zone: 'utc' }),
|
||||
end: DateTime.fromISO(b.end, { zone: 'utc' })
|
||||
}))
|
||||
.filter(b => b.start < b.end)
|
||||
.sort((a, b) => a.start - b.start);
|
||||
|
||||
let merged = [];
|
||||
for (const b of busy) {
|
||||
const last = merged[merged.length - 1];
|
||||
if (merged.length && b.start <= last.end) last.end = DateTime.max(last.end, b.end);
|
||||
else merged.push({ ...b });
|
||||
}
|
||||
|
||||
let free = [];
|
||||
for (const w of work) {
|
||||
let cs = w.start;
|
||||
for (const b of merged) {
|
||||
if (b.end <= cs) continue;
|
||||
if (b.start >= w.end) break;
|
||||
if (b.start > cs) free.push({ start: cs, end: b.start });
|
||||
cs = DateTime.max(cs, b.end);
|
||||
if (cs >= w.end) break;
|
||||
}
|
||||
if (cs < w.end) free.push({ start: cs, end: w.end });
|
||||
}
|
||||
|
||||
const d = c.durationMinutes;
|
||||
const slots = [];
|
||||
for (const f of free) {
|
||||
let ss = f.start;
|
||||
while (ss.plus({ minutes: d }) <= f.end) {
|
||||
slots.push({
|
||||
start: ss.toISO({ suppressMilliseconds: true }),
|
||||
end: ss.plus({ minutes: d }).toISO({ suppressMilliseconds: true })
|
||||
});
|
||||
ss = ss.plus({ minutes: d });
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 59.287s
|
||||
// Result: PASS
|
||||
30
tests/8_json_validator/outputs/anthropic_claude-fable-5.js
Normal file
30
tests/8_json_validator/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const validateJSON = (() => {
|
||||
let ajv;
|
||||
|
||||
const load = async () => {
|
||||
if (ajv) return ajv;
|
||||
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/ajv@8/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/ajv-formats@3/+esm')
|
||||
]);
|
||||
ajv = new Ajv({ allErrors: true, strict: false });
|
||||
addFormats(ajv);
|
||||
return ajv;
|
||||
};
|
||||
|
||||
const format = e =>
|
||||
`${e.instancePath || '/'} ${e.message}${e.params?.allowedValues ? `: ${e.params.allowedValues.join(', ')}` : ''}`;
|
||||
|
||||
return async (data, schema) => {
|
||||
try {
|
||||
const validator = (await load()).compile(schema);
|
||||
const valid = validator(data);
|
||||
return { valid, errors: valid ? [] : validator.errors.map(format) };
|
||||
} catch (err) {
|
||||
return { valid: false, errors: [`Schema error: ${err.message}`] };
|
||||
}
|
||||
};
|
||||
})();
|
||||
export default validateJSON;
|
||||
// Generation time: 13.342s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,23 @@
|
||||
const validateJSON = async (data, schema) => {
|
||||
try {
|
||||
const { default: Ajv } = await import("https://esm.sh/ajv@8");
|
||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(data);
|
||||
return {
|
||||
valid,
|
||||
errors: valid
|
||||
? []
|
||||
: (validate.errors || []).map(
|
||||
(e) => `${e.instancePath || "/"} ${e.message}`.trim()
|
||||
),
|
||||
};
|
||||
} catch (err) {
|
||||
return { valid: false, errors: [err.message] };
|
||||
}
|
||||
};
|
||||
|
||||
export { validateJSON };
|
||||
export default validateJSON;
|
||||
// Generation time: 5.406s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,22 @@
|
||||
async function validateJSON(data, schema) {
|
||||
const { default: Ajv } = await import('https://cdn.jsdelivr.net/npm/ajv@8/+esm');
|
||||
|
||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(data);
|
||||
|
||||
const errors = valid
|
||||
? []
|
||||
: validate.errors.map(({ instancePath, message, params }) => {
|
||||
const path = instancePath || '/';
|
||||
const extra = params?.missingProperty
|
||||
? ` (missing: ${params.missingProperty})`
|
||||
: '';
|
||||
return `${path}: ${message}${extra}`;
|
||||
});
|
||||
|
||||
return { valid, errors };
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 6.311s
|
||||
// Result: PASS
|
||||
21
tests/8_json_validator/outputs/moonshotai_kimi-k2.7-code.js
Normal file
21
tests/8_json_validator/outputs/moonshotai_kimi-k2.7-code.js
Normal file
@@ -0,0 +1,21 @@
|
||||
let ajv;
|
||||
|
||||
const validateJSON = async (data, schema) => {
|
||||
try {
|
||||
if (!ajv) {
|
||||
const Ajv = (await import('https://esm.sh/ajv@8.17.1')).default;
|
||||
ajv = new Ajv({ allErrors: true, strict: false });
|
||||
}
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(data);
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : validate.errors.map(e => `${e.instancePath || '/'}: ${e.message}`)
|
||||
};
|
||||
} catch (err) {
|
||||
return { valid: false, errors: [err.message] };
|
||||
}
|
||||
};
|
||||
export default validateJSON;
|
||||
// Generation time: 45.178s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,35 @@
|
||||
let ajvPromise;
|
||||
|
||||
const loadAjv = async () => {
|
||||
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
|
||||
import("https://esm.sh/ajv@8.17.1"),
|
||||
import("https://esm.sh/ajv-formats@3.0.1"),
|
||||
]);
|
||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||
addFormats(ajv);
|
||||
return ajv;
|
||||
};
|
||||
|
||||
const getAjv = () =>
|
||||
(ajvPromise ??= loadAjv().catch((error) => {
|
||||
ajvPromise = undefined;
|
||||
throw error;
|
||||
}));
|
||||
|
||||
async function validateJSON(data, schema) {
|
||||
try {
|
||||
const validate = (await getAjv()).compile(schema);
|
||||
const valid = validate(data);
|
||||
return {
|
||||
valid,
|
||||
errors: (validate.errors ?? []).map(
|
||||
({ instancePath, message }) => `${instancePath || "(root)"} ${message}`,
|
||||
),
|
||||
};
|
||||
} catch (error) {
|
||||
return { valid: false, errors: [error?.message ?? String(error)] };
|
||||
}
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 91.986s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,42 @@
|
||||
let ajvPromise;
|
||||
|
||||
const getAjv = () => {
|
||||
if (ajvPromise) return ajvPromise;
|
||||
|
||||
ajvPromise = import("https://esm.sh/ajv@8.17.1")
|
||||
.then(({ default: Ajv }) => Ajv)
|
||||
.catch(error => {
|
||||
ajvPromise = null;
|
||||
throw error;
|
||||
});
|
||||
|
||||
return ajvPromise;
|
||||
};
|
||||
|
||||
const formatError = ({ instancePath, message }) =>
|
||||
`${instancePath || "$"} ${message}`;
|
||||
|
||||
async function validateJSON(value, schema) {
|
||||
try {
|
||||
const Ajv = await getAjv();
|
||||
const validate = new Ajv({
|
||||
allErrors: true,
|
||||
strict: false
|
||||
}).compile(schema);
|
||||
|
||||
const valid = validate(value);
|
||||
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : (validate.errors || []).map(formatError)
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
valid: false,
|
||||
errors: [error instanceof Error ? error.message : String(error)]
|
||||
};
|
||||
}
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 15.651s
|
||||
// Result: PASS
|
||||
10
tests/8_json_validator/outputs/x-ai_grok-4.5.js
Normal file
10
tests/8_json_validator/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,10 @@
|
||||
async function validateJSON(data,schema){
|
||||
const{default:Ajv}=await import("https://esm.sh/ajv@8");
|
||||
const ajv=new Ajv({allErrors:true});
|
||||
const validate=ajv.compile(schema);
|
||||
const valid=validate(data);
|
||||
return{valid,errors:valid?[]:validate.errors.map(e=>(e.instancePath+" "+e.message).trim())}
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 13.050s
|
||||
// Result: PASS
|
||||
9
tests/8_json_validator/outputs/z-ai_glm-5.2.js
Normal file
9
tests/8_json_validator/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,9 @@
|
||||
async function validateJSON(data, schema) {
|
||||
const { default: Ajv } = await import('https://esm.sh/ajv@8');
|
||||
const ajv = new Ajv({ allErrors: true });
|
||||
const valid = ajv.validate(schema, data);
|
||||
return { valid, errors: valid ? [] : ajv.errors.map(e => e.message) };
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 31.005s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,21 @@
|
||||
async function createStreamVisualizer(src, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const data = [];
|
||||
let ema;
|
||||
for await (const { timestamp, value } of src) {
|
||||
ema = ema === undefined ? value : alpha * value + (1 - alpha) * ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
const x = d3.scaleLinear()
|
||||
.domain(data.length ? [data[0].timestamp, data[data.length - 1].timestamp] : [0, 1])
|
||||
.range([0, width]);
|
||||
const y = d3.scaleLinear().domain(yDomain).range([height, 0]);
|
||||
const path = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data) ?? '';
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 6.412s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,22 @@
|
||||
async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
const { scaleLinear, line } = await import("https://cdn.skypack.dev/d3");
|
||||
const data = [];
|
||||
let prevEma;
|
||||
for await (const value of asyncIterable) {
|
||||
prevEma = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
|
||||
data.push({ timestamp: Date.now(), value, ema: prevEma });
|
||||
if (data.length > maxPoints) data.splice(0, data.length - maxPoints);
|
||||
}
|
||||
const x = scaleLinear()
|
||||
.domain([data[0]?.timestamp ?? 0, data.at(-1)?.timestamp ?? 1])
|
||||
.range([0, width]);
|
||||
const y = scaleLinear().domain(yDomain).range([height, 0]);
|
||||
const path = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data) ?? "";
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 4.318s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,32 @@
|
||||
async function createStreamVisualizer(asyncIterable, options) {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
|
||||
const data = [];
|
||||
let prevEma;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
prevEma = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
|
||||
data.push({ timestamp, value, ema: prevEma });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: '' };
|
||||
|
||||
const x = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const y = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const line = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema));
|
||||
|
||||
return { data, path: line(data) };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 5.834s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,34 @@
|
||||
const createStreamVisualizer = async (stream, options) => {
|
||||
const { maxPoints, alpha, width, height, yDomain } = options;
|
||||
const mod = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const { scaleLinear, line } = mod.default || mod;
|
||||
|
||||
const data = [];
|
||||
let prev;
|
||||
|
||||
for await (const { timestamp, value } of stream) {
|
||||
const ema = prev === undefined ? value : alpha * value + (1 - alpha) * prev;
|
||||
prev = ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: '' };
|
||||
|
||||
const x = scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const y = scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const path = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data) || '';
|
||||
|
||||
return { data, path };
|
||||
};
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 48.885s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,27 @@
|
||||
async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const { scaleLinear, line } = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
|
||||
const data = [];
|
||||
let ema;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
ema = data.length ? alpha * value + (1 - alpha) * ema : value;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: "" };
|
||||
|
||||
const x = scaleLinear()
|
||||
.domain([data[0].timestamp, data.at(-1).timestamp])
|
||||
.range([0, width]);
|
||||
const y = scaleLinear().domain(yDomain).range([height, 0]);
|
||||
|
||||
const path = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 48.702s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,97 @@
|
||||
async function createStreamVisualizer(asyncIterable, options = {}) {
|
||||
const {
|
||||
maxPoints = 1000,
|
||||
alpha = 0.2,
|
||||
width = 800,
|
||||
height = 400,
|
||||
yDomain = [0, 1]
|
||||
} = options;
|
||||
|
||||
if (
|
||||
!asyncIterable ||
|
||||
typeof asyncIterable[Symbol.asyncIterator] !== "function"
|
||||
) {
|
||||
throw new TypeError("asyncIterable must be an async iterable");
|
||||
}
|
||||
|
||||
if (!Number.isSafeInteger(maxPoints) || maxPoints < 1) {
|
||||
throw new RangeError("maxPoints must be a positive integer");
|
||||
}
|
||||
|
||||
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) {
|
||||
throw new RangeError("alpha must be between 0 and 1");
|
||||
}
|
||||
|
||||
if (
|
||||
!Number.isFinite(width) ||
|
||||
width < 0 ||
|
||||
!Number.isFinite(height) ||
|
||||
height < 0
|
||||
) {
|
||||
throw new RangeError("width and height must be non-negative numbers");
|
||||
}
|
||||
|
||||
const [yMin, yMax] = Array.isArray(yDomain) ? yDomain : [];
|
||||
|
||||
if (
|
||||
!Number.isFinite(yMin) ||
|
||||
!Number.isFinite(yMax) ||
|
||||
yMin >= yMax
|
||||
) {
|
||||
throw new RangeError("yDomain must contain two ascending finite numbers");
|
||||
}
|
||||
|
||||
const { scaleLinear, line } = await import(
|
||||
"https://cdn.jsdelivr.net/npm/d3@7/+esm"
|
||||
);
|
||||
|
||||
const data = [];
|
||||
let ema;
|
||||
|
||||
for await (const point of asyncIterable) {
|
||||
if (!point || typeof point !== "object") {
|
||||
throw new TypeError("Each stream item must be an object");
|
||||
}
|
||||
|
||||
const { timestamp, value } = point;
|
||||
|
||||
if (!Number.isFinite(Number(timestamp))) {
|
||||
throw new TypeError("Each timestamp must be numeric or date-like");
|
||||
}
|
||||
|
||||
if (!Number.isFinite(value)) {
|
||||
throw new TypeError("Each value must be a finite number");
|
||||
}
|
||||
|
||||
ema = ema === undefined
|
||||
? value
|
||||
: alpha * value + (1 - alpha) * ema;
|
||||
|
||||
data.push({ timestamp, value, ema });
|
||||
|
||||
if (data.length > maxPoints) {
|
||||
data.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.length) {
|
||||
return { data, path: "" };
|
||||
}
|
||||
|
||||
const x = scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const y = scaleLinear()
|
||||
.domain([yMin, yMax])
|
||||
.range([height, 0]);
|
||||
|
||||
const path = line()
|
||||
.x(point => x(point.timestamp))
|
||||
.y(point => y(point.ema))(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 27.431s
|
||||
// Result: PASS
|
||||
19
tests/9_stream_visualizer/outputs/x-ai_grok-4.5.js
Normal file
19
tests/9_stream_visualizer/outputs/x-ai_grok-4.5.js
Normal file
@@ -0,0 +1,19 @@
|
||||
async function createStreamVisualizer(asyncIterable,{maxPoints,alpha,width,height,yDomain}){
|
||||
const d3=await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const data=[];
|
||||
let p;
|
||||
for await(const{timestamp:t,value:v}of asyncIterable){
|
||||
const e=p==null?v:alpha*v+(1-alpha)*p;
|
||||
p=e;
|
||||
data.push({timestamp:t,value:v,ema:e});
|
||||
if(data.length>maxPoints)data.shift();
|
||||
}
|
||||
if(!data.length)return{data,path:''};
|
||||
const x=d3.scaleLinear().domain([data[0].timestamp,data[data.length-1].timestamp]).range([0,width]);
|
||||
const y=d3.scaleLinear().domain(yDomain).range([height,0]);
|
||||
const path=d3.line().x(d=>x(d.timestamp)).y(d=>y(d.ema))(data);
|
||||
return{data,path};
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 7.991s
|
||||
// Result: PASS
|
||||
26
tests/9_stream_visualizer/outputs/z-ai_glm-5.2.js
Normal file
26
tests/9_stream_visualizer/outputs/z-ai_glm-5.2.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async function createStreamVisualizer(asyncIterable, { maxPoints: max, alpha, width: w, height: h, yDomain }) {
|
||||
const d3 = await import('d3');
|
||||
const data = [];
|
||||
let prev;
|
||||
|
||||
for await (const { timestamp: t, value: v } of asyncIterable) {
|
||||
const ema = prev === undefined ? v : alpha * v + (1 - alpha) * prev;
|
||||
prev = ema;
|
||||
data.push({ timestamp: t, value: v, ema });
|
||||
if (data.length > max) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: null };
|
||||
|
||||
const x = d3.scaleLinear([data[0].timestamp, data[data.length - 1].timestamp], [0, w]);
|
||||
const y = d3.scaleLinear(yDomain, [h, 0]);
|
||||
|
||||
const path = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data);
|
||||
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 17.130s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user