Skip to content

Commit

Permalink
Simplified pricing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Sep 25, 2024
1 parent f844c55 commit 584dbdc
Showing 1 changed file with 30 additions and 70 deletions.
100 changes: 30 additions & 70 deletions projects/scuba-physics/src/lib/blendPricing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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,
heUnitPrice: 8,
addTop: 4,
topMixUnitPrice: 10
};
});

it('should calculate prices according declared amount and price of gas', () => {
const expected: BlendPrice = {
o2Price: 10,
hePrice: 24,
Expand All @@ -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');
});
});
});
Expand Down

0 comments on commit 584dbdc

Please sign in to comment.