-
Notifications
You must be signed in to change notification settings - Fork 2k
/
codegrade_mvp1.test.js
187 lines (173 loc) · 6.84 KB
/
codegrade_mvp1.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
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
import functions from './index';
const zooAnimals = [
{ animal_name: "Jackal, asiatic", population: 5, scientific_name: "Canis aureus", state: "Kentucky" },
{ animal_name: "Screamer, southern", population: 1, scientific_name: "Chauna torquata", state: "Alabama" },
{ animal_name: "White spoonbill", population: 8, scientific_name: "Platalea leucordia", state: "Georgia" },
{ animal_name: "White-cheeked pintail", population: 1, scientific_name: "Anas bahamensis", state: "Oregon" },
{ animal_name: "Black-backed jackal", population: 2, scientific_name: "Canis mesomelas", state: "Washington" },
{ animal_name: "Brolga crane", population: 9, scientific_name: "Grus rubicundus", state: "New Mexico" },
{ animal_name: "Common melba finch", population: 5, scientific_name: "Pytilia melba", state: "Pennsylvania" },
{ animal_name: "Pampa gray fox", population: 10, scientific_name: "Pseudalopex gymnocercus", state: "Connecticut" },
{ animal_name: "Hawk-eagle, crowned", population: 10, scientific_name: "Spizaetus coronatus", state: "Florida" },
{ animal_name: "Australian pelican", population: 5, scientific_name: "Pelecanus conspicillatus", state: "West Virginia" },
];
//closures
describe('summation', ()=>{
it('summation returns a number. Review for loops and how to increment values after each iteration of the for loop', ()=>{
expect(functions.summation(4)).toBe(10);
})
it('summation returns a number. Review for loops and how to increment values after each iteration of the for loop', ()=>{
expect(functions.summation(10)).toBe(55);
})
});
//callbacks and array methods
describe('fooFunction', ()=>{
it('foo returns foo', ()=>{
expect(functions.foo()).toBe('bar');
})
});
describe('animalNames', ()=>{
it('animalNames returns an array. Review the for each array method', ()=>{
expect(functions.animalNames(zooAnimals)).toEqual(expect.arrayContaining(
["name: Jackal, asiatic, scientific: Canis aureus", "name: Screamer, southern, scientific: Chauna torquata", "name: White spoonbill, scientific: Platalea leucordia", "name: White-cheeked pintail, scientific: Anas bahamensis", "name: Black-backed jackal, scientific: Canis mesomelas", "name: Brolga crane, scientific: Grus rubicundus", "name: Common melba finch, scientific: Pytilia melba", "name: Pampa gray fox, scientific: Pseudalopex gymnocercus", "name: Hawk-eagle, crowned, scientific: Spizaetus coronatus", "name: Australian pelican, scientific: Pelecanus conspicillatus"]
));
})
});
describe('lowerCaseNames', ()=>{
it('lowerCaseNames returns an array. Review the map array method', ()=>{
expect(functions.lowerCaseNames(zooAnimals)).toEqual(expect.arrayContaining(
[
'jackal, asiatic',
'screamer, southern',
'white spoonbill',
'white-cheeked pintail',
'black-backed jackal',
'brolga crane',
'common melba finch',
'pampa gray fox',
'hawk-eagle, crowned',
'australian pelican'
]
));
})
});
describe('lowPopulationAnimals', ()=>{
it('lowPopulationAnimals returns an array. Review the filter array method', ()=>{
expect(functions.lowPopulationAnimals(zooAnimals)).toEqual(
[
{
animal_name: 'Screamer, southern',
population: 1,
scientific_name: 'Chauna torquata',
state: 'Alabama'
},
{
animal_name: 'White-cheeked pintail',
population: 1,
scientific_name: 'Anas bahamensis',
state: 'Oregon'
},
{
animal_name: 'Black-backed jackal',
population: 2,
scientific_name: 'Canis mesomelas',
state: 'Washington'
}
]
);
})
});
describe('USApop', ()=>{
it('USApop returns a number. Review the reduce array method', ()=>{
expect(functions.USApop(zooAnimals)).toEqual(56);
})
});
describe('consume', ()=>{
it('consume returns a number. Review callback functions', ()=>{
expect(functions.consume(2, 5, functions.add)).toBe(7);
})
it('consume returns a string. Review callback functions', ()=>{
expect(functions.consume('John', 'Doe', functions.greeting)).toBe(`Hello John Doe, nice to meet you!`);
})
});
describe('add', ()=>{
it('add returns a number. Review callback functions and math operations', ()=>{
expect(functions.add(2,5)).toBe(7);
})
});
describe('multiply', ()=>{
it('multiply returns a number. Review callback functions and math operations', ()=>{
expect(functions.multiply(2,5)).toBe(10);
})
});
describe('greeting', ()=>{
it('greeting returns a string. Review Template literals', ()=>{
expect(functions.greeting('Jane', 'Doe')).toBe(`Hello Jane Doe, nice to meet you!`);
})
});
// prototypes
describe('Instance of CuboidMaker', () => {
let cuboid
beforeEach(() => {
cuboid = new functions.CuboidMaker({
length: 4,
width: 5,
height:5,
})
})
it('[1] initializes with length.', () => {
console.log(cuboid);
expect(cuboid.length).toBe(4)
})
it('[2] initializes with the width', () => {
expect(cuboid.width).toBe(5)
})
it('[3] initializes with an empty height', () => {
expect(cuboid.height).toBe(5)
})
it('[4] has volume and surfaceArea methods', () => {
expect(cuboid.__proto__.volume).toBeDefined()
expect(cuboid.__proto__.surfaceArea).toBeDefined()
})
it('[5] has a volume', () => {
const vol = cuboid.volume()
expect(vol).toBe(100)
})
it('[5] has a surface', () => {
const sur = cuboid.surfaceArea()
expect(sur).toBe(130)
})
})
//classes
describe('Instance of CuboidMakerTwo', () => {
let cuboidTwo
beforeEach(() => {
cuboidTwo = new functions.CuboidMakerTwo({
length: 4,
width: 5,
height:5,
})
})
it('[1] initializes with length', () => {
console.log(cuboidTwo);
expect(cuboidTwo.length).toBe(4)
})
it('[2] initializes with the width', () => {
expect(cuboidTwo.width).toBe(5)
})
it('[3] initializes with an empty height', () => {
expect(cuboidTwo.height).toBe(5)
})
it('[4] has volume and surfaceArea methods', () => {
expect(cuboidTwo.__proto__.volume).toBeDefined()
expect(cuboidTwo.__proto__.surfaceArea).toBeDefined()
})
it('[5] has a volume', () => {
const vol = cuboidTwo.volume()
expect(vol).toBe(100)
})
it('[5] has a surface', () => {
const sur = cuboidTwo.surfaceArea()
expect(sur).toBe(130)
})
})