Skip to content

Commit

Permalink
Merge pull request #9 from josefbogar/newTestDiver2
Browse files Browse the repository at this point in the history
New diver tests
  • Loading branch information
jirkapok authored Aug 23, 2024
2 parents e53267b + 1ef108c commit e7417c2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"**/*{.,-,_}{test,spec}.{ts,js}",
"**/{test,spec}{.,-,_}*.{ts,js}"
],
}
}
25 changes: 25 additions & 0 deletions projects/planner/src/app/shared/IgnoredIssues.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { EventType } from 'scuba-physics';
import { ApplicationSettingsService } from './ApplicationSettings';
import { IgnoredIssuesService } from './IgnoredIssues.service';
import { UnitConversion } from './UnitConversion';

describe('IgnoredIssuesService', () => {
let appSettings: ApplicationSettingsService;
let service: IgnoredIssuesService;
let unitConversion: UnitConversion;

beforeEach(() => {
unitConversion = new UnitConversion();
appSettings = new ApplicationSettingsService(unitConversion);
service = new IgnoredIssuesService(appSettings);
});

describe('ignoredIssues', () => {
it('should add switchToHigherN2 to ignoredIssues when icdIgnored is true', () => {
appSettings.settings.icdIgnored = true;
const ignoredIssues = service.getIgnoredIssues();

expect(ignoredIssues).toContain(EventType.switchToHigherN2);
});
});
});
77 changes: 77 additions & 0 deletions projects/scuba-physics/src/lib/Diver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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', () => {
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('constructor with rmv defined only ', () => {
const diver = new Diver(18);
expect(diver.rmv).toBe(18);
expect(diver.stressRmv).toBe(18 * 1.5);
});

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);
const diver2 = new Diver();
diver2.loadFrom(diver1);
expect(diver2.rmv).toBe(30);
expect(diver2.stressRmv).toBe(45);
});

});


0 comments on commit e7417c2

Please sign in to comment.