From f0898ee91e32e504eac3b664fa8f79e6c1d0c10f Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 16 May 2019 11:54:38 +0200 Subject: [PATCH] Update jasmine tests --- spec/pab/pab_chute.spec.ts | 12 ++++++++++++ spec/pab/pab_nombre.spec.ts | 2 +- src/pab/pab_chute.ts | 8 ++++++++ src/util/message.ts | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/spec/pab/pab_chute.spec.ts b/spec/pab/pab_chute.spec.ts index 4fe6f25d..2f2f5b59 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 322fb2f7..91365537 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 e7b41568..abc8b914 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 d5f4cacb..8cdaa78e 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 */ -- GitLab