Commit 5169e14f authored by Matt Glorion's avatar Matt Glorion
Browse files

[DEL] 馃Ч old test files

parent 19d4abac
'use strict';
const assert = require('assert');
const CategoryDamage = require('../../../../model/classes/meeting/CategoryDamage');
const Journey = require('../../../../model/classes/meeting/Journey');
const Hardware = require('../../../../model/classes/meeting/Hardware');
const Software = require('../../../../model/classes/meeting/Software');
const {
meetingCategoryDamage,
bounds
} = require('../../../../constants/meeting');
const transportDatabase = require('../../../../database/meeting/transportationMean');
const softwareDatabase = require('../../../../database/meeting/software');
const hardwareDatabase = require('../../../../database/meeting/hardware');
describe('CategoryDamage class', () => {
describe('#computeDamage()', () => {
// Create the array of JSON objects that enables to create the journey categoryDamage object
const journeyJSON = [
{
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 journey categoryDamage object thanks the array of JSON object and compute
// the total damage of all the jouneys liked to the category damage object
const journeyCategoryDamage = new CategoryDamage({ components: journeyJSON, category: meetingCategoryDamage.JOURNEY });
journeyCategoryDamage.computeDamage();
// Create each Journey object and compute the damage they cause
const journey1 = new Journey({
passenger: 'Passenger 1',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
});
journey1.computeDamage();
const journey2 = new Journey({
passenger: 'Passenger 1',
mean: transportDatabase.BUS_LARGE_DISTANCE_ONE_PERSON_KM.name,
distance: 40,
numberOfPeople: 1
});
journey2.computeDamage();
const journey3 = new Journey({
passenger: 'Passenger 2',
mean: transportDatabase.CAR_ELECTRIC_ONE_KM.name,
distance: 120,
numberOfPeople: 4
});
journey3.computeDamage();
const journey4 = new Journey({
passenger: 'Passenger 2',
mean: transportDatabase.TRAIN_REGIONAL_ONE_PERSON_KM.name,
distance: 300,
numberOfPeople: 1
});
journey4.computeDamage();
const journey5 = new Journey({
passenger: 'Passenger 2',
mean: transportDatabase.BIKE_ONE_PERSON_ONE_KM.name,
distance: 10,
numberOfPeople: 1
});
journey5.computeDamage();
const totalDamage = journey1.damage.add(journey2.damage).add(journey3.damage).add(journey4.damage).add(journey5.damage);
it('should compute the total damage of a journey categoryDamage object', () => {
assert.deepStrictEqual(
journeyCategoryDamage.totalDamage,
totalDamage
);
});
// Create the array of JSON objects that enables to create a software categoryDamage object
const softwareJSON = [{ name: softwareDatabase.SKYPE.name }];
// Create the software categoryDamage object thanks the array of JSON object and compute
// the total damage of all the software liked to the category damage object
const softwareCategoryDamage = new CategoryDamage({ components: softwareJSON, category: meetingCategoryDamage.SOFTWARE });
softwareCategoryDamage.computeDamage({
instancesNumber: 5,
bandwithBound: bounds.UPPER,
networkBound: bounds.UPPER,
meetingDuration: 120
});
// Create each Software object and compute the damage they cause
const skype = new Software({ name: softwareDatabase.SKYPE.name });
skype.computeDamage({
instancesNumber: 5,
bandwithBound: bounds.UPPER,
networkBound: bounds.UPPER,
meetingDuration: 120
});
it('should compute the total damage of a software categoryDamage object', () => {
assert.deepStrictEqual(
softwareCategoryDamage.totalDamage,
skype.damage
);
});
// Create the array of JSON objects that enables to create a software categoryDamage object
const hardwareJSON = [
{ name: hardwareDatabase.LAPTOP.name },
{ name: hardwareDatabase.LOGITECH_KIT.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.TV.name },
{ name: hardwareDatabase.METAL_STRUCTURE.name }
];
const hardwareCategoryDamage = new CategoryDamage({ components: hardwareJSON, category: meetingCategoryDamage.HARDWARE });
hardwareCategoryDamage.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
// Create the hardware categoryDamage object thanks the array of JSON object and compute
// the total damage of all the hardware liked to the category damage object
const laptop = new Hardware({ name: hardwareDatabase.LAPTOP.name });
laptop.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
const logitechKit = new Hardware({ name: hardwareDatabase.LOGITECH_KIT.name });
logitechKit.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
const TV1 = new Hardware({ name: hardwareDatabase.TV.name });
TV1.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
const TV2 = new Hardware({ name: hardwareDatabase.TV.name });
TV2.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
const metalStructure = new Hardware({ name: hardwareDatabase.METAL_STRUCTURE.name });
metalStructure.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
it('should compute the total damage of a hardware categoryDamage object', () => {
assert.deepStrictEqual(
hardwareCategoryDamage.totalDamage,
laptop.damage.add(logitechKit.damage).add(TV1.damage).add(TV2.damage).add(metalStructure.damage)
);
});
});
});
This diff is collapsed.
'use strict';
const chai = require('chai');
const assert = chai.assert;
const transportDatabase = require('../../../../database/meeting/transportationMean');
const TransportationMean = require('../../../../model/classes/meeting/TransportationMean');
const Journey = require('../../../../model/classes/meeting/Journey');
const Damage = require('../../../../model/classes/shared/Damage');
describe('Journey class', () => {
describe('#computeEmbodiedDamage ()', () => {
const electricCar = new TransportationMean({ name: transportDatabase.CAR_ELECTRIC_ONE_KM.name });
const journeyElectricCar3People = new Journey({
passenger: 'Passenger 1',
mean: electricCar.name,
distance: 100,
numberOfPeople: 3
});
const embodiedDamage = new Damage({
humanHealth: electricCar.embodied.humanHealth * 100 / 3,
ecosystemQuality: electricCar.embodied.ecosystemQuality * 100 / 3,
climateChange: electricCar.embodied.climateChange * 100 / 3,
resources: electricCar.embodied.resources * 100 / 3
});
it('the damage of a car journey should be divided by the number of people in the car', () => {
const actual = journeyElectricCar3People.computeEmbodiedDamage();
Object.keys(actual).forEach(category => {
assert.strictEqual(actual[category], embodiedDamage[category]);
assert.isNotNaN(actual[category]);
});
});
it('should return the damage caused by 3 people in a eletric car for one kilometer ', () => {
assert.deepStrictEqual(
journeyElectricCar3People.computeEmbodiedDamage(),
embodiedDamage
);
});
const journeyElectricCar5People = new Journey({
passenger: 'Passenger 2',
mean: electricCar.name,
distance: 100,
numberOfPeople: 5
});
it('two identical journeys except for the number of people should cause different damages ', () => {
const threePeople = journeyElectricCar3People.computeEmbodiedDamage();
const fivePeople = journeyElectricCar5People.computeEmbodiedDamage();
Object.keys(threePeople).forEach(category => {
assert.isBelow(fivePeople[category], threePeople[category]);
assert.isNotNaN(fivePeople[category]);
});
});
const heatCar = new TransportationMean({ name: transportDatabase.CAR_HEAT_ENGINE_ONE_KM.name });
const journeyHeatCar3People = new Journey({
passenger: 'Passenger 2',
mean: heatCar.name,
distance: 100,
numberOfPeople: 3
});
it('a journey by car should be computed by kilometer (not by personKilometer)', () => {
assert.strictEqual(
journeyElectricCar3People.mean.isComputedByPersonKm && journeyHeatCar3People.mean.isComputedByPersonKm,
false
);
});
const intercontinentalPlane = new TransportationMean({ name: transportDatabase.PLANE_INTERCONTINENTAL_ONE_PERSON_KM.name });
const intercontinentalPlaneJourney2People = new Journey({
passenger: 'Passenger 1',
mean: intercontinentalPlane.name,
distance: 1000,
numberOfPeople: 2
});
const intercontinentalPlaneJourney4People = new Journey({
passenger: 'Passenger 2',
mean: intercontinentalPlane.name,
distance: 1000,
numberOfPeople: 4
});
const embodiedDamageIntercontinentalPlane = intercontinentalPlaneJourney2People.computeEmbodiedDamage();
const humanHealth = embodiedDamageIntercontinentalPlane.humanHealth;
const ecosystemQuality = embodiedDamageIntercontinentalPlane.ecosystemQuality;
const climateChange = embodiedDamageIntercontinentalPlane.climateChange;
const resources = embodiedDamageIntercontinentalPlane.resources;
const embodiedDamageTwice = new Damage({
humanHealth,
ecosystemQuality,
climateChange,
resources
});
embodiedDamageTwice.mutate(category => { embodiedDamageTwice[category] *= 2; });
it('a 4 people journey by plane should cause twice the damage of a 2 people journey by plane', () => {
assert.deepStrictEqual(
intercontinentalPlaneJourney4People.computeEmbodiedDamage(),
embodiedDamageTwice
);
});
});
describe('#computeDamage ()', () => {
const highSpeedTrain = new TransportationMean({ name: transportDatabase.TRAIN_HIGH_SPEED_ONE_PERSON_KM.name });
const distance = 300;
const numberOfPeople = 4;
const highSpeedTrainJourney = new Journey({
passenger: 'Passenger 2',
mean: highSpeedTrain.name,
distance,
numberOfPeople
});
highSpeedTrainJourney.computeDamage();
it('the total damage caused by a journey should by equal to its embodied damage', () => {
assert.deepStrictEqual(
highSpeedTrainJourney.damage,
highSpeedTrainJourney.computeEmbodiedDamage()
);
});
});
});
'use strict';
const assert = require('assert');
const CategoryDamage = require('../../../../model/classes/meeting/CategoryDamage');
const MeetingDamage = require('../../../../model/classes/meeting/MeetingDamage');
const transportDatabase = require('../../../../database/meeting/transportationMean');
const hardwareDatabase = require('../../../../database/meeting/hardware');
const softwareDatabase = require('../../../../database/meeting/software');
const {
meetingCategoryDamage,
bounds
} = require('../../../../constants/meeting');
describe('MeetingDamage class', () => {
describe('#computeDamage()', () => {
// Create the array of JSON objects that enables to create the journey components of the meeting
const journeyJSON = [
{
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 corresponding journey CategoryDamage object and compute its total damage
const journeyCategoryDamage = new CategoryDamage({ components: journeyJSON, category: meetingCategoryDamage.JOURNEY });
journeyCategoryDamage.computeDamage();
// Create the array of JSON objects that enables to create the software components of the meeting
const softwareJSON = [{ name: softwareDatabase.SKYPE.name }];
// Create the corresponding software CategoryDamage object and compute its total damage
const softwareCategoryDamage = new CategoryDamage({ components: softwareJSON, category: meetingCategoryDamage.SOFTWARE });
softwareCategoryDamage.computeDamage({ instancesNumber: 5, bandwithBound: bounds.UPPER, networkBound: bounds.UPPER, meetingDuration: 120 });
// Create the array of JSON objects that enables to create the hardware components of the meeting
const hardwareJSON = [
{ 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 }
];
// Create the corresponding software CategoryDamage object and compute its total damage
const hardwareCategoryDamage = new CategoryDamage({ components: hardwareJSON, category: meetingCategoryDamage.HARDWARE });
hardwareCategoryDamage.computeDamage({ meetingDuration: 120, bound: bounds.UPPER });
// Create the MeetingDamage object thnaks to three arrays of JSON object
const meetingDamage = new MeetingDamage({
hardware: hardwareJSON,
software: softwareJSON,
journey: journeyJSON
});
// Compute the total damage linked to the MeetingDamage object
const totalDamageJSON = {
[meetingCategoryDamage.HARDWARE]: { meetingDuration: 120, bound: bounds.UPPER },
[meetingCategoryDamage.SOFTWARE]: { instancesNumber: 5, bandwithBound: bounds.UPPER, networkBound: bounds.UPPER, meetingDuration: 120 },
[meetingCategoryDamage.JOURNEY]: {}
};
meetingDamage.computeDamage(totalDamageJSON);
it('should compute the total damage caused by all the compoments linked to the MeetingDamage object', () => {
assert.deepStrictEqual(
meetingDamage.totalDamage,
hardwareCategoryDamage.totalDamage.add(softwareCategoryDamage.totalDamage).add(journeyCategoryDamage.totalDamage)
);
});
});
});
'use strict';
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');
const transportDatabase = require('../../../../database/meeting/transportationMean');
const softwareDatabase = require('../../../../database/meeting/software');
const meetingScenarios = require('../../../../database/meeting/meetingScenarios');
const {
meetingCategoryDamage,
bounds,
modificationTypes
} = 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 the MeetingScenario object
const meetingScenario = new MeetingScenario({ user, meetingDuration, numberOfParticipants, payload });
// 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()', () => {
// Create the JSON object that enables to compute meeting total damage
const damagePayload = {
[meetingCategoryDamage.HARDWARE]: { meetingDuration: 120, bound: bounds.UPPER },
[meetingCategoryDamage.SOFTWARE]: { instancesNumber: 5, bandwithBound: bounds.UPPER, networkBound: bounds.UPPER, meetingDuration: 120 },
[meetingCategoryDamage.JOURNEY]: {}
};
// Create the expected MeetingDamage object
const meetingDamage = new MeetingDamage({
hardware: payload[meetingCategoryDamage.HARDWARE],
software: payload[meetingCategoryDamage.SOFTWARE],
journey: payload[meetingCategoryDamage.JOURNEY]
});
// Compute its total damage
meetingDamage.computeDamage(damagePayload);
// Compute meeting total damage
meetingScenario.computeDamage(damagePayload);
it('should compute the total damage caused by the meeting', () => {
Object.keys(meetingScenario.damage.totalDamage).forEach(category => {
assert.strictEqual(meetingScenario.damage.totalDamage[category], meetingDamage.totalDamage[category]);
assert.isNotNaN(meetingScenario.damage.totalDamage[category]);
assert.isNotNull(meetingScenario.damage.totalDamage[category]);
assert.notEqual(0, meetingScenario.damage.totalDamage[category]);
});
});
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]);
assert.notEqual(0, damage[category]);
});
});
});
describe('#generateAlternatives()', () => {
it('should create two alternative scenarios', () => {
const oldSize = meetingScenarios.size;
meetingScenario.generateAlternatives();
assert.deepStrictEqual(
meetingScenarios.size,
oldSize + 2
);
});
});
describe('#create()', () => {
// Create the meeting scenario
it('shoud create a meeting scenario and add it the database', () => {
const oldSize = meetingScenarios.size;
MeetingScenario.create({ user, meetingDuration, numberOfParticipants, payload });
assert.deepStrictEqual(
meetingScenarios.size,
oldSize + 1
);
});
});
describe('#read()', () => {
it('should read a meetingScenario thanks to its id', () => {
meetingScenarios.forEach(element => {
const id = element.id;
assert.deepStrictEqual(
MeetingScenario.read(id),
meetingScenarios.get(id)
);
});
});
});
describe('#remove()', () => {
it('should remove a meetingScenario thanks to its id', () => {
meetingScenarios.forEach(element => {
const id = element.id;
MeetingScenario.remove(id);
assert.deepStrictEqual(
meetingScenarios.get(id),
undefined
);
});
});
});
describe('#modify()', () => {
describe('update a component', () => {
it('should update a hardware component caracteristics and its damage value, total hardware category damage value and total meeting damage value', () => {
// old hardware category total damage value
const oldHardwareTotalDamage = meetingScenario.damage.hardwareDamage.totalDamage;
// old meeting total damage value
const oldMeetingTotalDamage = meetingScenario.damage.totalDamage;
for (const [id, component] of meetingScenario.damage.hardwareDamage.components.entries()) {
const payload = {
id,
categoryDamage: meetingCategoryDamage.HARDWARE,
modificationType: modificationTypes.UPDATE,
data: {
name: hardwareDatabase.PROJECTOR.name,
damagePayload: {
meetingDuration: 120,
bound: bounds.UPPER
}
}
};
// old component damage value
const oldDamage = component.damage;
meetingScenario.modify({ payload });
// updated component damage value
const updatedDamage = component.damage;
// updated hardware category total damage value
const updatedHardwareTotalDamage = meetingScenario.damage.hardwareDamage.totalDamage;
// updated meeting total damage value
const updatedMeetingTotalDamage = meetingScenario.damage.totalDamage;
Object.keys(oldDamage).forEach(category => {