mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-07-18 13:55:46 +00:00
Compare commits
10 Commits
48dfa6cd44
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6f8b6ad90 | ||
|
|
b552fc6f93 | ||
|
|
d5e4ee5f44 | ||
|
|
6c0f3f8e8c | ||
|
|
3531ba9742 | ||
| d881df7814 | |||
|
|
302f129522 | ||
| c2950d20e7 | |||
|
|
0d119317eb | ||
| 866e5c2bbb |
9
README
9
README
@@ -9,6 +9,9 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
|
|||||||
The following models are included in the benchmark run.
|
The following models are included in the benchmark run.
|
||||||
|
|
||||||
<!-- MODELS_START -->
|
<!-- 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
|
anthropic/claude-sonnet-5 EFF:high
|
||||||
z-ai/glm-5.2
|
z-ai/glm-5.2
|
||||||
moonshotai/kimi-k2.7-code
|
moonshotai/kimi-k2.7-code
|
||||||
@@ -17,15 +20,9 @@ anthropic/claude-opus-4.8 EFF:medium
|
|||||||
google/gemini-3.5-flash
|
google/gemini-3.5-flash
|
||||||
google/gemini-3.1-flash-lite
|
google/gemini-3.1-flash-lite
|
||||||
openai/gpt-5.5 EFF:high
|
openai/gpt-5.5 EFF:high
|
||||||
deepseek/deepseek-v4-pro
|
|
||||||
moonshotai/kimi-k2.6
|
moonshotai/kimi-k2.6
|
||||||
anthropic/claude-opus-4.7 EFF:medium
|
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
|
google/gemini-3.1-pro-preview
|
||||||
anthropic/claude-opus-4.6
|
|
||||||
moonshotai/kimi-k2.5
|
|
||||||
google/gemini-3-flash-preview TEMP:0.35
|
google/gemini-3-flash-preview TEMP:0.35
|
||||||
deepseek/deepseek-v3.2
|
deepseek/deepseek-v3.2
|
||||||
<!-- MODELS_END -->
|
<!-- MODELS_END -->
|
||||||
|
|||||||
@@ -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
|
||||||
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
|
||||||
@@ -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
|
||||||
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
|
||||||
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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user