Commit 41302cd1 authored by Clement Brizard's avatar Clement Brizard
Browse files

test: fix and add new ones

parent e25d7ef7
......@@ -19,9 +19,11 @@ describe('Hardware class', () => {
describe('#constructor()', () => {
it('should create an Hardware instance for each non-composite hardware', () => {
Object.values(hardwareDatabase).filter(json => {
return !(
Array.isArray(json.components) &&
json.components.length
return (
// Either there is no components key
!json.components ||
// Either the value is an empty object
Object.keys(json.components).length === 0
)
}).forEach(json => {
const instance = new Hardware({ name: json.name })
......@@ -31,17 +33,17 @@ describe('Hardware class', () => {
it('should create an Hardware instance for each composite hardware', () => {
Object.values(hardwareDatabase).filter(json => {
return (
Array.isArray(json.components) &&
json.components.length
json.components &&
Object.keys(json.components).length !== 0
)
}).forEach(json => {
const instance = new Hardware({ name: json.name })
// Compute expected components
const expected = {}
json.components.forEach(name => {
expected[name] = new Hardware({ name })
})
for (const [name, quantity] of Object.entries(json.components)) {
expected[name] = new Hardware({ name, quantity })
}
assert.deepStrictEqual(expected, instance._components)
})
......@@ -517,5 +519,50 @@ describe('Hardware class', () => {
assert.isAbove(defaultBound[category], lowerBound[category])
})
})
it('should compute the damage of a composite hardware with x instances of the same component (x > 1)', () => {
const json = hardwareDatabase.LOGITECH_KIT
const instance = new Hardware({ name: json.name })
// Compute expected damage
const expected = new Damage()
for (const [name, quantity] of Object.entries(json.components)) {
const component = new Hardware({ name, quantity: 1 })
const damage = component.computeDamage(meetingDuration)
expected.add(damage.mutate(category => {
return damage[category] * quantity
}))
}
const actual = instance.computeDamage(meetingDuration)
assert.deepStrictEqual(actual, expected)
Object.values(actual).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
it('should compute the damage of each composite hardware', () => {
Object.values(hardwareDatabase).filter(json => {
return (
json.components &&
Object.keys(json.components).length !== 0
)
}).forEach(json => {
const instance = new Hardware({ name: json.name })
// Compute expected damage
const expected = new Damage()
for (const [name, quantity] of Object.entries(json.components)) {
const component = new Hardware({ name, quantity })
expected.add(component.computeDamage(meetingDuration))
}
const actual = instance.computeDamage(meetingDuration)
assert.deepStrictEqual(actual, expected)
Object.values(actual).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment