From 97dbcfc962b530e5a791b82afc5e2b724c580ae8 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Sat, 5 Oct 2019 15:31:50 +0800 Subject: [PATCH] Fix the bug that LeetCode cannot test --- lib/commands/test.js | 7 +++++-- lib/plugins/leetcode.js | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/commands/test.js b/lib/commands/test.js index cd1ad4d9..609a18fd 100644 --- a/lib/commands/test.js +++ b/lib/commands/test.js @@ -86,11 +86,14 @@ function runTest(argv) { results[0].your_input = problem.testcase; results[0].output = results[0].answer; - results[1].expected = results[1].answer; + // LeetCode-CN returns the actual and expected answer into two separate responses + if (results[1]) { + results[0].expected_answer = results[1].answer; + } results[0].stdout = results[0].stdout.slice(1, -1).replace(/\\n/g, '\n'); printResult(results[0], null, 'your_input'); printResult(results[0], results[0].runtime, 'output'); - printResult(results[1], results[1].runtime, 'expected'); + printResult(results[0], null, 'expected_answer'); printResult(results[0], null, 'stdout'); }); }); diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 4b90412d..bc418f6f 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -266,6 +266,8 @@ function formatResult(result) { } x.stdout = util.inspect(output); x.answer = result.code_answer; + // LeetCode use 'expected_code_answer' to store the expected answer + x.expected_answer = result.expected_code_answer; } else { // It's submitting x.answer = result.code_output; @@ -291,8 +293,12 @@ plugin.testProblem = function(problem, cb) { const tasks = [ {type: 'Actual', id: task.interpret_id}, - {type: 'Expected', id: task.interpret_expected_id} ]; + + // Used by LeetCode-CN + if (task.interpret_expected_id) { + tasks.push({type: 'Expected', id: task.interpret_expected_id}); + } const q = new Queue(tasks, {opts: opts, results: []}, verifyResult); q.run(null, function(e, ctx) { return cb(e, ctx.results); 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