-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.js
137 lines (117 loc) · 4.63 KB
/
main.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
const {
doubleAll,
yelledGreetings,
absoluteValues,
upperCaseFirstLetters,
changeToInitials,
doubleOdd,
add1ToLeft,
} = require('./main.js')
describe('doubleAll', () => {
it(`doubles all numbers passed in`, () => {
const originalNumbers1 = [1, 2, 3, 4];
const numbers1 = [1, 2, 3, 4];
const originalNumbers2 = [-5, 101, 0, 32.5];
const numbers2 = [-5, 101, 0, 32.5];
expect(doubleAll(numbers1)).toEqual([2, 4, 6, 8]);
expect(doubleAll(numbers2)).toEqual([-10, 202, 0, 65]);
expect(numbers1).toEqual(originalNumbers1);
expect(numbers2).toEqual(originalNumbers2);
})
it(`doesn't modify the original array`, () => {
const originalNumbers1 = [1, 2, 3, 4];
const numbers1 = [1, 2, 3, 4];
const originalNumbers2 = [-5, 101, 0, 32.5];
const numbers2 = [-5, 101, 0, 32.5];
doubleAll(numbers1)
doubleAll(numbers2)
expect(numbers1).toEqual(originalNumbers1);
expect(numbers2).toEqual(originalNumbers2);
})
})
describe('yelledGreetings', () => {
it(`adds an exclamation point to the end of each string`, () => {
expect(yelledGreetings(['hello', 'there', 'you absolute fiend'])).toEqual(['hello!', 'there!', 'you absolute fiend!']);
expect(yelledGreetings(['hey', 'you'])).toEqual(['hey!', 'you!']);
})
it(`doesn't modify the original array`, () => {
const originalGreetings = ['hello', 'there', 'you absolute fiend'];
const greetings = ['hello', 'there', 'you absolute fiend'];
yelledGreetings(greetings)
expect(greetings).toEqual(originalGreetings);
})
})
describe('absoluteValues', () => {
it(`returns numbers unchanged if they're positive`, () => {
expect(absoluteValues([1, 3, 1000])).toEqual([1, 3, 1000]);
expect(absoluteValues([1, 5, 100])).toEqual([1, 5, 100]);
})
it(`returns positive versions of negative numbers`, () => {
expect(absoluteValues([-1, -3, 1000])).toEqual([1, 3, 1000]);
expect(absoluteValues([1, -5, 100])).toEqual([1, 5, 100]);
})
it(`can handle zeroes`, () => {
expect(absoluteValues([0, 0, 0])).toEqual([0, 0, 0]);
expect(absoluteValues([0])).toEqual([0]);
})
it(`doesn't modify the original array`, () => {
const originalNumbers = [-1, -3, 1000];
const numbers = [-1, -3, 1000];
absoluteValues(numbers)
expect(numbers).toEqual(originalNumbers);
})
})
describe('upperCaseFirstLetters', () => {
it(`uppercases the first letter of each name (as a string) in the given array`, () => {
expect(upperCaseFirstLetters(['colin', 'mesuara', 'genghis', 'pak', 'ginny', 'michael', 'tenzin'])).toEqual(['Colin', 'Mesuara', 'Genghis', 'Pak', 'Ginny', 'Michael', 'Tenzin'])
})
it(`lowercases the other letters of each name`, () => {
expect(upperCaseFirstLetters(['cOlin', 'geNghis', 'mesUara', 'ginny', 'michael', 'pak', 'tenzin'])).toEqual(['Colin', 'Genghis', 'Mesuara', 'Ginny', 'Michael', 'Pak', 'Tenzin'])
})
it(`doesn't modify the original array`, () => {
const originalNames = ['cOlin', 'geNghis', 'mesUara', 'ginny', 'michael', 'pak', 'tenzin'];
const names = ['cOlin', 'geNghis', 'mesUara', 'ginny', 'michael', 'pak', 'tenzin'];
upperCaseFirstLetters(names)
expect(names).toEqual(originalNames);
})
})
describe('changeToInitials', () => {
it(`will return the first letters from each word`, () => {
expect(changeToInitials(['Colin Jaffe', 'Mesuara Kaleziq'])).toEqual(['CJ', 'MK'])
expect(changeToInitials(['Larry Bird', 'Robert Parrish'])).toEqual(['LB', 'RP'])
})
it(`doesn't modify the original array`, () => {
const originalNames = ['Colin Jaffe', 'Mesuara Kaleziq']
const names = ['Colin Jaffe', 'Mesuara Kaleziq']
changeToInitials(names)
expect(names).toEqual(originalNames);
})
})
describe('doubleOdd', () => {
it(`doubles all odd numbers passed in`, () => {
expect(doubleOdd([1, 2, 3, 4, 101, 0, 32.5])).toEqual([2, 2, 6, 4, 202, 0, 32.5]);
})
it(`can handle negative numbers`, () => {
expect(doubleOdd([-5, -1, -100, -2])).toEqual([-10, -2, -100, -2]);
})
it(`doesn't modify the original array`, () => {
const originalNumbers = [-1, -3, 1000];
const numbers = [-1, -3, 1000];
doubleOdd(numbers)
expect(numbers).toEqual(originalNumbers);
})
})
describe('add1ToLeft', () => {
it(`adds a 1 on the left side of positive numbers`, () => {
expect(add1ToLeft([1, 2, 30, 400])).toEqual([11, 12, 130, 1400])
})
it(`can handle negative numbers`, () => {
expect(add1ToLeft([-1, -50])).toEqual([-11, -150])
})
it(`doesn't modify the original array`, () => {
const originalNumbers = [-1, -3, 1000];
const numbers = [-1, -3, 1000];
add1ToLeft(numbers)
expect(numbers).toEqual(originalNumbers);
})
})