forked from dgdang97/jax-ftd-day-7-javascript-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
45 lines (42 loc) · 1.46 KB
/
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
/* global describe */
const jsc = require('jsverify')
const { createGrowthModel, averageGrowthModel } = require('./lib')
describe('ftd day 7 javascript kata', function () {
jsc.property(
'#createGrowthModel() creates a correct GrowthModel object',
'number', 'number',
function (lengthToWingspan, leavesEatenToWeight) {
const growthModel = createGrowthModel(lengthToWingspan, leavesEatenToWeight)
return (lengthToWingspan === growthModel.lengthToWingspan &&
leavesEatenToWeight === growthModel.leavesEatenToWeight)
}
)
jsc.property(
'#averageGrowthModel() correctly averages GrowthModel objects',
jsc.array(jsc.record({
lengthToWingspan: jsc.number,
leavesEatenToWeight: jsc.number
})),
function (arr) {
const toCheck = averageGrowthModel(arr)
if (arr.length > 0) {
const summed = arr.reduce(
(acc, next) =>
createGrowthModel(
acc.lengthToWingspan + next.lengthToWingspan,
acc.leavesEatenToWeight + next.leavesEatenToWeight
),
createGrowthModel(0, 0)
)
const average = createGrowthModel(
summed.lengthToWingspan / arr.length,
summed.leavesEatenToWeight / arr.length
)
return (average.lengthToWingspan === toCheck.lengthToWingspan &&
average.leavesEatenToWeight === toCheck.leavesEatenToWeight)
} else {
return toCheck === undefined
}
}
)
})