-
Notifications
You must be signed in to change notification settings - Fork 3
/
question_test.go
34 lines (31 loc) · 7.43 KB
/
question_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package leetgode
import (
"encoding/json"
"testing"
)
func TestGetQuestionDetailResult(t *testing.T) {
var got GetQuestionDetailResult
data := `
{
"data": {
"isCurrentUserAuthenticated": false,
"question": {
"questionId": "2",
"content": "<p>You are given two <b>non-empty</b> linked lists representing two non-negative integers. The digits are stored in <b>reverse order</b> and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.</p>\r\n\r\n<p>You may assume the two numbers do not contain any leading zero, except the number 0 itself.</p>\r\n\r\n<p><b>Example:</b></p>\r\n\r\n<pre>\r\n<b>Input:</b> (2 -> 4 -> 3) + (5 -> 6 -> 4)\r\n<b>Output:</b> 7 -> 0 -> 8\r\n<b>Explanation:</b> 342 + 465 = 807.\r\n</pre>\r\n",
"stats": "{\"totalAccepted\": \"1.5M\", \"totalSubmission\": \"4.5M\", \"totalAcceptedRaw\": 1515823, \"totalSubmissionRaw\": 4454304, \"acRate\": \"34.0%\"}",
"codeDefinition": "[{\"value\": \"cpp\", \"text\": \"C++\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * struct ListNode {\\n * int val;\\n * ListNode *next;\\n * ListNode() : val(0), next(nullptr) {}\\n * ListNode(int x) : val(x), next(nullptr) {}\\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\\n * };\\n */\\nclass Solution {\\npublic:\\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\\n \\n }\\n};\"}, {\"value\": \"java\", \"text\": \"Java\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * public class ListNode {\\n * int val;\\n * ListNode next;\\n * ListNode() {}\\n * ListNode(int val) { this.val = val; }\\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\\n * }\\n */\\nclass Solution {\\n public ListNode addTwoNumbers(ListNode l1, ListNode l2) {\\n \\n }\\n}\"}, {\"value\": \"python\", \"text\": \"Python\", \"defaultCode\": \"# Definition for singly-linked list.\\n# class ListNode(object):\\n# def __init__(self, val=0, next=None):\\n# self.val = val\\n# self.next = next\\nclass Solution(object):\\n def addTwoNumbers(self, l1, l2):\\n \\\"\\\"\\\"\\n :type l1: ListNode\\n :type l2: ListNode\\n :rtype: ListNode\\n \\\"\\\"\\\"\\n \"}, {\"value\": \"python3\", \"text\": \"Python3\", \"defaultCode\": \"# Definition for singly-linked list.\\n# class ListNode:\\n# def __init__(self, val=0, next=None):\\n# self.val = val\\n# self.next = next\\nclass Solution:\\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:\\n \"}, {\"value\": \"c\", \"text\": \"C\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * struct ListNode {\\n * int val;\\n * struct ListNode *next;\\n * };\\n */\\n\\n\\nstruct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){\\n\\n}\"}, {\"value\": \"csharp\", \"text\": \"C#\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * public class ListNode {\\n * public int val;\\n * public ListNode next;\\n * public ListNode(int val=0, ListNode next=null) {\\n * this.val = val;\\n * this.next = next;\\n * }\\n * }\\n */\\npublic class Solution {\\n public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {\\n \\n }\\n}\"}, {\"value\": \"javascript\", \"text\": \"JavaScript\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * function ListNode(val, next) {\\n * this.val = (val===undefined ? 0 : val)\\n * this.next = (next===undefined ? null : next)\\n * }\\n */\\n/**\\n * @param {ListNode} l1\\n * @param {ListNode} l2\\n * @return {ListNode}\\n */\\nvar addTwoNumbers = function(l1, l2) {\\n \\n};\"}, {\"value\": \"ruby\", \"text\": \"Ruby\", \"defaultCode\": \"# Definition for singly-linked list.\\n# class ListNode\\n# attr_accessor :val, :next\\n# def initialize(val = 0, _next = nil)\\n# @val = val\\n# @next = _next\\n# end\\n# end\\n# @param {ListNode} l1\\n# @param {ListNode} l2\\n# @return {ListNode}\\ndef add_two_numbers(l1, l2)\\n \\nend\"}, {\"value\": \"swift\", \"text\": \"Swift\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * public class ListNode {\\n * public var val: Int\\n * public var next: ListNode?\\n * public init() { self.val = 0; self.next = nil; }\\n * public init(_ val: Int) { self.val = val; self.next = nil; }\\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\\n * }\\n */\\nclass Solution {\\n func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\\n \\n }\\n}\"}, {\"value\": \"golang\", \"text\": \"Go\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * type ListNode struct {\\n * Val int\\n * Next *ListNode\\n * }\\n */\\nfunc addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\\n \\n}\"}, {\"value\": \"scala\", \"text\": \"Scala\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\\n * var next: ListNode = _next\\n * var x: Int = _x\\n * }\\n */\\nobject Solution {\\n def addTwoNumbers(l1: ListNode, l2: ListNode): ListNode = {\\n \\n }\\n}\"},{\"value\": \"rust\", \"text\": \"Rust\", \"defaultCode\": \"// Definition for singly-linked list.\\n// #[derive(PartialEq, Eq, Clone, Debug)]\\n// pub struct ListNode {\\n// pub val: i32,\\n// pub next: Option<Box<ListNode>>\\n// }\\n// \\n// impl ListNode {\\n// #[inline]\\n// fn new(val: i32) -> Self {\\n// ListNode {\\n// next: None,\\n// val\\n// }\\n// }\\n// }\\nimpl Solution {\\n pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\\n \\n }\\n}\"}, {\"value\": \"php\", \"text\": \"PHP\", \"defaultCode\": \"/**\\n * Definition for a singly-linked list.\\n * class ListNode {\\n * public $val = 0;\\n * public $next = null;\\n * function __construct($val = 0, $next = null) {\\n * $this->val = $val;\\n * $this->next = $next;\\n * }\\n * }\\n */\\nclass Solution {\\n\\n /**\\n * @param ListNode $l1\\n * @param ListNode $l2\\n * @return ListNode\\n */\\n function addTwoNumbers($l1, $l2) {\\n \\n }\\n}\"}, {\"value\": \"typescript\", \"text\": \"TypeScript\", \"defaultCode\": \"/**\\n * Definition for singly-linked list.\\n * class ListNode {\\n * val: number\\n * next: ListNode | null\\n * constructor(val?: number, next?: ListNode | null) {\\n * this.val = (val===undefined ? 0 : val)\\n * this.next = (next===undefined ? null : next)\\n * }\\n * }\\n */\\n\\nfunction addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {\\n\\n};\"}]",
"sampleTestCase": "[2,4,3]\n[5,6,4]",
"enableRunCode": true,
"metaData": "{\r\n \"name\": \"addTwoNumbers\",\r\n \"params\": [\r\n {\r\n \"name\": \"l1\",\r\n \"type\": \"ListNode\",\r\n \"dealloc\": false\r\n },\r\n {\r\n \"name\": \"l2\",\r\n \"type\": \"ListNode\",\r\n \"dealloc\": false\r\n }\r\n ],\r\n \"return\": {\r\n \"type\": \"ListNode\",\r\n \"dealloc\": true\r\n }\r\n}",
"translatedContent": null
}
}
}
`
if err := json.Unmarshal([]byte(data), &got); err != nil {
t.Fatal(err)
}
if len(got.Data.Question.CodeDefinition) == 0 {
t.Errorf("failed parse.")
}
}