Skip to content

Commit

Permalink
Code cleanup in Diver spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 25, 2024
1 parent b0c3d9e commit 3937ce1
Showing 1 changed file with 31 additions and 55 deletions.
86 changes: 31 additions & 55 deletions projects/scuba-physics/src/lib/Diver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,52 @@ import { Diver} from './Diver';
import { Tank} from './Tanks';

describe('Diver', () => {

it('Diver.rmv', () => {
const diver = new Diver(20, 25);
expect(diver.rmv).toBe(20);
});

it('Diver.stressRmv', () => {
const diver = new Diver(20, 30);
expect(diver.stressRmv).toBe(30);
});

it('should correctly change rmv and stressRmv', () => {
describe('Create', () => {
it('Assigns given values', () => {
const diver = new Diver(25, 26);
expect(diver.rmv).toBe(25);
expect(diver.stressRmv).toBe(26);
});

it('Assigns default rmv and stressRmv', () => {
const diver = new Diver();
expect(diver.rmv).toBe(20);
expect(diver.stressRmv).toBe(30);
});

it('Assigns default stress rmv only', () => {
const diver = new Diver(18);
expect(diver.rmv).toBe(18);
expect(diver.stressRmv).toBe(27);
});
});

it('applies rmv and stressRmv', () => {
const diver = new Diver(20, 30);
diver.rmv = 25;
diver.stressRmv = 35;
expect(diver.rmv).toBe(25);
expect(diver.stressRmv).toBe(35);
});

it('should correctly assign default rmv and stressRmv if undefined', () => {
const diver = new Diver(undefined, undefined);
expect(diver.rmv).toBe(Diver.defaultSac);
expect(diver.stressRmv).toBe(Diver.defaultSac * 1.5);
});

it('constructor with default values', () => {
const diver = new Diver();
expect(diver.rmv).toBe(Diver.defaultSac);
expect(diver.stressRmv).toBe(Diver.defaultSac * 1.5);
it('calculates teamStressRmv from stressRmv', () =>{
const diver = new Diver(20, 24);
expect(diver.teamStressRmv).toBe(48);
});

it('constructor with rmv defined only ', () => {
const diver = new Diver(18);
expect(diver.rmv).toBe(18);
expect(diver.stressRmv).toBe(18 * 1.5);
it('calculates gas SAC based on tank size', () => {
const diver = new Diver(12);
const tank = new Tank(10, 200, 21);
expect(diver.gasSac(tank)).toBe(1.2);
});

it('constructor with defined values ', () => {
const diver = new Diver(30,50);
expect(diver.rmv).toBe(30);
expect(diver.stressRmv).toBe(50);
});

it('should correctly calculate teamStressRmv', () =>{
const stressRmv = 30;
const diver = new Diver(20, stressRmv);
expect(diver.teamStressRmv).toBe(60);
});

it('should correctly calculate gas SAC based on tank size', () => {
const diver = new Diver (20, 30);
const tank = new Tank(100, 100, 20);
tank.size = 100;
expect(diver.gasSac(tank)).toBe(0.2);
});

it('should correctly calculate gas SAC based on instance properties', () => {
const diver = new Diver();
const tank = new Tank(100, 100, 20);
expect(diver.gasSac(tank)).toBe(0.2);
});

it('should correctly pass values from Diver instance', () => {
const diver1 = new Diver(30, 45);
it('loadFrom should correctly copy values', () => {
const diver1 = new Diver(22, 45);
const diver2 = new Diver();
diver2.loadFrom(diver1);
expect(diver2.rmv).toBe(30);
expect(diver2.rmv).toBe(22);
expect(diver2.stressRmv).toBe(45);
});

});


0 comments on commit 3937ce1

Please sign in to comment.