Skip to content

Commit

Permalink
✨: Add Dafalgan implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Coniface committed Jun 11, 2022
1 parent 26d004e commit 095c48a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/model/drug/__snapshots__/dafalgan.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Dafalgan should be serializable to JSON 1`] = `
Object {
"benefit": 5,
"expiresIn": 30,
"name": "Dafalgan",
}
`;

exports[`Dafalgan should be serializable to string 1`] = `"{\\"name\\":\\"Dafalgan\\",\\"expiresIn\\":30,\\"benefit\\":5}"`;

exports[`Dafalgan should decrease benefit twice as much if expired 1`] = `
Object {
"benefit": 1,
"expiresIn": -1,
"name": "Dafalgan",
}
`;

exports[`Dafalgan should decrease expiresIn and benefit over time 1`] = `
Object {
"benefit": 3,
"expiresIn": 29,
"name": "Dafalgan",
}
`;

exports[`Dafalgan should not allow for a benefit greater than 50 1`] = `
Object {
"benefit": 50,
"expiresIn": 30,
"name": "Dafalgan",
}
`;

exports[`Dafalgan should not allow for a negative benefit 1`] = `
Object {
"benefit": 0,
"expiresIn": 30,
"name": "Dafalgan",
}
`;
44 changes: 44 additions & 0 deletions src/model/drug/dafalgan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Dafalgan } from './dafalgan';

describe('Dafalgan', () => {
let dafalgan: Dafalgan;

beforeEach(() => {
dafalgan = new Dafalgan(30, 5);
});

it('should not allow for a negative benefit', () => {
dafalgan.benefit = -5;
expect(dafalgan).toMatchSnapshot();
});

it('should not allow for a benefit greater than 50', () => {
dafalgan.benefit = 51;
expect(dafalgan).toMatchSnapshot();
});

it('should return expiration status', () => {
expect(dafalgan.isExpired()).toBe(false);
dafalgan.expiresIn = 0;
expect(dafalgan.isExpired()).toBe(true);
});

it('should decrease expiresIn and benefit over time', () => {
dafalgan.updateValues();
expect(dafalgan).toMatchSnapshot();
});

it('should decrease benefit twice as much if expired', () => {
dafalgan.expiresIn = 0;
dafalgan.updateValues();
expect(dafalgan).toMatchSnapshot();
});

it('should be serializable to JSON', () => {
expect(dafalgan.toJSON()).toMatchSnapshot();
});

it('should be serializable to string', () => {
expect(dafalgan.toString()).toMatchSnapshot();
});
});
15 changes: 15 additions & 0 deletions src/model/drug/dafalgan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DrugName } from '../../type/DrugName';
import { Drug } from './drug';

export class Dafalgan extends Drug {
constructor(expiresIn: number, benefit: number) {
super(DrugName.DAFALGAN, expiresIn, benefit);
}

public updateValues(): this {
this.benefit -= this.isExpired() ? 4 : 2;
this.expiresIn -= 1;

return this;
}
}
1 change: 1 addition & 0 deletions src/type/DrugName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum DrugName {
DAFALGAN = 'Dafalgan',
DOLIPRANE = 'Doliprane',
HERBAL_TEA = 'Herbal Tea',
FERVEX = 'Fervex',
Expand Down

0 comments on commit 095c48a

Please sign in to comment.