Commit 5545616c authored by Clement Brizard's avatar Clement Brizard
Browse files

feat: add test for embodied assimilated to another one

parent 26940bac
......@@ -173,7 +173,7 @@ const hardware = {
french: 'micro',
category: meetingComponents.HARDWARE,
isSizeDependent: false,
embodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1',
embodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
// source: Jabra Speak 410 - https://www.jabra.fr/business/speakerphones/jabra-speak-series/jabra-speak-410#/#7410-209
weight: 180.3,
operatingOneMinVisio: {
......
......@@ -35,11 +35,13 @@ class Hardware extends Component {
this._name = json.name
this._quantity = quantity
this._size = size
this._weight = json.weight
this._shareForVisio = shareForVisio
this._isSizeDependent = json.isSizeDependent
this._embodiedAssimilatedTo = json.embodiedAssimilatedTo
this._embodied = (json.embodiedAssimilatedTo)
? hardwareDatabase[json.embodiedAssimilatedTo.embodied]
? hardwareDatabase[json.embodiedAssimilatedTo].embodied
: json.embodied
this._operatingOneMinVisio = json.operatingOneMinVisio
......@@ -98,6 +100,10 @@ class Hardware extends Component {
return this._size
}
get weight () {
return this._weight
}
/**
* Get the optional weight. Useful if the embodied
* damage is assilimated to the damage of 1g of another
......@@ -129,6 +135,10 @@ class Hardware extends Component {
return this._isSizeDependent
}
get embodiedAssimilatedTo () {
return this._embodiedAssimilatedTo
}
/**
* Get the optional hardware name to which the current
* hardware's embodied damage is assimilated to.
......@@ -217,6 +227,10 @@ class Hardware extends Component {
this._size = size
}
set weight (weight) {
this._weight = weight
}
set shareForVisio (shareForVisio) {
this._shareForVisio = shareForVisio
}
......@@ -346,6 +360,30 @@ class Hardware extends Component {
) {
// Damage is for visio time
damageType = hardwareDamageTypes.EMBODIED
// Embodied damage may be assimilated to the one of another hardware
if (this.embodiedAssimilatedTo) {
/* Assimilated emmbodied is for 1 g, so we have to multiply
it by the weight of our hardware */
let weight
// Get weight specific value if available
if (this.weight.upper && this.weight.lower) {
weight = (bound != null)
? this.weight[bound]
: this.weight[bounds.UPPER]
} else {
weight = this.weight
}
const weightEmbodied = this.embodied
Object.keys(weightEmbodied).map(category => {
weightEmbodied[category] *= weight
})
return weightEmbodied
}
}
if (!this[damageType]) {
......
......@@ -91,7 +91,20 @@ describe('Hardware class', () => {
assert.deepStrictEqual(expected, component._components)
})
it('should create a hardware for all hardwares which embodied is assimilated to another one', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
assert.deepStrictEqual(
instance.embodied,
hardwareDatabase[json.embodiedAssimilatedTo].embodied
)
})
})
})
describe('#computeVisioOrStandbyTimeOverLife()', () => {
describe('operating', () => {
const hardwaresWithKnownOperatingTime = Object.keys(knownOperatingTimeOverLife)
......@@ -261,7 +274,7 @@ describe('Hardware class', () => {
}
Object.values(hardwareDatabase).filter(json => {
return (!json[damageType])
return (!json[damageType] && !json.embodiedAssimilatedTo)
}).forEach(json => {
const component = new Hardware({ name: json.name })
assert.strictEqual(
......@@ -271,6 +284,31 @@ describe('Hardware class', () => {
})
})
})
it('should get assimilated embodied damages', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
const weight = (json.weight.upper && json.weight.lower)
? json.weight.upper
: json.weight
console.log(hardwareDatabase.ASSIMILATION_COMPUTER_TOWER_1G)
const expected = hardwareDatabase[json.embodiedAssimilatedTo].embodied
Object.keys(expected).map(category => {
expected[category] *= weight
})
assert.deepStrictEqual(
instance.getTypedDamage(hardwareDamageTypes.EMBODIED_VISIO),
expected
)
Object.values(expected).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
it('should return the unique available value', () => {
Object.values(hardwareDamageTypes).forEach(damageType => {
if (
......@@ -382,7 +420,7 @@ describe('Hardware class', () => {
Object.values(hardwareDatabase)
.filter(json => {
return (
!json[damageType] &&
!json[damageType] && !json.embodiedAssimilatedTo &&
!(
Array.isArray(json.components) &&
json.components.length
......@@ -469,6 +507,30 @@ describe('Hardware class', () => {
})
})
})
it('should compute assimilated embodied damages', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
const weight = (json.weight.upper && json.weight.lower)
? json.weight.upper
: json.weight
const expected = hardwareDatabase[json.embodiedAssimilatedTo].embodied
Object.keys(expected).map(category => {
expected[category] *= weight
})
assert.deepStrictEqual(
instance.getTypedDamage(hardwareDamageTypes.EMBODIED_VISIO),
expected
)
Object.values(expected).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
it('should compute the damage of a composite hardware', () => {
Object.values(hardwareDamageTypes).forEach(damageType => {
Object.values(hardwareDatabase)
......
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