js-practice/test/list/sort-list.test.js

17 lines
580 B
JavaScript
Raw Normal View History

2020-05-02 13:34:49 +08:00
import { sortList } from '../../src/list/sort-list'
2020-05-10 16:57:42 +08:00
import { arrToList } from './ListNode'
2020-05-02 13:34:49 +08:00
test('链表排序', () => {
const source = [4, 2, 1, 3]
expect(sortList(arrToList(source))).toEqual(arrToList(source.sort((a, b) => a - b)))
const source2 = [-1, 5, 3, 4, 0]
expect(sortList(arrToList(source2))).toEqual(arrToList(source2.sort((a, b) => a - b)))
const source3 = [1, 3, 2, null]
expect(sortList(arrToList(source3))).toEqual(arrToList([1, 2, 3]))
const source4 = [1, 7, 2, 6, null]
expect(sortList(arrToList(source4))).toEqual(arrToList([1, 2, 6, 7]))
})