-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathordered_list.test.ts
52 lines (39 loc) · 1.44 KB
/
ordered_list.test.ts
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
import {OrderedList} from './ordered_list';
test('ordered list should support random insertion and order checks', () => {
const ol = new OrderedList<null>();
const c1 = ol.insertEntryAfter(null, ol.base);
const c3 = ol.insertEntryAfter(null, c1);
const c2 = ol.insertEntryAfter(null, c1);
// the entries are ordered c1 -> c2 -> c3;
expect(ol.order(c1, c2)).toBe(1);
expect(ol.order(c2, c1)).toBe(-1);
expect(ol.order(c1, c1)).toBe(0);
expect(ol.order(c1, c2)).toBe(1);
expect(ol.order(c2, c3)).toBe(1);
expect(ol.order(c1, c3)).toBe(1);
});
test('ordered list should support simple deletion', () => {
const ol = new OrderedList<null>();
// c1 -> c2 -> c3
const c1 = ol.insertEntryAfter(null, ol.base);
const c2 = ol.insertEntryAfter(null, c1);
const c3 = ol.insertEntryAfter(null, c2);
expect(ol.deleted(c1)).toBe(false);
expect(ol.deleted(c2)).toBe(false);
ol.delete(c2);
expect(ol.deleted(c1)).toBe(false);
expect(ol.deleted(c2)).toBe(true);
expect(ol.order(c1, c3)).toBe(1);
});
test('ordered list should support splice deletion', () => {
const ol = new OrderedList<null>();
// c1 -> c2 -> c3
const c1 = ol.insertEntryAfter(null, ol.base);
const c2 = ol.insertEntryAfter(null, c1);
const c3 = ol.insertEntryAfter(null, c2);
expect(ol.deleted(c2)).toBe(false);
expect(ol.deleted(c3)).toBe(false);
ol.spliceOut(c2, c3);
expect(ol.deleted(c2)).toBe(false);
expect(ol.deleted(c3)).toBe(true);
});