-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlistNode.spec.js
36 lines (34 loc) · 978 Bytes
/
listNode.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
import { test, expect, describe } from 'vitest';
import { ListNode } from "#common/structures/ListNode";
test('toArray 正常数组', () => {
// 创建链表
const head = new ListNode(1);
const node1 = new ListNode(2);
const node2 = new ListNode(3);
head.next = node1;
node1.next = node2;
const arr = ListNode.toArray(head)
expect(arr).toEqual([1, 2, 3])
})
test('toArray undefined', () => {
const arr = ListNode.toArray(undefined)
expect(arr).toEqual([])
})
test('toArray false', () => {
const arr = ListNode.toArray(false)
expect(arr).toEqual([undefined])
})
test('toArray 1', () => {
const arr = ListNode.toArray(1)
expect(arr).toEqual([undefined])
})
test('parse [1,2,3]', () => {
const listNode = ListNode.parse([1,2,3])
expect(listNode.val).toEqual(1)
expect(listNode.next?.val).toEqual(2)
expect(listNode.next?.next?.val).toEqual(3)
})
test('parse []', () => {
const listNode = ListNode.parse([])
expect(listNode).toEqual(null)
})