forked from jbarrus/typescript-refactoring-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finder.spec.ts
111 lines (83 loc) · 2.55 KB
/
finder.spec.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
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
110
111
import Thing from './thing';
import Finder from './finder';
import FT from './ft';
describe('finder', () => {
let sue = new Thing();
let greg = new Thing();
let sarah = new Thing();
let mike = new Thing();
beforeEach(() => {
sue.name = "Sue";
sue.birthDate = new Date(50, 0, 1);
greg.name = "Greg";
greg.birthDate = new Date(52, 5, 1);
sarah.name = "Sarah";
sarah.birthDate = new Date(82, 0, 1);
mike.name = "Mike";
mike.birthDate = new Date(79, 0, 1);
});
it('should return empty results when given empty list', () => {
const list: Thing[] = [];
const finder = new Finder(list);
const result = finder.Find(FT.One);
expect(result.P1).toEqual(undefined);
expect(result.P2).toEqual(undefined);
});
it('should return empty results when given on person', () => {
const list: Thing[] = [];
list.push(sue);
const finder = new Finder(list);
const result = finder.Find(FT.One);
expect(result.P1).toEqual(undefined);
expect(result.P2).toEqual(undefined);
});
it('should return closest two for two people', () => {
const list: Thing[] = [];
list.push(sue);
list.push(greg);
const finder = new Finder(list);
const result = finder.Find(FT.One);
expect(result.P1).toEqual(sue);
expect(result.P2).toEqual(greg);
});
it('should return the furthest two for two people', () => {
const list: Thing[] = [];
list.push(mike);
list.push(greg);
const finder = new Finder(list);
const result = finder.Find(FT.Two);
expect(result.P1).toEqual(greg);
expect(result.P2).toEqual(mike);
});
it('should return the furthest two for two people', () => {
const list: Thing[] = [];
list.push(mike);
list.push(greg);
const finder = new Finder(list);
const result = finder.Find(FT.Two);
expect(result.P1).toEqual(greg);
expect(result.P2).toEqual(mike);
});
it('should return the furthest two for four people', () => {
const list: Thing[] = [];
list.push(sue);
list.push(sarah);
list.push(mike);
list.push(greg);
const finder = new Finder(list);
const result = finder.Find(FT.Two);
expect(result.P1).toEqual(sue);
expect(result.P2).toEqual(sarah);
});
it('should return the closest two for four people', () => {
const list: Thing[] = [];
list.push(sue);
list.push(sarah);
list.push(mike);
list.push(greg);
const finder = new Finder(list);
const result = finder.Find(FT.One);
expect(result.P1).toEqual(sue);
expect(result.P2).toEqual(greg);
});
});