Skip to content

Commit e53812e

Browse files
committed
Use the leetcode assessment of test correctness
The code currently decides whether or not the answer is the expected answer by comparing the `code_answer` and `expected_code_answer` output blocks in the response to see if they're the same. This can be an issue for problems where the output is a list but the problem specifies that the order doesn't matter. For instance, for problem 49 (Group Anagrams) the problem states that "You can return the answer in **any order**." However, running my solution to that problem gave: FAIL: Code Answer: [["eat","tea","ate"],["tan","nat"],["bat"]] [[""]] [["a"]] Expected Code Answer: [["bat"],["nat","tan"],["ate","eat","tea"]] [[""]] [["a"]] in the `*leetcode-result-49*` buffer. The problem here is that the we're not respecting the order-insensitivity of the answer the problem specifies. Looking at the result data structure, we see that there is also a `correct_answer` field which is the Leetcode assessment of whether the answer was correct or not. For example, in the case shown above the "correct_answer" field is set to "true". This change uses the "correct_answer" field to decide whether the test passed or failed, rather than comparing the output blocks directly.
1 parent f61ad97 commit e53812e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

leetcode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ alist specified in `display-buffer-alist'."
10341034
(goto-char (point-max))
10351035
(cond
10361036
((eq .status_code 10)
1037-
(if (equal .code_answer .expected_code_answer)
1037+
(if (equal .correct_answer t)
10381038
(insert (leetcode--add-font-lock "PASS: " 'leetcode-accepted-face))
10391039
(insert (leetcode--add-font-lock "FAIL: " 'leetcode-error-face)))
10401040
(insert "\n\n")

0 commit comments

Comments
 (0)