forked from bloominstituteoftechnology/Basic-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-2.test.js
More file actions
207 lines (189 loc) · 6.92 KB
/
project-2.test.js
File metadata and controls
207 lines (189 loc) · 6.92 KB
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
/* eslint-disable no-undef */
const {
getBiggest,
greeting,
isTenOrFive,
isInRange,
isInteger,
fizzBuzz,
isPrime,
returnFirst,
returnLast,
getArrayLength,
incrementByOne,
addItemToArray,
addItemToFront,
wordsToSentence,
contains,
addNumbers,
averageTestScore,
largestNumber
} = require('../src/project-2');
describe('Project 2', () => {
describe('getBiggest(x, y)', () => {
it('should return x if it is larger than y', () => {
expect(getBiggest(10, 5)).toBe(10);
});
it('should return y if it is larger than x', () => {
expect(getBiggest(50, 100)).toBe(100);
});
it('should return either one if they are the same', () => {
expect(getBiggest(1000, 1000)).toBe(1000);
});
});
describe('greeting(language)', () => {
it('should return \'Guten Tag!\' for German', () => {
expect(greeting('German')).toBe('Guten Tag!');
});
it('should return \'Hola!\' for Spanish', () => {
expect(greeting('Spanish')).toBe('Hola!');
});
it('should return \'Ni Hao!\' for Chinese', () => {
expect(greeting('Chinese')).toBe('Ni Hao!');
});
it('should return \'Hello!\' if no argument is passed in or if a language beyond Spanish, English, and German is passed in.', () => {
expect(greeting('French')).toBe('Hello!');
expect(greeting()).toBe('Hello!');
});
});
describe('isTenOrFive(num)', () => {
it('should return true if num is 10 or 5', () => {
expect(isTenOrFive(10)).toBe(true);
expect(isTenOrFive(5)).toBe(true);
});
it('should return false if num is not 10 or 5', () => {
expect(isTenOrFive(11)).toBe(false);
expect(isTenOrFive(6)).toBe(false);
expect(isTenOrFive(0)).toBe(false);
expect(isTenOrFive(5.01)).toBe(false);
});
});
describe('isInRange(num)', () => {
it('should return true if num is inside range', () => {
expect(isInRange(35.5)).toBe(true);
expect(isInRange(40)).toBe(true);
expect(isInRange(49)).toBe(true);
expect(isInRange(21)).toBe(true);
});
it('should return false if outside of range', () => {
expect(isInRange(10)).toBe(false);
expect(isInRange(20)).toBe(false);
expect(isInRange(50)).toBe(false);
expect(isInRange(100)).toBe(false);
});
});
describe('isInteger(num)', () => {
it('should return true if num is 5', () => {
expect(isInteger(5)).toBe(true);
});
it('should return false if num is 0.5', () => {
expect(isInteger(0.5)).toBe(false);
});
it('should return true if num is -20', () => {
expect(isInteger(-20)).toBe(true);
});
it('should return true for 0', () => {
expect(isInteger(0)).toBe(true);
});
});
describe('fizzBuzz(num)', () => {
it('should return fizz if divisible by 3', () => {
expect(fizzBuzz(9)).toBe('fizz');
});
it('should return buzz if divisible by 5', () => {
expect(fizzBuzz(10)).toBe('buzz');
});
it('should return fizzbuzz if divisible by 3 and 5', () => {
expect(fizzBuzz(15)).toBe('fizzbuzz');
});
it('should return num if not divisible by 3 or 5', () => {
expect(fizzBuzz(4)).toBe(4);
});
});
describe('isPrime(num)', () => {
it('should return true if num is prime', () => {
expect(isPrime(7)).toBe(true);
expect(isPrime(97)).toBe(true);
});
it('should return false if num is not prime', () => {
expect(isPrime(10)).toBe(false);
expect(isPrime(100)).toBe(false);
expect(isPrime(0)).toBe(false);
expect(isPrime(1)).toBe(false);
});
});
describe('returnFirst(arr)', () => {
it('should return the first item in the array', () => {
expect(returnFirst([10, 10, 16, 12])).toBe(10);
expect(returnFirst([97, 100, 80, 55, 72, 94])).toBe(97);
});
});
describe('returnLast(arr)', () => {
it('should return the last item in the array', () => {
expect(returnLast([10, 10, 16, 12])).toBe(12);
expect(returnLast([97, 100, 80, 55, 72, 94])).toBe(94);
expect(returnLast(['hi', 'there', 'how', 'are', 'you', 'doing?'])).toBe('doing?');
});
});
describe('getArrayLength(arr)', () => {
it('should return the length of the array', () => {
expect(getArrayLength([10, 10, 16, 12])).toBe(4);
expect(getArrayLength([97, 100, 80, 55, 72, 94])).toBe(6);
expect(getArrayLength(['hi', 'there', 'how', 'are', 'you', 'doing?'])).toBe(6);
});
});
describe('incrementByOne(arr)', () => {
it('should return the array with each value incremented by one', () => {
expect(incrementByOne([10, 10, 16, 12])).toEqual([11, 11, 17, 13]);
expect(incrementByOne([97, 100, 80, 55, 72, 94])).toEqual([98, 101, 81, 56, 73, 95]);
expect(incrementByOne([])).toEqual([]);
});
});
describe('addItemToArray(arr, item)', () => {
it('should return the array with the item added to the end', () => {
expect(addItemToArray([10, 10, 16, 12], 10)).toEqual([10, 10, 16, 12, 10]);
expect(addItemToArray([97, 100, 80, 55, 72, 94], 'Hello')).toEqual([97, 100, 80, 55, 72, 94, 'Hello']);
expect(addItemToArray([], true)).toEqual([true]);
});
});
describe('addItemToFront(arr, item)', () => {
it('should return the array with the item added to the front', () => {
expect(addItemToFront([10, 10, 16, 12], 10)).toEqual([10, 10, 10, 16, 12]);
expect(addItemToFront([97, 100, 80, 55, 72, 94], 'Hello')).toEqual(['Hello', 97, 100, 80, 55, 72, 94]);
expect(addItemToFront([], true)).toEqual([true]);
});
});
describe('wordsToSentence(words)', () => {
it('should return a string that has all of the words from the array separated by spaces', () => {
expect(wordsToSentence(['LambdaSchool', 'JavaScript', 'Class'])).toBe('LambdaSchool JavaScript Class');
expect(wordsToSentence(['LambdaSchool'])).toBe('LambdaSchool');
});
});
describe('contains(arr, item)', () => {
it('should return true if the array contains the item', () => {
expect(contains([10, 10, 16, 12], 10)).toBe(true);
expect(contains([97, 100, 80, 55, 72, 94], 'Hello')).toBe(false);
expect(contains([], true)).toBe(false);
});
});
describe('addNumbers(numbers)', () => {
it('should add all of the numbers in the array together and return the sum', () => {
expect(addNumbers([10, 10, 16])).toBe(36);
expect(addNumbers([97, 100])).toBe(197);
expect(addNumbers([0])).toBe(0);
});
});
describe('averageTestScore(testScores)', () => {
it('should return the average test score', () => {
expect(averageTestScore([10, 10, 16, 12])).toBe(12);
expect(averageTestScore([97, 100, 80, 55, 72, 94])).toBe(83);
});
});
describe('largestNumber(numbers)', () => {
it('should return the largest number', () => {
expect(largestNumber([10, 10, 16, 12])).toBe(16);
expect(largestNumber([97, 100, 80, 55, 72, 94])).toBe(100);
expect(largestNumber([97, 10000, 80, 55, 7.2, -94])).toBe(10000);
});
});
});