-
Notifications
You must be signed in to change notification settings - Fork 1
/
12-front-back-split.test.js
56 lines (49 loc) · 2.09 KB
/
12-front-back-split.test.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
const { Node } = require('../lib/00-utils')
const { buildList } = require('../lib/01-push-and-build-one-two-three')
const {
frontBackSplit,
frontBackSplitV2,
frontBackSplitV3,
} = require('../lib/12-front-back-split')
describe('12 Front Back Split', () => {
createTests(frontBackSplit)
createTests(frontBackSplitV2)
createTests(frontBackSplitV3)
function createTests(fn) {
describe(fn.name, () => {
it('should be able to handle all null arguments.', () => {
expect(() => fn(null, null, null)).toThrow('invalid arguments')
})
it('should be able to handle cases when one argument is null.', () => {
expect(() => fn(null, new Node(), new Node())).toThrow('invalid arguments')
expect(() => fn(new Node(), null, new Node())).toThrow('invalid arguments')
expect(() => fn(new Node(), new Node(), null)).toThrow('invalid arguments')
})
it('should be able to handle a list of length 0 or 1.', () => {
expect(() => fn(new Node(), new Node(), new Node())).toThrow('invalid arguments')
expect(() => fn(new Node(23), new Node(), new Node())).toThrow('invalid arguments')
})
it('should be able to handle a list of length 3.', () => {
const front = new Node()
const back = new Node()
fn(buildList([1, 2, 3]), front, back)
expect(front).toEqualLinkedList(buildList([1, 2]))
expect(back).toEqualLinkedList(new Node(3))
})
it('should be able to handle a list of length 6.', () => {
const front = new Node()
const back = new Node()
fn(buildList([1, 2, 3, 4, 5, 6]), front, back)
expect(front).toEqualLinkedList(buildList([1, 2, 3]))
expect(back).toEqualLinkedList(buildList([4, 5, 6]))
})
it('should be able to handle a list of length 11.', () => {
const front = new Node()
const back = new Node()
fn(buildList([3, 4, 6, 1, 2, 4, 2, 0, 3, 2, 6]), front, back)
expect(front).toEqualLinkedList(buildList([3, 4, 6, 1, 2, 4]))
expect(back).toEqualLinkedList(buildList([2, 0, 3, 2, 6]))
})
})
}
})