From 584dbdccab0670097976c787f12e4f0920ac1b60 Mon Sep 17 00:00:00 2001 From: Jiri Pokorny Date: Wed, 25 Sep 2024 23:46:12 +0200 Subject: [PATCH] Simplified pricing tests --- .../src/lib/blendPricing.spec.ts | 100 ++++++------------ 1 file changed, 30 insertions(+), 70 deletions(-) diff --git a/projects/scuba-physics/src/lib/blendPricing.spec.ts b/projects/scuba-physics/src/lib/blendPricing.spec.ts index ba8e7587..540ff89e 100644 --- a/projects/scuba-physics/src/lib/blendPricing.spec.ts +++ b/projects/scuba-physics/src/lib/blendPricing.spec.ts @@ -1,10 +1,10 @@ import { BlendPricing, BlendCosts, BlendPrice } from './blendPricing'; describe('BlendPricing', () => { + let costs: BlendCosts; - it('should calculate prices according declared amount and price of gas', () => { - - const costs: BlendCosts = { + beforeEach(() => { + costs = { addO2: 2, o2UnitPrice: 5, addHe: 3, @@ -12,7 +12,9 @@ describe('BlendPricing', () => { addTop: 4, topMixUnitPrice: 10 }; + }); + it('should calculate prices according declared amount and price of gas', () => { const expected: BlendPrice = { o2Price: 10, hePrice: 24, @@ -25,83 +27,41 @@ describe('BlendPricing', () => { expect(result).toEqual(expected); }); - describe('Negative costs validation', () => { - it('should throw an error for negative addO2', () => { - const negativeCosts: BlendCosts = { - addO2: -1, - o2UnitPrice: 5, - addHe: 3, - heUnitPrice: 8, - addTop: 4, - topMixUnitPrice: 10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('addO2 must be positive number'); + describe('Negative value validation throws an error for', () => { + it('addO2', () => { + costs.addO2 = -1; + + expect(() => BlendPricing.price(costs)).toThrowError('addO2 must be positive number'); }); - it('should throw an error for negative o2UnitPrice', () => { - const negativeCosts: BlendCosts = { - addO2: 2, - o2UnitPrice: -5, - addHe: 3, - heUnitPrice: 8, - addTop: 4, - topMixUnitPrice: 10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('o2UnitPrice must be positive number'); + it('o2UnitPrice', () => { + costs.o2UnitPrice = -5; + + expect(() => BlendPricing.price(costs)).toThrowError('o2UnitPrice must be positive number'); }); - it('should throw an error for negative addHe', () => { - const negativeCosts: BlendCosts = { - addO2: 2, - o2UnitPrice: 5, - addHe: -3, - heUnitPrice: 8, - addTop: 4, - topMixUnitPrice: 10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('addHe must be positive number'); + it('addHe', () => { + costs.addHe = -3; + + expect(() => BlendPricing.price(costs)).toThrowError('addHe must be positive number'); }); - it('should throw an error for negative heUnitPrice', () => { - const negativeCosts: BlendCosts = { - addO2: 2, - o2UnitPrice: 5, - addHe: 3, - heUnitPrice: -8, - addTop: 4, - topMixUnitPrice: 10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('heUnitPrice must be positive number'); + it('heUnitPrice', () => { + costs.heUnitPrice = -8; + + expect(() => BlendPricing.price(costs)).toThrowError('heUnitPrice must be positive number'); }); - it('should throw an error for negative addTop', () => { - const negativeCosts: BlendCosts = { - addO2: 2, - o2UnitPrice: 5, - addHe: 3, - heUnitPrice: 8, - addTop: -4, - topMixUnitPrice: 10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('addTop must be positive number'); + it('addTop', () => { + costs.addTop = -4; + + expect(() => BlendPricing.price(costs)).toThrowError('addTop must be positive number'); }); - it('should throw an error for negative topMixUnitPrice', () => { - const negativeCosts: BlendCosts = { - addO2: 2, - o2UnitPrice: 5, - addHe: 3, - heUnitPrice: 8, - addTop: 4, - topMixUnitPrice: -10 - }; - - expect(() => BlendPricing.price(negativeCosts)).toThrowError('topMixUnitPrice must be positive number'); + it('topMixUnitPrice', () => { + costs.topMixUnitPrice = -10; + + expect(() => BlendPricing.price(costs)).toThrowError('topMixUnitPrice must be positive number'); }); }); });