diff --git a/index.js b/index.js index e5ea0074..878cdd24 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,8 @@ const drugs = [ new Drug("Doliprane", 20, 30), new Drug("Herbal Tea", 10, 5), new Drug("Fervex", 5, 40), - new Drug("Magic Pill", 15, 40) + new Drug("Magic Pill", 15, 40), + new Drug("Dafalgan", 15, 40) ]; const trial = new Pharmacy(drugs); diff --git a/output.txt b/output.txt index d3e0f699..a15536c1 100644 --- a/output.txt +++ b/output.txt @@ -1 +1 @@ -[{"name":"Doliprane","expiresIn":19,"benefit":29},{"name":"Herbal Tea","expiresIn":9,"benefit":6},{"name":"Fervex","expiresIn":4,"benefit":43},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":18,"benefit":28},{"name":"Herbal Tea","expiresIn":8,"benefit":7},{"name":"Fervex","expiresIn":3,"benefit":46},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":17,"benefit":27},{"name":"Herbal Tea","expiresIn":7,"benefit":8},{"name":"Fervex","expiresIn":2,"benefit":49},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":16,"benefit":26},{"name":"Herbal Tea","expiresIn":6,"benefit":9},{"name":"Fervex","expiresIn":1,"benefit":50},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":15,"benefit":25},{"name":"Herbal Tea","expiresIn":5,"benefit":10},{"name":"Fervex","expiresIn":0,"benefit":50},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":14,"benefit":24},{"name":"Herbal Tea","expiresIn":4,"benefit":11},{"name":"Fervex","expiresIn":-1,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":13,"benefit":23},{"name":"Herbal Tea","expiresIn":3,"benefit":12},{"name":"Fervex","expiresIn":-2,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":12,"benefit":22},{"name":"Herbal Tea","expiresIn":2,"benefit":13},{"name":"Fervex","expiresIn":-3,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":11,"benefit":21},{"name":"Herbal Tea","expiresIn":1,"benefit":14},{"name":"Fervex","expiresIn":-4,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":10,"benefit":20},{"name":"Herbal Tea","expiresIn":0,"benefit":15},{"name":"Fervex","expiresIn":-5,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":9,"benefit":19},{"name":"Herbal Tea","expiresIn":-1,"benefit":17},{"name":"Fervex","expiresIn":-6,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":8,"benefit":18},{"name":"Herbal Tea","expiresIn":-2,"benefit":19},{"name":"Fervex","expiresIn":-7,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":7,"benefit":17},{"name":"Herbal Tea","expiresIn":-3,"benefit":21},{"name":"Fervex","expiresIn":-8,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":6,"benefit":16},{"name":"Herbal Tea","expiresIn":-4,"benefit":23},{"name":"Fervex","expiresIn":-9,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":5,"benefit":15},{"name":"Herbal Tea","expiresIn":-5,"benefit":25},{"name":"Fervex","expiresIn":-10,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":4,"benefit":14},{"name":"Herbal Tea","expiresIn":-6,"benefit":27},{"name":"Fervex","expiresIn":-11,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":3,"benefit":13},{"name":"Herbal Tea","expiresIn":-7,"benefit":29},{"name":"Fervex","expiresIn":-12,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":2,"benefit":12},{"name":"Herbal Tea","expiresIn":-8,"benefit":31},{"name":"Fervex","expiresIn":-13,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":1,"benefit":11},{"name":"Herbal Tea","expiresIn":-9,"benefit":33},{"name":"Fervex","expiresIn":-14,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":0,"benefit":10},{"name":"Herbal Tea","expiresIn":-10,"benefit":35},{"name":"Fervex","expiresIn":-15,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-1,"benefit":8},{"name":"Herbal Tea","expiresIn":-11,"benefit":37},{"name":"Fervex","expiresIn":-16,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-2,"benefit":6},{"name":"Herbal Tea","expiresIn":-12,"benefit":39},{"name":"Fervex","expiresIn":-17,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-3,"benefit":4},{"name":"Herbal Tea","expiresIn":-13,"benefit":41},{"name":"Fervex","expiresIn":-18,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-4,"benefit":2},{"name":"Herbal Tea","expiresIn":-14,"benefit":43},{"name":"Fervex","expiresIn":-19,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-5,"benefit":0},{"name":"Herbal Tea","expiresIn":-15,"benefit":45},{"name":"Fervex","expiresIn":-20,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-6,"benefit":0},{"name":"Herbal Tea","expiresIn":-16,"benefit":47},{"name":"Fervex","expiresIn":-21,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-7,"benefit":0},{"name":"Herbal Tea","expiresIn":-17,"benefit":49},{"name":"Fervex","expiresIn":-22,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-8,"benefit":0},{"name":"Herbal Tea","expiresIn":-18,"benefit":50},{"name":"Fervex","expiresIn":-23,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-9,"benefit":0},{"name":"Herbal Tea","expiresIn":-19,"benefit":50},{"name":"Fervex","expiresIn":-24,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}],[{"name":"Doliprane","expiresIn":-10,"benefit":0},{"name":"Herbal Tea","expiresIn":-20,"benefit":50},{"name":"Fervex","expiresIn":-25,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40}] \ No newline at end of file +[{"name":"Doliprane","expiresIn":19,"benefit":29},{"name":"Herbal Tea","expiresIn":9,"benefit":6},{"name":"Fervex","expiresIn":4,"benefit":43},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":14,"benefit":38}],[{"name":"Doliprane","expiresIn":18,"benefit":28},{"name":"Herbal Tea","expiresIn":8,"benefit":7},{"name":"Fervex","expiresIn":3,"benefit":46},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":13,"benefit":36}],[{"name":"Doliprane","expiresIn":17,"benefit":27},{"name":"Herbal Tea","expiresIn":7,"benefit":8},{"name":"Fervex","expiresIn":2,"benefit":49},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":12,"benefit":34}],[{"name":"Doliprane","expiresIn":16,"benefit":26},{"name":"Herbal Tea","expiresIn":6,"benefit":9},{"name":"Fervex","expiresIn":1,"benefit":50},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":11,"benefit":32}],[{"name":"Doliprane","expiresIn":15,"benefit":25},{"name":"Herbal Tea","expiresIn":5,"benefit":10},{"name":"Fervex","expiresIn":0,"benefit":50},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":10,"benefit":30}],[{"name":"Doliprane","expiresIn":14,"benefit":24},{"name":"Herbal Tea","expiresIn":4,"benefit":11},{"name":"Fervex","expiresIn":-1,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":9,"benefit":28}],[{"name":"Doliprane","expiresIn":13,"benefit":23},{"name":"Herbal Tea","expiresIn":3,"benefit":12},{"name":"Fervex","expiresIn":-2,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":8,"benefit":26}],[{"name":"Doliprane","expiresIn":12,"benefit":22},{"name":"Herbal Tea","expiresIn":2,"benefit":13},{"name":"Fervex","expiresIn":-3,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":7,"benefit":24}],[{"name":"Doliprane","expiresIn":11,"benefit":21},{"name":"Herbal Tea","expiresIn":1,"benefit":14},{"name":"Fervex","expiresIn":-4,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":6,"benefit":22}],[{"name":"Doliprane","expiresIn":10,"benefit":20},{"name":"Herbal Tea","expiresIn":0,"benefit":15},{"name":"Fervex","expiresIn":-5,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":5,"benefit":20}],[{"name":"Doliprane","expiresIn":9,"benefit":19},{"name":"Herbal Tea","expiresIn":-1,"benefit":17},{"name":"Fervex","expiresIn":-6,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":4,"benefit":18}],[{"name":"Doliprane","expiresIn":8,"benefit":18},{"name":"Herbal Tea","expiresIn":-2,"benefit":19},{"name":"Fervex","expiresIn":-7,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":3,"benefit":16}],[{"name":"Doliprane","expiresIn":7,"benefit":17},{"name":"Herbal Tea","expiresIn":-3,"benefit":21},{"name":"Fervex","expiresIn":-8,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":2,"benefit":14}],[{"name":"Doliprane","expiresIn":6,"benefit":16},{"name":"Herbal Tea","expiresIn":-4,"benefit":23},{"name":"Fervex","expiresIn":-9,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":1,"benefit":12}],[{"name":"Doliprane","expiresIn":5,"benefit":15},{"name":"Herbal Tea","expiresIn":-5,"benefit":25},{"name":"Fervex","expiresIn":-10,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":0,"benefit":10}],[{"name":"Doliprane","expiresIn":4,"benefit":14},{"name":"Herbal Tea","expiresIn":-6,"benefit":27},{"name":"Fervex","expiresIn":-11,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-1,"benefit":6}],[{"name":"Doliprane","expiresIn":3,"benefit":13},{"name":"Herbal Tea","expiresIn":-7,"benefit":29},{"name":"Fervex","expiresIn":-12,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-2,"benefit":2}],[{"name":"Doliprane","expiresIn":2,"benefit":12},{"name":"Herbal Tea","expiresIn":-8,"benefit":31},{"name":"Fervex","expiresIn":-13,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-3,"benefit":0}],[{"name":"Doliprane","expiresIn":1,"benefit":11},{"name":"Herbal Tea","expiresIn":-9,"benefit":33},{"name":"Fervex","expiresIn":-14,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-4,"benefit":0}],[{"name":"Doliprane","expiresIn":0,"benefit":10},{"name":"Herbal Tea","expiresIn":-10,"benefit":35},{"name":"Fervex","expiresIn":-15,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-5,"benefit":0}],[{"name":"Doliprane","expiresIn":-1,"benefit":8},{"name":"Herbal Tea","expiresIn":-11,"benefit":37},{"name":"Fervex","expiresIn":-16,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-6,"benefit":0}],[{"name":"Doliprane","expiresIn":-2,"benefit":6},{"name":"Herbal Tea","expiresIn":-12,"benefit":39},{"name":"Fervex","expiresIn":-17,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-7,"benefit":0}],[{"name":"Doliprane","expiresIn":-3,"benefit":4},{"name":"Herbal Tea","expiresIn":-13,"benefit":41},{"name":"Fervex","expiresIn":-18,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-8,"benefit":0}],[{"name":"Doliprane","expiresIn":-4,"benefit":2},{"name":"Herbal Tea","expiresIn":-14,"benefit":43},{"name":"Fervex","expiresIn":-19,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-9,"benefit":0}],[{"name":"Doliprane","expiresIn":-5,"benefit":0},{"name":"Herbal Tea","expiresIn":-15,"benefit":45},{"name":"Fervex","expiresIn":-20,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-10,"benefit":0}],[{"name":"Doliprane","expiresIn":-6,"benefit":0},{"name":"Herbal Tea","expiresIn":-16,"benefit":47},{"name":"Fervex","expiresIn":-21,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-11,"benefit":0}],[{"name":"Doliprane","expiresIn":-7,"benefit":0},{"name":"Herbal Tea","expiresIn":-17,"benefit":49},{"name":"Fervex","expiresIn":-22,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-12,"benefit":0}],[{"name":"Doliprane","expiresIn":-8,"benefit":0},{"name":"Herbal Tea","expiresIn":-18,"benefit":50},{"name":"Fervex","expiresIn":-23,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-13,"benefit":0}],[{"name":"Doliprane","expiresIn":-9,"benefit":0},{"name":"Herbal Tea","expiresIn":-19,"benefit":50},{"name":"Fervex","expiresIn":-24,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-14,"benefit":0}],[{"name":"Doliprane","expiresIn":-10,"benefit":0},{"name":"Herbal Tea","expiresIn":-20,"benefit":50},{"name":"Fervex","expiresIn":-25,"benefit":0},{"name":"Magic Pill","expiresIn":15,"benefit":40},{"name":"Dafalgan","expiresIn":-15,"benefit":0}] \ No newline at end of file diff --git a/pharmacy.js b/pharmacy.js index cda44c41..a0079ab6 100644 --- a/pharmacy.js +++ b/pharmacy.js @@ -10,54 +10,66 @@ export class Pharmacy { constructor(drugs = []) { this.drugs = drugs; } + + treatHerbalTea(drug) { + if (drug.expiresIn > 0) { + drug.benefit = drug.benefit <= 49 ? drug.benefit + 1 : 50; + } else { + drug.benefit = drug.benefit <= 48 ? drug.benefit + 2 : 50; + } + drug.expiresIn--; + } + + treatMagicPill(drug) {} + + treatFervex(drug) { + if (drug.expiresIn >= 11) { + drug.benefit = drug.benefit <= 49 ? drug.benefit + 1 : 50; + } else if (drug.expiresIn >= 6 && drug.expiresIn <= 10) { + drug.benefit = drug.benefit <= 48 ? drug.benefit + 2 : 50; + } else if (drug.expiresIn >= 1 && drug.expiresIn <= 5) { + drug.benefit = drug.benefit <= 47 ? drug.benefit + 3 : 50; + } else { + drug.benefit = 0; + } + drug.expiresIn--; + } + + treatDafalgan(drug) { + if (drug.expiresIn > 0) { + drug.benefit = drug.benefit >= 2 ? drug.benefit - 2 : 0; + } else { + drug.benefit = drug.benefit >= 4 ? drug.benefit - 4 : 0; + } + drug.expiresIn--; + } + + treatDefault(drug) { + if (drug.expiresIn > 0) { + drug.benefit = drug.benefit >= 1 ? drug.benefit - 1 : 0; + } else { + drug.benefit = drug.benefit >= 2 ? drug.benefit - 2 : 0; + } + drug.expiresIn--; + } + updateBenefitValue() { - for (var i = 0; i < this.drugs.length; i++) { - if ( - this.drugs[i].name != "Herbal Tea" && - this.drugs[i].name != "Fervex" - ) { - if (this.drugs[i].benefit > 0) { - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].benefit = this.drugs[i].benefit - 1; - } - } - } else { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - if (this.drugs[i].name == "Fervex") { - if (this.drugs[i].expiresIn < 11) { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } - if (this.drugs[i].expiresIn < 6) { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } - } - } - } - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].expiresIn = this.drugs[i].expiresIn - 1; - } - if (this.drugs[i].expiresIn < 0) { - if (this.drugs[i].name != "Herbal Tea") { - if (this.drugs[i].name != "Fervex") { - if (this.drugs[i].benefit > 0) { - if (this.drugs[i].name != "Magic Pill") { - this.drugs[i].benefit = this.drugs[i].benefit - 1; - } - } - } else { - this.drugs[i].benefit = - this.drugs[i].benefit - this.drugs[i].benefit; - } - } else { - if (this.drugs[i].benefit < 50) { - this.drugs[i].benefit = this.drugs[i].benefit + 1; - } - } + for (let drug of this.drugs) { + switch (drug.name) { + case 'Herbal Tea': + this.treatHerbalTea(drug); + break; + case 'Magic Pill': + this.treatMagicPill(drug); + break; + case 'Fervex': + this.treatFervex(drug); + break; + case 'Dafalgan': + this.treatDafalgan(drug); + break; + default: + this.treatDefault(drug); } } diff --git a/pharmacy.test.js b/pharmacy.test.js index f0925fc1..6ef5cfc8 100644 --- a/pharmacy.test.js +++ b/pharmacy.test.js @@ -1,9 +1,152 @@ -import { Drug, Pharmacy } from "./pharmacy"; +import { Drug, Pharmacy } from './pharmacy'; -describe("Pharmacy", () => { - it("should decrease the benefit and expiresIn", () => { - expect(new Pharmacy([new Drug("test", 2, 3)]).updateBenefitValue()).toEqual( - [new Drug("test", 1, 2)] - ); +function testPhar(drugName, expiresIn, benifit, newExpiresIn, newBenifit) { + expect(new Pharmacy([new Drug(drugName, expiresIn, benifit)]).updateBenefitValue()).toEqual([ + new Drug(drugName, newExpiresIn, newBenifit) + ]); +} + +describe('Pharmacy', () => { + describe('Test a normal drug', () => { + describe('When drug not expired', () => { + it('If benefit >= 1 ==> expiresIn -= 1, benefit -= 1 ', () => { + testPhar('Test', 2, 3, 1, 2); + }); + + it('If benefit == 0 ==> expiresIn -= 1, benefit == 0', () => { + testPhar('Test', 2, 0, 1, 0); + }); + }); + + describe('When drug expired', () => { + it('If beneft >= 2 ==> expiresIn -= 1, benefit -= 2', () => { + testPhar('Test', 0, 10, -1, 8); + }); + + it('If benefit ∈ [0, 1] ==> expiresIn -= 1, benefit == 0', () => { + testPhar('Test', 0, 1, -1, 0); + testPhar('Test', 0, 0, -1, 0); + }); + }); + }); + + describe('Test Herbal Tea', () => { + describe('When drug not expired', () => { + it('If benefit <= 49 ==> expiresIn -= 1, benefit += 1', () => { + testPhar('Herbal Tea', 15, 30, 14, 31); + }); + + it('If benefit == 50 ==> expiresIn -= 1, benefit == 50', () => { + testPhar('Herbal Tea', 15, 50, 14, 50); + }); + }); + + describe('When drug expired', () => { + it('If benefit <= 48 ==> expiresIn -= 1, benefit += 2', () => { + testPhar('Herbal Tea', 0, 12, -1, 14); + }); + + it('If benefit ∈ [49, 50] ==> expiresIn -= 1, benefit == 50', () => { + testPhar('Herbal Tea', 0, 49, -1, 50); + testPhar('Herbal Tea', 0, 50, -1, 50); + }); + }); }); + + describe('Test Magic Pill', () => { + it('When expiresIn > 0 ==> expiresIn does not change, benefit does not change', () => { + testPhar('Magic Pill', 12, 33, 12, 33); + }); + + it('When expiresIn == 0 ==> expiresIn does not change, benefit does not change', () => { + testPhar('Magic Pill', 0, 33, 0, 33); + }); + }); + + describe('Test Fervex', () => { + describe('When drug not expired', () => { + describe('If expiresIn >= 11', () => { + it('If benefit <= 49 ==> expiresIn -= 1, benefit += 1', () => { + testPhar('Fervex', 15, 25, 14, 26); + }); + + it('If benefit == 50 ==> expiresIn -= 1, benefit == 50', () => { + testPhar('Fervex', 15, 50, 14, 50); + testPhar('Fervex', 11, 50, 10, 50); + }); + }); + + describe('If expiresIn ∈ [6, 10]', () => { + it('If benefit <= 48 ==> expiresIn -= 1, benefit += 2', () => { + testPhar('Fervex', 10, 15, 9, 17); + testPhar('Fervex', 8, 15, 7, 17); + testPhar('Fervex', 6, 15, 5, 17); + }); + + it('If benefit ∈ [49, 50] ==> expiresIn -= 1, benefit == 50', () => { + testPhar('Fervex', 10, 49, 9, 50); + testPhar('Fervex', 8, 49, 7, 50); + testPhar('Fervex', 6, 49, 5, 50); + + testPhar('Fervex', 10, 50, 9, 50); + testPhar('Fervex', 8, 50, 7, 50); + testPhar('Fervex', 6, 50, 5, 50); + }); + }); + + describe('If expiresIn ∈ [1, 5]', () => { + it('If benefit <= 47 ==> expiresIn -= 1, benefit += 3', () => { + testPhar('Fervex', 5, 30, 4, 33); + testPhar('Fervex', 3, 30, 2, 33); + testPhar('Fervex', 1, 30, 0, 33); + }); + + it('If benefit ∈ [48, 50] ==> expiresIn -= 1, benefit == 50', () => { + testPhar('Fervex', 5, 48, 4, 50); + testPhar('Fervex', 3, 48, 2, 50); + testPhar('Fervex', 1, 48, 0, 50); + + testPhar('Fervex', 5, 49, 4, 50); + testPhar('Fervex', 3, 49, 2, 50); + testPhar('Fervex', 1, 49, 0, 50); + + testPhar('Fervex', 5, 50, 4, 50); + testPhar('Fervex', 3, 50, 2, 50); + testPhar('Fervex', 1, 50, 0, 50); + }); + }); + }); + + describe('When drug expired', () => { + it('benefit should turn to 0', () => { + testPhar('Fervex', 0, 33, -1, 0); + }); + }); + }); + + describe('Test Dafalgan', () => { + describe('When drug not expired', () => { + it('If benefit >= 2 ==> expiresIn -= 1, benefit -= 2', () => { + testPhar('Dafalgan', 15, 20, 14, 18); + }) + + it('If benefit ∈ [0, 1] ==> expiresIn -= 1, benefit == 0', () => { + testPhar('Dafalgan', 15, 1, 14, 0); + testPhar('Dafalgan', 15, 0, 14, 0); + }) + }); + + describe('When drug expired', () => { + it('If benefit >= 4 ==> expiresIn -= 1, benefit -= 4', () => { + testPhar('Dafalgan', 0, 30, -1, 26); + }) + + it('If benefit ∈ [0, 3] ==> expiresIn -= 1, benefit == 0', () => { + testPhar('Dafalgan', 0, 3, -1, 0); + testPhar('Dafalgan', 0, 2, -1, 0); + testPhar('Dafalgan', 0, 1, -1, 0); + testPhar('Dafalgan', 0, 0, -1, 0); + }) + }); + }) });