-
Notifications
You must be signed in to change notification settings - Fork 12
/
exercises.test.js
60 lines (50 loc) · 2.39 KB
/
exercises.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
// Question 1
const exercises = require('./exercises');
test('Question 1: isRealPalindrome', () => {
expect(exercises.isRealPalindrome('madam')).toBe(true);
expect(exercises.isRealPalindrome('Madam')).toBe(true);
expect(exercises.isRealPalindrome("Madam, I'm Adam")).toBe(true);
expect(exercises.isRealPalindrome('356653')).toBe(true);
expect(exercises.isRealPalindrome('356a653')).toBe(true);
expect(exercises.isRealPalindrome('123ab321')).toBe(false);
});
test('Question 2: RunningTotal', () => {
expect(exercises.runningTotal([2, 5, 13])).toEqual([2, 7, 20]);
expect(exercises.runningTotal([14, 11, 7, 15, 20])).toEqual([14, 25, 32, 47, 67]);
expect(exercises.runningTotal([3])).toEqual([3]);
expect(exercises.runningTotal([])).toEqual([]);
});
test('Question 3: swap', () => {
expect(exercises.swap('Oh what a wonderful day it is')).toBe("hO thaw a londerfuw yad ti si");
expect(exercises.swap('Abcde')).toBe("ebcdA");
expect(exercises.swap('a')).toBe("a");
});
test('Question 4: wordSizes', () => {
expect(exercises.wordSizes('Four score and seven.')).toEqual({ "3": 1, "4": 1, "5": 1, "6": 1 });
expect(exercises.wordSizes("What's up doc?")).toEqual({ "2": 1, "4": 1, "6": 1 });
expect(exercises.wordSizes("I ate her lunch")).toEqual({ "1": 1, "3": 2, "5": 1 });
expect(exercises.wordSizes("")).toEqual({});
});
test('Question 5: union', () => {
expect(exercises.union([1, 3, 5], [3, 6, 9])).toEqual([1, 3, 5, 6, 9]);
expect(exercises.union([2, 2, 2, 2], [10, 5, 2])).toEqual([2, 10, 5]);
});
test('Question 6: firstRecurring', () => {
expect(exercises.firstRecurring('reuben')).toBe("e");
expect(exercises.firstRecurring('anne')).toBe("n");
expect(exercises.firstRecurring('restaurant')).toBe("r");
expect(exercises.firstRecurring('paul')).toBe("");
});
test('Question 7: showMultiplicativeAverage', () => {
expect(exercises.showMultiplicativeAverage([3, 5])).toBe("7.500");
expect(exercises.showMultiplicativeAverage([2, 5, 7, 11, 13, 17])).toBe("28361.667");
});
test('Question 8: multiplyList', () => {
expect(exercises.multiplyList([3, 5, 7], [9, 10, 11])).toEqual([27, 50, 77]);
expect(exercises.multiplyList([5, 10, 15, 20], [1, 2, 3, 4])).toEqual([5, 20, 45, 80]);
});
test('Question 9: sequence', () => {
expect(exercises.sequence(5)).toEqual([1, 2, 3, 4, 5]);
expect(exercises.sequence(3)).toEqual([1, 2, 3]);
expect(exercises.sequence(1)).toEqual([1]);
});