Skip to content

Commit f5f1fa8

Browse files
committed
Update tests - add missing import
1 parent 578d90c commit f5f1fa8

File tree

1 file changed

+54
-53
lines changed

1 file changed

+54
-53
lines changed

tests/functions-and-arrays.spec.js

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const {
22
maxOfTwoNumbers,
33
findLongestWord,
44
sumNumbers,
5+
sum,
56
averageNumbers,
67
uniquifyArray,
78
doesWordExist,
@@ -24,44 +25,44 @@ const shuffle = (currentArray) => {
2425
};
2526

2627
describe('Find the maximum', () => {
27-
it('should declare a function named maxOfTwoNumbers', () => {
28+
test('should declare a function named maxOfTwoNumbers', () => {
2829
expect(typeof maxOfTwoNumbers).toBe('function');
2930
});
3031

31-
it('should return greater of two arguments - if the first argument greater', () => {
32+
test('should return greater of two arguments - if the first argument greater', () => {
3233
expect(maxOfTwoNumbers(2, 1)).toBe(2);
3334
expect(maxOfTwoNumbers(5, -7)).toBe(5);
3435
});
3536

36-
it('should return greater of two arguments - if the second argument greater', () => {
37+
test('should return greater of two arguments - if the second argument greater', () => {
3738
expect(maxOfTwoNumbers(1, 3)).toBe(3);
3839
expect(maxOfTwoNumbers(-5, 3)).toBe(3);
3940
});
4041

41-
it('should return either arguments - if both arguments are equal', () => {
42+
test('should return either arguments - if both arguments are equal', () => {
4243
expect(maxOfTwoNumbers(4, 4)).toBe(4);
4344
});
4445
});
4546

4647
describe('Find the longest word', () => {
47-
it('should declare a function named findLongestWord', () => {
48+
test('should declare a function named findLongestWord', () => {
4849
expect(typeof findLongestWord).toBe('function');
4950
});
5051

51-
it('should return null when called with an empty array', () => {
52+
test('should return null when called with an empty array', () => {
5253
expect(findLongestWord([])).toBe(null);
5354
});
5455

55-
it('should return the word when called with a single-word array', () => {
56+
test('should return the word when called with a single-word array', () => {
5657
expect(findLongestWord(['foo'])).toBe('foo');
5758
});
5859

59-
it('should return the first occurrence of the word when longest have multiple occurrences ', () => {
60+
test('should return the first occurrence of the word when longest have multiple occurrences ', () => {
6061
expect(findLongestWord(['foo', 'bar'])).toBe('foo');
6162
expect(findLongestWord(['bar', 'foo'])).toBe('bar');
6263
});
6364

64-
it('should return the longest occurrence when it has multiple words', () => {
65+
test('should return the longest occurrence when it has multiple words', () => {
6566
let words = ['a', 'zab', '12abc', '$$abcd', 'abcde', 'ironhack'];
6667
for (let i = 0; i < 10; i++) {
6768
words = shuffle(words);
@@ -71,120 +72,120 @@ describe('Find the longest word', () => {
7172
});
7273

7374
describe('Calculate the sum of array of numbers', () => {
74-
it('should declare a function named sumNumbers', () => {
75+
test('should declare a function named sumNumbers', () => {
7576
expect(typeof sumNumbers).toBe('function');
7677
});
7778

78-
it('should return zero if receives an empty array when called', () => {
79+
test('should return zero if receives an empty array when called', () => {
7980
expect(sumNumbers([])).toBe(0);
8081
});
8182

82-
it('should return the sum with one number array', () => {
83+
test('should return the sum with one number array', () => {
8384
expect(sumNumbers([4])).toBe(4);
8485
});
8586

86-
it('should return zero if all elements are zero', () => {
87+
test('should return zero if all elements are zero', () => {
8788
expect(sumNumbers([0, 0, 0, 0, 0])).toBe(0);
8889
});
8990

90-
it('should return the sum when passed array of numbers', () => {
91+
test('should return the sum when passed array of numbers', () => {
9192
expect(sumNumbers([10, 5, 4, 32, 8])).toBe(59);
9293
});
9394
});
9495

9596
describe('Bonus: Calculate the sum', () => {
96-
it('should declare a function named sum', () => {
97+
test('should declare a function named sum', () => {
9798
expect(typeof sum).toBe('function');
9899
});
99100

100-
it('should return zero if receives an empty array when called', () => {
101+
test('should return zero if receives an empty array when called', () => {
101102
expect(sum([])).toBe(0);
102103
});
103104

104-
it('should return the sum with one number array', () => {
105+
test('should return the sum with one number array', () => {
105106
expect(sum([4])).toBe(4);
106107
});
107108

108-
it('should return zero if all elements are zero', () => {
109+
test('should return zero if all elements are zero', () => {
109110
expect(sum([0, 0, 0, 0, 0])).toBe(0);
110111
});
111112

112-
it('should return the sum when passed array of numbers', () => {
113+
test('should return the sum when passed array of numbers', () => {
113114
expect(sum([10, 5, 4, 32, 8])).toBe(59);
114115
});
115116

116-
it('should return the sum when passed array of strings', () => {
117+
test('should return the sum when passed array of strings', () => {
117118
expect(sum(['ana', 'marco', 'nicolas', 'tania', 'ptwd'])).toBe(24);
118119
});
119120

120-
it('should return the sum when passed array of mixed strings and numbers - ', () => {
121+
test('should return the sum when passed array of mixed strings and numbers - ', () => {
121122
expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, 10])).toBe(56);
122123
});
123-
it('should return the sum when passed array of mixed strings, numbers and booleans - ', () => {
124+
test('should return the sum when passed array of mixed strings, numbers and booleans - ', () => {
124125
// false is counted as 0
125126
expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, false])).toBe(46);
126127
// true is counted as 1
127128
expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, true])).toBe(47);
128129
});
129-
it('should throw an error when unsupported data type (object or array) present in the array', () => {
130+
test('should throw an error when unsupported data type (object or array) present in the array', () => {
130131
expect(() => sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, [], {}])).toThrow(
131132
new Error("Unsupported data type sir or ma'am")
132133
);
133134
});
134135
});
135136

136137
describe('Calculate the average of an array of numbers', () => {
137-
it('should declare a function named averageNumbers', () => {
138+
test('should declare a function named averageNumbers', () => {
138139
expect(typeof averageNumbers).toBe('function');
139140
});
140141

141-
it('should return null if receives an empty array when called', () => {
142+
test('should return null if receives an empty array when called', () => {
142143
expect(averageNumbers([])).toBe(null);
143144
});
144145

145-
it('should return the average of a one-element array', () => {
146+
test('should return the average of a one-element array', () => {
146147
expect(averageNumbers([9])).toBe(9);
147148
});
148149

149-
it('should return the average even with negative values', () => {
150+
test('should return the average even with negative values', () => {
150151
expect(averageNumbers([9, -3, -4, 6])).toBe(2);
151152
});
152153

153-
it('should return the average of the array', () => {
154+
test('should return the average of the array', () => {
154155
expect(averageNumbers([9, 10, 82, 92, 32, 102, 58])).toBe(55);
155156
});
156157
});
157158

158159
describe('Calculate the average of an array of strings', () => {
159-
it('should declare a function named averageWordLength', () => {
160+
test('should declare a function named averageWordLength', () => {
160161
expect(typeof averageWordLength).toBe('function');
161162
});
162163

163-
it('should return null if receives an empty array when called', () => {
164+
test('should return null if receives an empty array when called', () => {
164165
expect(averageWordLength([])).toBe(null);
165166
});
166167

167-
it('should return the average of a one-element array', () => {
168+
test('should return the average of a one-element array', () => {
168169
expect(averageWordLength(['ironhack'])).toBe(8);
169170
});
170171

171-
it('should return the average of a the array', () => {
172+
test('should return the average of a the array', () => {
172173
expect(
173174
averageWordLength(['Ironhack', 'Madrid', 'Barcelona', 'Paris', 'Miami', 'Mexico', 'Berlin', 'Programmers'])
174175
).toBe(7);
175176
});
176177
});
177178

178179
describe('Bonus: Calculate the average of a mixed elements array', () => {
179-
it('should declare a function named avg', () => {
180+
test('should declare a function named avg', () => {
180181
expect(typeof avg).toBe('function');
181182
});
182183

183-
it('should return null if receives an empty array when called', () => {
184+
test('should return null if receives an empty array when called', () => {
184185
expect(avg([])).toBe(null);
185186
});
186187

187-
it('should return the average of the array', () => {
188+
test('should return the average of the array', () => {
188189
// false is counted as 0
189190
expect(avg([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, false])).toBe(5.11);
190191
// true is counted as 1
@@ -193,69 +194,69 @@ describe('Bonus: Calculate the average of a mixed elements array', () => {
193194
});
194195

195196
describe('Unique array', () => {
196-
it('should declare a function named uniquifyArray', () => {
197+
test('should declare a function named uniquifyArray', () => {
197198
expect(typeof uniquifyArray).toBe('function');
198199
});
199200

200-
it('should return null if receives an empty array when called', () => {
201+
test('should return null if receives an empty array when called', () => {
201202
expect(uniquifyArray([])).toEqual(null);
202203
});
203204

204-
it('should return the correct uniqified array when an array of the same elements passed as argument', () => {
205+
test('should return the correct uniqified array when an array of the same elements passed as argument', () => {
205206
expect(uniquifyArray(['Ironhack', 'Ironhack', 'Ironhack'])).toEqual(['Ironhack']);
206207
});
207208

208-
it('should return the same array when no element is repeated', () => {
209+
test('should return the same array when no element is repeated', () => {
209210
expect(uniquifyArray(['Cat', 'Dog', 'Cow'])).toEqual(['Cat', 'Dog', 'Cow']);
210211
});
211212

212-
it('should return the uniquified array', () => {
213+
test('should return the uniquified array', () => {
213214
expect(
214215
uniquifyArray(['iPhone', 'Samsung', 'Android', 'iOS', 'iPhone', 'Samsung', 'Nokia', 'Blackberry', 'Android'])
215216
).toEqual(['iPhone', 'Samsung', 'Android', 'iOS', 'Nokia', 'Blackberry']);
216217
});
217218
});
218219

219220
describe('Find elements', () => {
220-
it('should declare a function named doesWordExist', () => {
221+
test('should declare a function named doesWordExist', () => {
221222
expect(typeof doesWordExist).toBe('function');
222223
});
223224

224-
it('should return null if receives an empty array when called', () => {
225+
test('should return null if receives an empty array when called', () => {
225226
expect(doesWordExist([])).toBe(null);
226227
});
227228

228-
it('should return true if the word we are looking for is the only one in the array', () => {
229+
test('should return true if the word we are looking for is the only one in the array', () => {
229230
expect(doesWordExist(['machine'], 'machine')).toBe(true);
230231
});
231232

232-
it('should return false if the word we are looking for is not in the array', () => {
233+
test('should return false if the word we are looking for is not in the array', () => {
233234
expect(doesWordExist(['machine', 'poison', 'eat', 'apple', 'horse'], 'ratatouille')).toBe(false);
234235
});
235236

236-
it('should return true if the word we are looking for is in the array', () => {
237+
test('should return true if the word we are looking for is in the array', () => {
237238
expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(true);
238239
});
239240
});
240241

241242
describe('Count repetition', () => {
242-
it('should declare a function named howManyTimes', () => {
243+
test('should declare a function named howManyTimes', () => {
243244
expect(typeof howManyTimes).toBe('function');
244245
});
245246

246-
it('should return 0 (zero) if receives an empty array when called', () => {
247+
test('should return 0 (zero) if receives an empty array when called', () => {
247248
expect(howManyTimes([])).toBe(0);
248249
});
249250

250-
it('should return 1 (one) when the word appears only one time in the array', () => {
251+
test('should return 1 (one) when the word appears only one time in the array', () => {
251252
expect(howManyTimes(['basketball', 'football', 'tennis'], 'tennis')).toBe(1);
252253
});
253254

254-
it("should return 0 (zero) when the word doesn't appear in the array", () => {
255+
test("should return 0 (zero) when the word doesn't appear in the array", () => {
255256
expect(howManyTimes(['basketball', 'football', 'tennis'], 'rugby')).toBe(0);
256257
});
257258

258-
it('should return 5 (five) when the word appears 5 times in the array', () => {
259+
test('should return 5 (five) when the word appears 5 times in the array', () => {
259260
expect(
260261
howManyTimes(
261262
[
@@ -278,11 +279,11 @@ describe('Count repetition', () => {
278279
});
279280

280281
describe('Bonus Quest - greatestProduct', () => {
281-
it('should declare a function named greatestProduct', () => {
282+
test('should declare a function named greatestProduct', () => {
282283
expect(typeof greatestProduct).toBe('function');
283284
});
284285

285-
it('should return 1 (one) when all numbers of the arrays are 1', () => {
286+
test('should return 1 (one) when all numbers of the arrays are 1', () => {
286287
let matrix = [
287288
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
288289
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
@@ -308,7 +309,7 @@ describe('Bonus Quest - greatestProduct', () => {
308309
expect(greatestProduct(matrix)).toBe(1);
309310
});
310311

311-
it('should return 16 when all the numbers of the arrays are 2', () => {
312+
test('should return 16 when all the numbers of the arrays are 2', () => {
312313
let matrix = [
313314
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
314315
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],

0 commit comments

Comments
 (0)