From b60999b20dccce54b748daf0ed07182ddce79ccb Mon Sep 17 00:00:00 2001 From: josefbogar <161020900+josefbogar@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:50:30 +0200 Subject: [PATCH] add blend-pricing.service tests --- .../app/shared/blend-pricing.service.spec.ts | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/projects/planner/src/app/shared/blend-pricing.service.spec.ts b/projects/planner/src/app/shared/blend-pricing.service.spec.ts index 6516d2cf..2a582b8e 100644 --- a/projects/planner/src/app/shared/blend-pricing.service.spec.ts +++ b/projects/planner/src/app/shared/blend-pricing.service.spec.ts @@ -6,8 +6,9 @@ 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); }; @@ -15,8 +16,8 @@ describe('BlendPricingService', () => { 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; @@ -24,12 +25,37 @@ describe('BlendPricingService', () => { 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); + }); }); }); +