forked from seanwessmith/Lambda-Challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assessment.test.js
75 lines (70 loc) · 2.23 KB
/
assessment.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
const {
helloWorld,
lambdaSchool,
longestString,
computeUserAverageAge,
} = require('./assessment');
describe('Lambda School Precourse Assessment', () => {
describe('helloWorld', () => {
it('should return a string', () => {
expect(typeof helloWorld()).toBe('string');
});
it('should return the string \'Hello World!\'', () => {
expect(helloWorld()).toBe('Hello World!');
});
});
describe('lambdaSchool', () => {
it('should return \'Lambda\' for a number divisible by 3', () => {
expect(lambdaSchool(12)).toBe('Lambda');
expect(lambdaSchool(63)).toBe('Lambda');
expect(lambdaSchool(999)).toBe('Lambda');
});
it('should return \'School\' for a number divisible by 5', () => {
expect(lambdaSchool(10)).toBe('School');
expect(lambdaSchool(155)).toBe('School');
expect(lambdaSchool(1000)).toBe('School');
});
it('should return \'Lambda School\' for a number divisible by 3 and 5', () => {
expect(lambdaSchool(15)).toBe('Lambda School');
expect(lambdaSchool(30)).toBe('Lambda School');
expect(lambdaSchool(180)).toBe('Lambda School');
});
});
describe('longestString', () => {
it('should return the longest string in the array', () => {
expect(longestString(['array', 'object', 'function'])).toBe('function');
expect(longestString(['C++', 'JavaScript', 'Python'])).toBe('JavaScript');
});
it('should return the first longest string if there is a tie', () => {
expect(longestString(['C++', 'CSS', 'JWT'])).toBe('C++');
});
});
describe('computeUserAverageAge', () => {
const authors = [{
name: 'Frank Herbert',
age: 65,
}, {
name: 'Douglas Adams',
age: 49,
}, {
name: 'Isaac Asimov',
age: 72,
}];
const computerScientists = [{
name: 'Brendan Eich',
age: 56,
}, {
name: 'Linus Torvalds',
age: 48,
}, {
name: 'Margaret Hamilton',
age: 81,
}];
it('should return the average age of the users', () => {
expect(computeUserAverageAge(authors)).toBe(62);
});
it('should round the average before returning it', () => {
expect(computeUserAverageAge(computerScientists)).toBe(62);
});
});
});