forked from EternalHeartTeam/leetcode-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaseDataStructure.spec.js
109 lines (97 loc) · 2.88 KB
/
paseDataStructure.spec.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { expect, it } from 'vitest'
import { getDataStructure } from '#common/utils/question-handler/parseStructure.js'
const mockJSDOC_multiple = `/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} list1
* @param {number} a
* @param {number} b
* @param {ListNode} list2
* @return {ListNode}
*/
var mergeInBetween = function(list1, a, b, list2) {
console.log(list1.val,list1)
};`
const mockJSDOC_single = `/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var sortList = function(head) {
};`
const return_void = `/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {void} Do not return anything, modify head in-place instead.
*/
var reorderList = function(head) {
};`
const mockJSDOC_ListNodeArray = `/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode[]} lists
* @return {ListNode}
*/
var mergeKLists = function(lists) {
// console.log(lists.length, lists.val)
// const lists_1 = new ListNode(null)
for (let i = 0; i < lists.length; i++) {
let node = lists[i];
if(node) {
console.log(node.val)
}
// while (node) {
// list.push(node.val);
// node = node.next;
// }
}
};`
const array = ['ListNode', 'number', 'number', 'ListNode']
it('获取入参的数据结构 多参 是数组', () => {
expect(getDataStructure(mockJSDOC_multiple)).toBeInstanceOf(Array)
})
it('获取入参的数据结构 多参 匹配值', () => {
expect(getDataStructure(mockJSDOC_multiple)).toEqual(array)
})
it('获取入参的数据结构 单参 是数组', () => {
expect(getDataStructure(mockJSDOC_single)).toBeInstanceOf(Array)
})
it('获取入参的数据结构 单参 匹配值', () => {
expect(getDataStructure(mockJSDOC_single)).toEqual(['ListNode'])
})
it('获取入参的数据结构 单参 ListNode[]', () => {
expect(getDataStructure(mockJSDOC_ListNodeArray, 'param')).toEqual([
'ListNode[]'
])
})
it('获取返回值的数据结构 单参 匹配值', () => {
expect(getDataStructure(mockJSDOC_single, 'return')).toEqual(['ListNode'])
})
it('获取返回值的数据结构 多参 匹配值', () => {
expect(getDataStructure(mockJSDOC_multiple, 'return')).toEqual(['ListNode'])
})
it('获取返回值的数据结构 单参 void', () => {
expect(getDataStructure(return_void, 'return')).toEqual(['void'])
})