Skip to content

Commit

Permalink
add blend-pricing.service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josefbogar committed Sep 24, 2024
1 parent b1aa79b commit b60999b
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions projects/planner/src/app/shared/blend-pricing.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,56 @@ describe('BlendPricingService', () => {
let sut: BlendPricingService;
let gasBlender: GasBlenderService;

const createGasBlenderService = (): GasBlenderService => {
const createGasBlenderService = (imperialUnits: boolean = false): GasBlenderService => {
const units = new UnitConversion();
units.imperialUnits = imperialUnits;
return new GasBlenderService(units);
};

beforeEach(() => {
gasBlender = createGasBlenderService();
sut = new BlendPricingService(gasBlender);

gasBlender.topMix.o2 = 25;
gasBlender.topMix.he = 25;
gasBlender.targetTank.o2 = 25;
gasBlender.targetTank.he = 25;
gasBlender.calculate();

sut.o2UnitPrice = 2;
sut.heUnitPrice = 3;
sut.topMixUnitPrice = 4;
});

it('Calculates prices for for the amount of gas', () => {
it('Calculates gas prices', () => {
sut.calculate();

expect(sut.o2Price).toBeCloseTo(50);
expect(sut.hePrice).toBeCloseTo(75);
expect(sut.topMixPrice).toBeCloseTo(200);
expect(sut.totalPrice).toBeCloseTo(325);
expect(sut.o2Price).toBeCloseTo(5.88235294, 8);
expect(sut.hePrice).toBeCloseTo(150);
expect(sut.topMixPrice).toBeCloseTo(588.2352941176471, 8);
expect(sut.totalPrice).toBeCloseTo(744.1176470576471, 8);
});

describe('Imperial units', () => {
beforeEach(() => {
gasBlender = createGasBlenderService(true);
sut = new BlendPricingService(gasBlender);

gasBlender.targetTank.o2 = 25;
gasBlender.targetTank.he = 25;
gasBlender.calculate();

sut.o2UnitPrice = 2;
sut.heUnitPrice = 3;
sut.topMixUnitPrice = 4;
});

it('Calculates gas prices in imperial units', () => {
sut.calculate();

expect(sut.o2Price).toBeCloseTo(85.31631629483086, 8);
expect(sut.hePrice).toBeCloseTo(2175.5660659533, 8);
expect(sut.topMixPrice).toBeCloseTo(8531.631631189413, 8);
expect(sut.totalPrice).toBeCloseTo(10792.514013437543, 8);
});
});
});

0 comments on commit b60999b

Please sign in to comment.