diff --git a/spec/pab/pab_puissance.spec.ts b/spec/pab/pab_puissance.spec.ts index 63151b2c2cdb21cd14e8a39bf26dc456a79e6f3e..af705d65c61854c1e67205f112e4edd44507d4d9 100644 --- a/spec/pab/pab_puissance.spec.ts +++ b/spec/pab/pab_puissance.spec.ts @@ -7,27 +7,28 @@ import { checkResult } from "../test_func"; function PabPuissanceTest(varTest: string) { describe("Calc(): ", () => { - it("V should be 1", () => { - const prms = new PabPuissanceParams( - 0.3, // Chute entre bassins DH (m) - 0.1, // Débit Q (m3/s) - 0.5, // Volume V (m3) - 588.6 // Puissance dissipée PV (W/m3) - ); - + it(`${varTest} should be ${prms[varTest].v}`, () => { + prms = createPabPuisPrms(); const res: number = prms[varTest].v; - const nub = new PabPuissance(prms); prms[varTest].v = undefined; - checkResult(nub.Calc(varTest, 1e-9), res); }); }); } +function createPabPuisPrms(): PabPuissanceParams { + return new PabPuissanceParams( + 0.3, // Chute entre bassins DH (m) + 0.1, // Débit Q (m3/s) + 0.5, // Volume V (m3) + 588.6 // Puissance dissipée PV (W/m3) + ); +} + +let prms: PabPuissanceParams = createPabPuisPrms(); + describe("Class PabPuissance: ", () => { - // beforeEach(() => { - // }); // beforeAll(() => { // }); PabPuissanceTest("DH"); diff --git a/spec/structure/parallel_structure.spec.ts b/spec/structure/parallel_structure.spec.ts index a0119897ddb44f89f83da796b02f942e158625e3..0d25eed2c43dcc16d195d52a0622b30fd9db09dd 100644 --- a/spec/structure/parallel_structure.spec.ts +++ b/spec/structure/parallel_structure.spec.ts @@ -6,10 +6,15 @@ */ // import { describe, expect, it, xdescribe, xit } from "../mock_jasmine"; -import { MessageCode } from "../../src/index"; +import { CalculatorType } from "../../src/compute-node"; +import { Props } from "../../src/props"; +import { Session } from "../../src/session"; +import { CreateStructure } from "../../src/structure/factory_structure"; import { ParallelStructure } from "../../src/structure/parallel_structure"; import { ParallelStructureParams } from "../../src/structure/parallel_structure_params"; import { StructureKivi, StructureKiviParams } from "../../src/structure/structure_kivi"; +import { LoiDebit } from "../../src/structure/structure_props"; +import { MessageCode } from "../../src/util/message"; import { Result } from "../../src/util/result"; import { precDigits } from "../test_config"; import { checkResult } from "../test_func"; @@ -133,4 +138,18 @@ describe("Class ParallelStructure: ", () => { expect(ps3.CalcSerie().vCalc).toBeCloseTo(101.57, 2); }); }); + describe("#116 Pas de calcul de Z2 sur loi dénoyée", () => { + it("Calc(Z2) should return an error", () => { + // Create Parallel Structure with default parameters + const ps4 = Session.getInstance().createNub( + new Props({calcType: CalculatorType.ParallelStructure}) + ) as ParallelStructure; + // Add Free flow weir + ps4.addChild(CreateStructure(LoiDebit.WeirFree)); + // Define Z2 to calculate + ps4.calculatedParam = ps4.prms.Z2; + + expect(ps4.CalcSerie().ok).toBeFalsy(); + }); + }); }); diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 377aac3f184b242dc3855b10b8e6685d26d0d893..db7a38f76493bbd8630196bd6bc659ec3f83d432 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -516,7 +516,7 @@ export class Dichotomie extends Debug { tolAct = 1e-15 * Math.abs(b) + errorTol / 2; newStep = (c - b) / 2; - if (Math.abs(newStep) <= tolAct || fb === 0) { + if (Math.abs(newStep) <= tolAct && Math.abs(fb) < 0.1) { return b; // Acceptable approx. is found }