diff --git a/spec/pab/pab_chute.spec.ts b/spec/pab/pab_chute.spec.ts index 4fe6f25d757b7b98ccac00f8bbc0a440a2b021e4..2f2f5b5943be7218fe42cfc69fbff14952da8aec 100644 --- a/spec/pab/pab_chute.spec.ts +++ b/spec/pab/pab_chute.spec.ts @@ -25,4 +25,16 @@ describe("Class PabChute: ", () => { pabChuteTest("Z2", 0.5); pabChuteTest("DH", 1.5); + it ("Z1 < Z2 should lead to log error entry", () => { + const prms = new PabChuteParams( + 100, // Cote amont Z1 + 100.5, // Cote aval Z2 + 1.5, // Chute DH + ); + + const nub = new PabChute(prms); + + expect(nub.Calc("DH", 0).log.messages.length).toBeGreaterThan(0); + }); + }); diff --git a/spec/pab/pab_nombre.spec.ts b/spec/pab/pab_nombre.spec.ts index 322fb2f7dcd900e47786fb81291e2d3eb1452ccf..9136553725fb39bdb301f17c33c949d9d40a942b 100644 --- a/spec/pab/pab_nombre.spec.ts +++ b/spec/pab/pab_nombre.spec.ts @@ -53,7 +53,7 @@ describe("Class PabNombre: ", () => { expect(nub.result.getExtraResult("DHR")).toBe(0); }); - it ("non-integer number of basins should throw an error", () => { + it ("non-integer number of basins should lead to log error entry", () => { const prms = new PabNombreParams( 3, // Chute totale DHT 4.5, // Nombre de bassins N diff --git a/src/pab/pab_chute.ts b/src/pab/pab_chute.ts index e7b41568894db60e8c52a34cdc26069c4a373145..abc8b9144f9f52f220a3a6242276626fc796ca0b 100644 --- a/src/pab/pab_chute.ts +++ b/src/pab/pab_chute.ts @@ -3,6 +3,7 @@ import { Nub } from "../nub"; import { ParamCalculability, ParamDefinition, ParamFamily } from "../param/param-definition"; import { ParamDomainValue } from "../param/param-domain"; import { ParamsEquation } from "../param/params-equation"; +import { Message, MessageCode } from "../util/message"; import { Result } from "../util/result"; export class PabChuteParams extends ParamsEquation { @@ -60,6 +61,13 @@ export class PabChute extends Nub { public Equation(sVarCalc: string): Result { let v: number; + if (! [ "Z1", "Z2" ].includes(sVarCalc) && this.prms.Z1.singleValue <= this.prms.Z2.singleValue) { + const m = new Message(MessageCode.ERROR_ELEVATION_ZI_LOWER_THAN_Z2); + m.extraVar.Z1 = this.prms.Z1.singleValue; + m.extraVar.Z2 = this.prms.Z2.singleValue; + return new Result(m); + } + switch (sVarCalc) { case "Z1": v = this.prms.Z2.v + this.prms.DH.v; diff --git a/src/util/message.ts b/src/util/message.ts index d5f4cacb013bf6cc666ace1b4c47f4f251223487..8cdaa78ec234e7667ba8ce00801e1c5cf0541c54 100644 --- a/src/util/message.ts +++ b/src/util/message.ts @@ -43,6 +43,11 @@ export enum MessageCode { */ ERROR_DICHO_FUNCTION_VARIATION, + /** + * la cote amont Z1 est plus basse que la cote aval Z2 + */ + ERROR_ELEVATION_ZI_LOWER_THAN_Z2, + /** * les bornes de l'intervalle d'un ParamDomain sont incorrectes */