Skip to content

Commit

Permalink
refactor(pharmacy) benefit revaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
mordenius committed Dec 23, 2021
1 parent 1fe169f commit 7969cfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 55 deletions.
7 changes: 4 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Drug, Pharmacy } from "./pharmacy";
import { Linear, DoubleAfterExpires, Reverse, ChangeAcrossExpires, ZeroAfterExpires, Double } from "./revaluations";

import fs from "fs";

const drugs = [
new Drug("Doliprane", 20, 30),
new Drug("Herbal Tea", 10, 5),
new Drug("Fervex", 5, 40),
new Drug("Doliprane", 20, 30, [new Linear(), new DoubleAfterExpires()]),
new Drug("Herbal Tea", 10, 5, [new Linear(), new DoubleAfterExpires(), new Reverse()]),
new Drug("Fervex", 5, 40, [new Linear(), new ChangeAcrossExpires(), new Reverse(), new ZeroAfterExpires()]),
new Drug("Magic Pill", 15, 40)
];
const trial = new Pharmacy(drugs);
Expand Down
61 changes: 9 additions & 52 deletions pharmacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,60 +81,17 @@ export class Drug implements DrugData {
}
}
export class Pharmacy {
constructor(public drugs = []) {
this.drugs = drugs;
constructor(private _drugs: Drug[] = []) {}

public get drugs(): Drug[] {
return [...this._drugs];
}
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;
}
}
}

updateBenefitValue(): Drug[] {
for (const drug of this._drugs) {
drug.benefitRevaluate();
}

return this.drugs;
return [...this._drugs];
}
}

0 comments on commit 7969cfa

Please sign in to comment.