Skip to content

Commit

Permalink
Changed contentCode to property
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 23, 2024
1 parent 427de6a commit 2da63f1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
9 changes: 5 additions & 4 deletions projects/scuba-physics/src/lib/Gases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,24 +328,25 @@ describe('Gases', () => {
beforeEach(() => {
sut = new Gas(GasMixtures.o2InAir, 0);
});

it('Creation', () => {
sut = new Gas(0.28, 0.27);
expect(sut.contentCode()).toBeCloseTo(28002700);
expect(sut.contentCode).toBeCloseTo(28002700);
});

it('o2 change', () => {
sut.fO2 = 0.32;
expect(sut.contentCode()).toBeCloseTo(32000000);
expect(sut.contentCode).toBeCloseTo(32000000);
});

it('He change', () => {
sut.fHe = 0.48;
expect(sut.contentCode()).toBeCloseTo(20904800);
expect(sut.contentCode).toBeCloseTo(20904800);
});

it('standard gas assignment', () => {
sut.assignStandardGas('Trimix 18/45');
expect(sut.contentCode()).toBeCloseTo(18004500);
expect(sut.contentCode).toBeCloseTo(18004500);
});
});
});
10 changes: 5 additions & 5 deletions projects/scuba-physics/src/lib/Gases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ export class Gas {
return Gas.nameFor(this.fO2, this.fHe);
}

/** Unique identifier of content */
public get contentCode(): number {
return this._contentCode;
}

public set fO2(newValue: number) {
this._fO2 = newValue > 1 ? 1 : newValue;

Expand Down Expand Up @@ -237,11 +242,6 @@ export class Gas {
this._fHe === other._fHe;
}

/** Unique identifier of content */
public contentCode(): number {
return this._contentCode;
}

public assignStandardGas(gasName: string): void {
const found = Gas.byName(gasName);

Expand Down
8 changes: 4 additions & 4 deletions projects/scuba-physics/src/lib/consumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class Consumption {
// add the reserve from opposite order than consumed gas
for (let index = 0; index <= tanks.length - 1; index++) {
const tank = tanks[index];
const gasCode = tank.gas.contentCode();
const gasCode = tank.gas.contentCode;
const consumedLiters = gasesConsumed.get(gasCode);
this.updateTankReserve(tank, index, options, consumedLiters);
const remaining = consumedLiters - (tank.reserve * tank.size);
Expand Down Expand Up @@ -196,7 +196,7 @@ export class Consumption {
// to consumed stages first. This simulates open circuit procedure: First consume, what you can drop.
for (let index = tanks.length - 1; index >= 0; index--) {
const tank = tanks[index];
const gasCode = tank.gas.contentCode();
const gasCode = tank.gas.contentCode;
let remaining = remainToConsume.get(gasCode);
let reallyConsumed = this.consumeFromTank(tank, remaining, minimum);
reallyConsumed = reallyConsumed < 0 ? 0 : reallyConsumed;
Expand All @@ -221,7 +221,7 @@ export class Consumption {
getConsumed: (s: Segment, remaining: number) => number): GasVolumes {
segments.forEach((segment: Segment) => {
if (segment.tank) {
const gasCode = segment.gas.contentCode();
const gasCode = segment.gas.contentCode;
let remaining: number = remainToConsume.get(gasCode);
const consumeLiters = getConsumed(segment, remaining);
let reallyConsumed = this.consumeFromTank(segment.tank, consumeLiters, minimum);
Expand Down Expand Up @@ -256,7 +256,7 @@ export class Consumption {

if (includeSegment(segment)) {
const gas = segment.gas;
const gasCode = gas.contentCode();
const gasCode = gas.contentCode;
const consumedLiters = this.consumedBySegment(segment, rmvSeconds);
let consumedByGas: number = remainToConsume.get(gasCode);
consumedByGas += consumedLiters;
Expand Down
2 changes: 1 addition & 1 deletion projects/scuba-physics/src/lib/consumptionByMix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ConsumedByMix', () => {

it('Groups by Gas', () => {
const expected = [20900000, 32000000];
assertResult(r => r.gas.contentCode(), expected);
assertResult(r => r.gas.contentCode, expected);
});

it('Sums total volume', () => {
Expand Down
2 changes: 1 addition & 1 deletion projects/scuba-physics/src/lib/consumptionByMix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ConsumptionByMix {
* @param tanks with already calculated consumption and reserve
*/
public static combine(tanks: Tank[]): IConsumedMix[] {
return _(tanks).groupBy(t => t.gas.contentCode())
return _(tanks).groupBy(t => t.gas.contentCode)
.map((gasTanks: Tank[]) => {
const gasResult: IConsumedMix = {
gas: gasTanks[0].gas,
Expand Down

0 comments on commit 2da63f1

Please sign in to comment.