-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
208 lines (194 loc) · 4.57 KB
/
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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const {
filterByLength,
everyNPerson,
initials,
peopleWithPosition,
sortByFirstName,
sortByLastName,
countTotalCharacters,
everyoneHasLetter,
someoneHasLetter,
} = require('./cardio');
const people = [
'Faber Guerreau',
'Gilbertine Stichall',
'Cristina Cuckoo',
'Johnette Chatelot',
'Trish Mayou',
'Ruth Connell',
'Hamid Elsegood',
'Thorstein Woodward',
'Bethena Porte',
'Nelle Durek',
'Bastien Leyrroyd',
'Albie Tranfield',
'Bryce Temprell',
'Darya Chinery',
'Rea Matoshin',
'Tommie Benda',
'Lowell Trowel',
'Wayne Claughton',
'Teena Bansal',
'Basile Phonix',
];
describe('filterByLength', () => {
it('filters by length of 15', () => {
const answer = [
'Gilbertine Stichall',
'Johnette Chatelot',
'Thorstein Woodward',
'Bastien Leyrroyd',
];
expect(filterByLength(people, 15)).toEqual(answer);
});
it('filters by length of 0', () => {
expect(filterByLength(people, 0)).toEqual(people);
});
it('filters by a massive length', () => {
expect(filterByLength(people, 100000000)).toEqual([]);
});
});
describe('everyNPerson', () => {
it('returns every third person', () => {
const answer = [
'Faber Guerreau',
'Johnette Chatelot',
'Hamid Elsegood',
'Nelle Durek',
'Bryce Temprell',
'Tommie Benda',
'Teena Bansal',
];
expect(everyNPerson(people, 3)).toEqual(answer);
});
it('returns every person', () => {
expect(everyNPerson(people, 0)).toEqual(people);
});
it('returns every massive number of people', () => {
expect(everyNPerson(people, 1000000)).toEqual(['Faber Guerreau']);
});
});
describe('initials', () => {
it(`returns everyone's initials`, () => {
const answer = [
'FG',
'GS',
'CC',
'JC',
'TM',
'RC',
'HE',
'TW',
'BP',
'ND',
'BL',
'AT',
'BT',
'DC',
'RM',
'TB',
'LT',
'WC',
'TB',
'BP',
];
expect(initials(people)).toEqual(answer);
});
});
describe('sortByLastName', () => {
it('returns a sorted list of names by last name', () => {
const answer = [
'Teena Bansal',
'Tommie Benda',
'Johnette Chatelot',
'Darya Chinery',
'Wayne Claughton',
'Ruth Connell',
'Cristina Cuckoo',
'Nelle Durek',
'Hamid Elsegood',
'Faber Guerreau',
'Bastien Leyrroyd',
'Rea Matoshin',
'Trish Mayou',
'Basile Phonix',
'Bethena Porte',
'Gilbertine Stichall',
'Bryce Temprell',
'Albie Tranfield',
'Lowell Trowel',
'Thorstein Woodward',
];
// console.log(sortByLastName(people));
expect(sortByLastName(people)).toEqual(answer);
});
});
describe('countTotalCharacters', () => {
it('counts the total characters in a name (including spaces)', () => {
expect(countTotalCharacters(people)).toEqual(279);
});
});
describe('someoneHasLetter', () => {
it('returns if one or more people have the letter', () => {
expect(someoneHasLetter(people, 'e')).toEqual(true);
});
});
describe('everyoneHasLetter', () => {
it('returns if all people have the letter', () => {
expect(everyoneHasLetter(people, 'z')).toEqual(false);
});
});
describe('peopleWithPosition', () => {
it(`returns everyone's name with their position`, () => {
const answer = [
'0: Faber Guerreau',
'1: Gilbertine Stichall',
'2: Cristina Cuckoo',
'3: Johnette Chatelot',
'4: Trish Mayou',
'5: Ruth Connell',
'6: Hamid Elsegood',
'7: Thorstein Woodward',
'8: Bethena Porte',
'9: Nelle Durek',
'10: Bastien Leyrroyd',
'11: Albie Tranfield',
'12: Bryce Temprell',
'13: Darya Chinery',
'14: Rea Matoshin',
'15: Tommie Benda',
'16: Lowell Trowel',
'17: Wayne Claughton',
'18: Teena Bansal',
'19: Basile Phonix',
];
expect(peopleWithPosition(people)).toEqual(answer);
});
});
describe('sortByFirstName', () => {
it('sorts by first name', () => {
const answer = [
'Albie Tranfield',
'Basile Phonix',
'Bastien Leyrroyd',
'Bethena Porte',
'Bryce Temprell',
'Cristina Cuckoo',
'Darya Chinery',
'Faber Guerreau',
'Gilbertine Stichall',
'Hamid Elsegood',
'Johnette Chatelot',
'Lowell Trowel',
'Nelle Durek',
'Rea Matoshin',
'Ruth Connell',
'Teena Bansal',
'Thorstein Woodward',
'Tommie Benda',
'Trish Mayou',
'Wayne Claughton',
];
expect(sortByFirstName(people)).toEqual(answer);
});
});