Skip to content

Commit 9c4420d

Browse files
authored
Fix the bug that LeetCode cannot test (#27)
1 parent f5c6f9a commit 9c4420d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/commands/test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ function runTest(argv) {
8686

8787
results[0].your_input = problem.testcase;
8888
results[0].output = results[0].answer;
89-
results[1].expected = results[1].answer;
89+
// LeetCode-CN returns the actual and expected answer into two separate responses
90+
if (results[1]) {
91+
results[0].expected_answer = results[1].answer;
92+
}
9093
results[0].stdout = results[0].stdout.slice(1, -1).replace(/\\n/g, '\n');
9194
printResult(results[0], null, 'your_input');
9295
printResult(results[0], results[0].runtime, 'output');
93-
printResult(results[1], results[1].runtime, 'expected');
96+
printResult(results[0], null, 'expected_answer');
9497
printResult(results[0], null, 'stdout');
9598
});
9699
});

lib/plugins/leetcode.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ function formatResult(result) {
266266
}
267267
x.stdout = util.inspect(output);
268268
x.answer = result.code_answer;
269+
// LeetCode use 'expected_code_answer' to store the expected answer
270+
x.expected_answer = result.expected_code_answer;
269271
} else {
270272
// It's submitting
271273
x.answer = result.code_output;
@@ -291,8 +293,12 @@ plugin.testProblem = function(problem, cb) {
291293

292294
const tasks = [
293295
{type: 'Actual', id: task.interpret_id},
294-
{type: 'Expected', id: task.interpret_expected_id}
295296
];
297+
298+
// Used by LeetCode-CN
299+
if (task.interpret_expected_id) {
300+
tasks.push({type: 'Expected', id: task.interpret_expected_id});
301+
}
296302
const q = new Queue(tasks, {opts: opts, results: []}, verifyResult);
297303
q.run(null, function(e, ctx) {
298304
return cb(e, ctx.results);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy