MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / parseDiffMsg

Function parseDiffMsg

packages/hydrojudge/src/checkers.ts:26–58  ·  view source on GitHub ↗
(msg: string)

Source from the content-addressed store, hash-verified

24}>;
25
26function parseDiffMsg(msg: string) {
27 msg = msg.trim();
28 try {
29 if (!msg) return '';
30 if (!msg.startsWith('L=')) throw new Error();
31 const [meta, u, t] = msg.split('\n');
32 const lline = meta.split('L=')[1];
33 if (lline?.trim() === 'EOF') {
34 const next = u.split('EOF on ')[1].split(' ')[0];
35 if (next === 'usrout.processed') return 'Standard answer longer than user output.';
36 if (next === 'answer.processed') return 'User output longer than standard answer.';
37 return `Unable to parse: ${u}`;
38 }
39 const lineNum = +lline;
40 // Split by token
41 const usr = u.trim().split(' ');
42 const std = t.trim().split(' ');
43 if (std.every((x) => !Number.isNaN(+x))) {
44 // Number mode, report length not match
45 if (usr.length > std.length) return 'User output longer than standard answer.';
46 if (usr.length < std.length) return 'Standard answer longer than user output.';
47 }
48 for (let i = 0; i < usr.length; i++) {
49 if (usr[i] === std[i]) continue;
50 const usrString = usr[i].length > 20 ? `${usr[i].substring(0, 16)}...` : usr[i];
51 const stdString = std[i].length > 20 ? `${std[i].substring(0, 16)}...` : std[i];
52 return { message: 'On line {0}: Read {1}, expect {2}.', params: [lineNum, usrString, stdString] };
53 }
54 throw new Error();
55 } catch (e) {
56 return msg.substring(0, msg.length - 1 <= 30 ? msg.length - 1 : 30);
57 }
58}
59
60const compareSh = `#!/bin/bash
61set -e

Callers 1

getDefaultCheckerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected