Commit 40763b77 authored by Valentin Le Gauche's avatar Valentin Le Gauche
Browse files

Merge branch '55-creer-un-meetingscenario-sans-une-categorie' into 'master'

Resolve "Pouvoir créer un MeetingScenario sans une certaine catégorie de composants"

Closes #55

See merge request tx-techno-num/impactometre!52
parents c5e09d6a 2e62ed03
......@@ -89,9 +89,9 @@ const transportationMeanSubCategories = {
* Damage categories for meetings
*/
const meetingCategoryDamage = {
HARDWARE: 'HARDWARE',
SOFTWARE: 'SOFTWARE',
JOURNEY: 'JOURNEY'
HARDWARE: 'hardware',
SOFTWARE: 'software',
JOURNEY: 'journey'
}
exports.hourToMinutes = hourToMinutes
......
......@@ -20,7 +20,9 @@ class CategoryDamage {
this._category = category
// Create a hashmap that contains components and their id
this._components = this.arrayToMapComponents(components, category)
this._components = (components !== null)
? this.arrayToMapComponents(components, category)
: new Map()
}
// Getters
......
......@@ -11,16 +11,16 @@ class MeetingDamage {
* It's composed of a Damage component that represents the total damage caused by the meeting
* and of three CategoryDamage objects that repesent the damages caused by all
* the meeting components gathered by category (hardware, software, transport).
* @param {Object[]} hardwareComponents - An array of JSON objects that contain all necessary data to create the hardware components of the meeting.
* @param {Object[]} softwareComponents - An array of JSON objects that contain all necessary data to create the software components of the meeting.
* @param {Object[]} journeyComponents - An array of JSON objects that contain all necessary data to create the transport components of the meeting.
* @param {Object[]} hardware - An array of JSON objects that contain all necessary data to create the hardware components of the meeting.
* @param {Object[]} software - An array of JSON objects that contain all necessary data to create the software components of the meeting.
* @param {Object[]} journey - An array of JSON objects that contain all necessary data to create the transport components of the meeting.
* @see CategoryDamage
*/
constructor ({ hardwareComponents, softwareComponents, journeyComponents }) {
constructor ({ hardware = null, software = null, journey = null }) {
// Create all the category damages linked to the meeting
this._hardwareDamage = new CategoryDamage({ components: hardwareComponents, category: meetingCategoryDamage.HARDWARE })
this._softwareDamage = new CategoryDamage({ components: softwareComponents, category: meetingCategoryDamage.SOFTWARE })
this._journeyDamage = new CategoryDamage({ components: journeyComponents, category: meetingCategoryDamage.JOURNEY })
this._hardwareDamage = new CategoryDamage({ components: hardware, category: meetingCategoryDamage.HARDWARE })
this._softwareDamage = new CategoryDamage({ components: software, category: meetingCategoryDamage.SOFTWARE })
this._journeyDamage = new CategoryDamage({ components: journey, category: meetingCategoryDamage.JOURNEY })
}
// Getters
......
......@@ -21,11 +21,15 @@ class MeetingScenario extends Scenario {
super(user)
this._meetingDuration = meetingDuration
this._numberOfParticipants = numberOfParticipants
this._damage = new MeetingDamage({
hardwareComponents: payload[meetingCategoryDamage.HARDWARE],
softwareComponents: payload[meetingCategoryDamage.SOFTWARE],
journeyComponents: payload[meetingCategoryDamage.JOURNEY]
const params = {}
Object.values(meetingCategoryDamage).forEach(category => {
if (payload[category]) {
params[category] = payload[category]
}
})
this._damage = new MeetingDamage(params)
}
// Getters
......
......@@ -71,9 +71,9 @@ describe('MeetingDamage class', () => {
// Create the MeetingDamage object thnaks to three arrays of JSON object
const meetingDamage = new MeetingDamage({
hardwareComponents: hardwareJSON,
softwareComponents: softwareJSON,
journeyComponents: journeyJSON
hardware: hardwareJSON,
software: softwareJSON,
journey: journeyJSON
})
// Compute the total damage linked to the MeetingDamage object
const totalDamageJSON = {
......
'use strict'
const assert = require('assert')
const chai = require('chai')
const assert = chai.assert
const MeetingScenario = require('../../../../model/classes/meeting/MeetingScenario')
const MeetingDamage = require('../../../../model/classes/meeting/MeetingDamage')
const hardwareDatabase = require('../../../../database/meeting/hardware')
......@@ -12,59 +13,70 @@ const {
} = require('../../../../constants/meeting')
describe('MeetingScenario class', () => {
// The user who creates the meeting
const user = 'vlegauch'
// The meeting duration in minutes
const meetingDuration = 120
// Number of participants
const numberOfParticipants = 4
// The JSON object that enables to creates components linked to the meeting
const payload = {
[meetingCategoryDamage.HARDWARE]: [
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.LAPTOP.name },
{ name: hardwareDatabase.LOGITECH_KIT.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.METAL_STRUCTURE.name }
],
[meetingCategoryDamage.SOFTWARE]: [{ name: softwareDatabase.SKYPE.name }],
[meetingCategoryDamage.JOURNEY]: [
{
passenger: 'Passenger 1',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 1',
mean: transportDatabase.BUS_LARGE_DISTANCE_ONE_PERSON_KM.name,
distance: 40,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 2',
mean: transportDatabase.TRAIN_REGIONAL_ONE_PERSON_KM.name,
distance: 300,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.BIKE_ONE_PERSON_ONE_KM.name,
distance: 10,
numberOfPeople: 1
}
]
}
// Create scenario with missing components in a category
const incompletePayload = Object.assign({}, payload)
delete incompletePayload[meetingCategoryDamage.JOURNEY]
const incompleteScenario = new MeetingScenario({ user, meetingDuration, numberOfParticipants, payload: incompletePayload })
describe('#constructor()', () => {
it('should create a MeetingScenario without components in all categories', () => {
assert.notStrictEqual(incompleteScenario.damage.softwareDamage.components, new Map())
})
})
describe('#computeDamage()', () => {
// The user who creates the meeting
const user = 'vlegauch'
// The meeting duration in minutes
const meetingDuration = 120
// Number of participants
const numberOfParticipants = 4
// The JSON object that enables to creates components linked to the meeting
const payload = {
[meetingCategoryDamage.HARDWARE]: [
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.DESKTOP.name },
{ name: hardwareDatabase.LAPTOP.name },
{ name: hardwareDatabase.LOGITECH_KIT.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.METAL_STRUCTURE.name }
],
[meetingCategoryDamage.SOFTWARE]: [{ name: softwareDatabase.SKYPE.name }],
[meetingCategoryDamage.JOURNEY]: [
{
passenger: 'Passenger 1',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 1',
mean: transportDatabase.BUS_LARGE_DISTANCE_ONE_PERSON_KM.name,
distance: 40,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
},
{
passenger: 'Passenger 2',
mean: transportDatabase.TRAIN_REGIONAL_ONE_PERSON_KM.name,
distance: 300,
numberOfPeople: 1
},
{
passenger: 'Passenger 2',
mean: transportDatabase.BIKE_ONE_PERSON_ONE_KM.name,
distance: 10,
numberOfPeople: 1
}
]
}
// Create the MeetingScenario object
const meetingScenario = new MeetingScenario({ user, meetingDuration, numberOfParticipants, payload })
......@@ -77,9 +89,9 @@ describe('MeetingScenario class', () => {
// Create the expected MeetingDamage object
const meetingDamage = new MeetingDamage({
hardwareComponents: payload[meetingCategoryDamage.HARDWARE],
softwareComponents: payload[meetingCategoryDamage.SOFTWARE],
journeyComponents: payload[meetingCategoryDamage.JOURNEY]
hardware: payload[meetingCategoryDamage.HARDWARE],
software: payload[meetingCategoryDamage.SOFTWARE],
journey: payload[meetingCategoryDamage.JOURNEY]
})
// Compute its total damage
meetingDamage.computeDamage(damagePayload)
......@@ -88,10 +100,27 @@ describe('MeetingScenario class', () => {
meetingScenario.computeDamage(damagePayload)
it('should compute the total damage caused by the meeting', () => {
assert.deepStrictEqual(
meetingScenario.damage.totalDamage,
meetingDamage.totalDamage
)
Object.keys(meetingScenario.damage.totalDamage).forEach(category => {
assert.strictEqual(meetingScenario.damage.totalDamage[category], meetingDamage.totalDamage[category])
assert.isNotNaN(meetingScenario.damage.totalDamage)
assert.isNotNull(meetingScenario.damage.totalDamage)
})
})
it('should compute the damage of an incomplete scenario', () => {
const damagePayload = {
[meetingCategoryDamage.HARDWARE]: { meetingDuration: 120, bound: bounds.UPPER },
[meetingCategoryDamage.SOFTWARE]: { instancesNumber: 5, bandwithBound: bounds.UPPER, networkBound: bounds.UPPER, meetingDuration: 120 },
[meetingCategoryDamage.JOURNEY]: {}
}
incompleteScenario.computeDamage(damagePayload)
const damage = incompleteScenario.damage.totalDamage
const expected = incompleteScenario.damage.hardwareDamage.totalDamage.add(incompleteScenario.damage.softwareDamage.totalDamage)
Object.keys(damage).forEach(category => {
assert.strictEqual(damage[category], expected[category])
assert.isNotNaN(damage[category])
assert.isNotNull(damage[category])
})
})
})
})
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