Team Ai
Apppublic

Ratankumar10/code-execution-engine

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
quick-test.js88 linesDownload Raw Back to test
1// ╔══════════════════════════════════════════════════════════════════╗2// ║  Quick Test — 1 Problem, 5 Test Cases                         ║3// ║  Run: node test/quick-test.js                                 ║4// ╚══════════════════════════════════════════════════════════════════╝5 6const http = require("http");7const BASE_URL = process.argv[2] || "http://140.245.240.6:3000";8 9function request(method, path, body) {10  return new Promise((resolve, reject) => {11    const url = new URL(path, BASE_URL);12    const options = {13      hostname: url.hostname,14      port: url.port,15      path: url.pathname,16      method,17      headers: { "Content-Type": "application/json" },18    };19    const req = http.request(options, (res) => {20      let data = "";21      res.on("data", (chunk) => (data += chunk));22      res.on("end", () => {23        try {24          resolve({ status: res.statusCode, body: JSON.parse(data) });25        } catch {26          resolve({ status: res.statusCode, body: data });27        }28      });29    });30    req.on("error", reject);31    if (body) req.write(JSON.stringify(body));32    req.end();33  });34}35 36async function run() {37  console.log("\n⚡ Quick Test — Single Problem\n");38 39  const start = Date.now();40 41  const res = await request("POST", "/api/judge", {42    language: "cpp",43    code: [44      "#include <bits/stdc++.h>",45      "using namespace std;",46      "int main() {",47      "    int a, b; cin >> a >> b;",48      "    cout << a + b << endl;",49      "    return 0;",50      "}",51    ].join("\n"),52    testCases: [53      { input: "1 2\n", expectedOutput: "3" },54      { input: "0 0\n", expectedOutput: "0" },55      { input: "-5 5\n", expectedOutput: "0" },56      { input: "100 200\n", expectedOutput: "300" },57      { input: "999 1\n", expectedOutput: "1000" },58    ],59    timeLimit: 2,60    memoryLimit: 256,61  });62 63  const wallTime = Date.now() - start;64  const d = res.body.data;65 66  console.log(`  Verdict:      ${d.overallVerdict}`);67  console.log(`  Passed:       ${d.passed}/${d.totalTestCases}`);68  console.log(`  Total Time:   ${d.totalTime}ms (execution only)`);69  console.log(70    `  Max Memory:   ${d.maxMemory}KB (${(d.maxMemory / 1024).toFixed(1)}MB)`,71  );72  console.log(`  Wall Time:    ${wallTime}ms (includes network + Docker)`);73  console.log("");74 75  d.results.forEach((r) => {76    const icon = r.verdict === "AC" ? "✅" : "❌";77    console.log(78      `  ${icon} TC#${r.testCase}  ${r.verdict.padEnd(4)} ${r.executionTime}ms  ${r.memoryUsed}KB`,79    );80  });81 82  console.log(83    `\n  📊 Avg per test case: ${(wallTime / d.totalTestCases).toFixed(0)}ms wall, ${(d.totalTime / d.totalTestCases).toFixed(0)}ms execution\n`,84  );85}86 87run().catch((err) => console.error("❌", err.message));88