diff --git a/spec/base.spec.ts b/spec/base.spec.ts index 1c61ec68a92c1d931d2e99808a52641cf607d764..8f000e314ed60a88683806e034715737068bea87 100644 --- a/spec/base.spec.ts +++ b/spec/base.spec.ts @@ -1,6 +1,7 @@ /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { nub, precDigits } from "./nubtest"; +import { nub } from "./nubtest"; +import { precDigits } from "./test_config"; import { Message, MessageCode, MessageSeverity } from "../src/util/message"; diff --git a/spec/cond_distri.spec.ts b/spec/cond_distri.spec.ts index fc6fe224613958965102662f411285cfe3546043..ec93042b6fc3ea956a7f7bba38bba3c3e1ad3be5 100644 --- a/spec/cond_distri.spec.ts +++ b/spec/cond_distri.spec.ts @@ -1,13 +1,8 @@ // tslint:disable-next-line:no-reference /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../src/util/result"; import { ConduiteDistrib, ConduiteDistribParams } from "../src/cond_distri"; -import { equalEpsilon } from "./nubtest"; - -function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBe(true); -} +import { checkResult } from "./test_func"; describe("Class ConduiteDistrib: ", () => { // beforeEach(() => { @@ -26,7 +21,7 @@ describe("Class ConduiteDistrib: ", () => { const nub = new ConduiteDistrib(prms); - check(nub.Calc("Q"), 9.393); + checkResult(nub.Calc("Q"), 9.393); }); }); @@ -45,7 +40,7 @@ describe("Class ConduiteDistrib: ", () => { nub.prms.Lg.v = 10; nub.prms.Nu.v = 1e-6; - check(nub.Calc("Q"), 152.992); + checkResult(nub.Calc("Q"), 152.992); }); }); @@ -60,7 +55,7 @@ describe("Class ConduiteDistrib: ", () => { const nub = new ConduiteDistrib(prms); - check(nub.Calc("D"), 2.12847); + checkResult(nub.Calc("D"), 2.12847); }); }); @@ -75,7 +70,7 @@ describe("Class ConduiteDistrib: ", () => { const nub = new ConduiteDistrib(prms); - check(nub.Calc("J"), 0.00814); + checkResult(nub.Calc("J"), 0.00814); }); }); @@ -90,7 +85,7 @@ describe("Class ConduiteDistrib: ", () => { const nub = new ConduiteDistrib(prms); - check(nub.Calc("Lg"), 737.021); + checkResult(nub.Calc("Lg"), 737.021); }); }); @@ -105,7 +100,7 @@ describe("Class ConduiteDistrib: ", () => { const nub = new ConduiteDistrib(prms); - check(nub.Calc("Nu"), 0.00295); + checkResult(nub.Calc("Nu"), 0.00295); }); }); }); diff --git a/spec/lechaptcalmon.spec.ts b/spec/lechaptcalmon.spec.ts index 076c66e1ff0f5e0f5ac7600dcf1c85980aae3fd8..573a60b30c29efdb56db7621683806713f973442 100644 --- a/spec/lechaptcalmon.spec.ts +++ b/spec/lechaptcalmon.spec.ts @@ -1,16 +1,11 @@ /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../src/util/result"; -import { equalEpsilon } from "./nubtest"; import { LechaptCalmonParams, LechaptCalmon } from "../src/lechaptcalmon" +import { checkResult } from "./test_func"; let lechapt: LechaptCalmon; let prms: LechaptCalmonParams; -function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBe(true); -} - describe('Class LechaptCalmon : ', () => { describe('Calc() : ', () => { it('Q should be 2.917', () => { @@ -24,7 +19,7 @@ describe('Class LechaptCalmon : ', () => { ); lechapt = new LechaptCalmon(prms); - check(lechapt.Calc("Q"), 2.917); + checkResult(lechapt.Calc("Q"), 2.917); }); it('D should be 1.213', () => { @@ -38,7 +33,7 @@ describe('Class LechaptCalmon : ', () => { ); lechapt = new LechaptCalmon(prms); - check(lechapt.Calc("D"), 1.213); + checkResult(lechapt.Calc("D"), 1.213); }); it('J should be 0.634', () => { @@ -52,7 +47,7 @@ describe('Class LechaptCalmon : ', () => { ); lechapt = new LechaptCalmon(prms); - check(lechapt.Calc("J"), 0.634); + checkResult(lechapt.Calc("J"), 0.634); }); it('Lg should be 94.565', () => { @@ -66,7 +61,7 @@ describe('Class LechaptCalmon : ', () => { ); lechapt = new LechaptCalmon(prms); - check(lechapt.Calc("Lg"), 94.565); + checkResult(lechapt.Calc("Lg"), 94.565); }); }); }); diff --git a/spec/mock_jasmine.ts b/spec/mock_jasmine.ts index 134851d5b0d9379cf18827c8a3728af29e8315ab..acb2b503f4896e06cc625e3af4e671d86f6a8d80 100644 --- a/spec/mock_jasmine.ts +++ b/spec/mock_jasmine.ts @@ -63,7 +63,10 @@ class Expect { * @param expected Objet de référence */ public toBe(expected: any) { - return this.actual === expected; + const res = this.actual === expected; + if (!res) + console.error("Error : expected " + this.actual + " to be " + expected); + return res; } /** @@ -71,9 +74,29 @@ class Expect { * @param expected Objet de référence */ public toEqual(expected: any) { - return this.actual === expected; + const res = this.actual === expected; + if (!res) + console.error("Error : expected " + this.actual + " to be equal to " + expected); + return res; } + /** + * Mock de la fonction toBeTruthy de Jasmine : the actual value should be true + * @param message message d'erreur + */ + public toBeTruthy(message: string) { + if (!this.actual) + console.error(message); + } + + /** + * Mock de la fonction toBeFalsy de Jasmine : the actual value should be false + * @param message message d'erreur + */ + public toBeFalsy(message: string) { + if (this.actual) + console.error(message); + } } /** diff --git a/spec/nubtest.ts b/spec/nubtest.ts index ef4affddfd3b37eb7b9e7c7c95e65b9f856a3b20..5ed87f706f82a99ead44bb06a76fc33ac4d3bb5f 100644 --- a/spec/nubtest.ts +++ b/spec/nubtest.ts @@ -1,10 +1,6 @@ import { Result } from "../src/util/result"; import { Nub } from "../src/nub"; -import { - ComputeNodeType, ParamCalculability, ParamDefinition, ParamDomain, ParamDomainValue, ParamsEquation, - } from "../src/param"; -import { cLog } from "../src/util/log"; -import { Message, MessageCode } from "../src/util/message"; +import { ComputeNodeType, ParamCalculability, ParamDefinition, ParamDomainValue, ParamsEquation } from "../src/param"; class NubTestParams extends ParamsEquation { private _A: ParamDefinition; @@ -57,175 +53,3 @@ export class NubTest extends Nub { } export let nub = new NubTest(new NubTestParams()); - -/** - * précision de calcul (nombre de décimales) - */ -export let precDigits = 3; - -/** - * précision de calcul (max de abs(v-v')) - */ -export let precDist: number = Math.pow(10, -precDigits); - -/** - * Compare deux valeurs réelles à un epsilon près - * @param val1 Première valeur à comparer - * @param val2 Deuxième valeur à comparer - * @param epsilon Erreur de comparaison acceptable - * @return Vrai si les valeurs sont égales, faux sinon - */ -export function equalEpsilon(val1: number, val2: number, epsilon: number = precDist) { - return Math.abs(val1 - val2) < epsilon; -} - -/** - * Test jasmine de deux valeurs réelles à un epsilon près - * @param val1 Première valeur à comparer - * @param val2 Deuxième valeur à comparer - */ -export function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBe(true); -} - -/** - * compare 2 objets - * @param s message - * @param objTest objet à tester - * @param objValid objet de référence - * @param epsilon tolérance pour les comparaisons de nombres - */ -export function compareObject( - s: string, - objTest: { [key: number]: number }, - objValid: { [key: number]: number }, - epsilon: number, -) { - const n1 = Object.keys(objTest).length; - const n2 = Object.keys(objValid).length; - let b: boolean = n1 === n2; - expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); - if (!b) { return; } - - for (let i = 0; i < n1; i++) { - const v1: number = objTest[+Object.keys(objTest)[i]]; - const v2: number = objValid[+Object.keys(objValid)[i]]; - b = equalEpsilon(v1, v2, epsilon); - expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); - if (!b) { return; } - } -} - -/** - * compare 2 tableaux - * @param s message - * @param arrTest tableau à tester - * @param arrValid tableau de référence - */ -export function compareArray(s: string, arrTest: string[], arrValid: number[]) { - const n1 = arrTest.length; - const n2 = arrValid.length; - let b: boolean = n1 === n2; - expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); - if (!b) { return; } - - for (let i = 0; i < arrTest.length; i++) { - const v1: number = +arrTest[i]; - const v2: number = arrValid[i]; - b = equalEpsilon(v1, v2); - expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); - if (!b) { return; } - } -} - -/** - * compare 2 journaux - */ -export function compareLog(logTest: cLog, logValid: cLog) { - // console.log(JSON.stringify(logTest)); - // console.log("journal :\n" + logTest.toString()); - - // taille - - const n1 = logTest.messages.length; - const n2 = logValid.messages.length; - let b: boolean = n1 === n2; - expect(b).toBeTruthy("journal : nombre de messages incorrect (" + n1 + "), devrait etre " + n2); - if (!b) { return; } - - // codes - - for (let i = 0; i < n1; i++) { - const m1: Message = logTest.messages[i]; - const m2: Message = logValid.messages[i]; - b = m1.code === m2.code; - expect(b).toBeTruthy( - "journal : message n°" + i + ", code " + MessageCode[m1.code] - + " incorrect, devrait être " + MessageCode[m2.code], - ); - if (!b) { return; } - } - - // données - - for (let i = 0; i < n1; i++) { - const m1: Message = logTest.messages[i]; - const m2: Message = logValid.messages[i]; - const code1 = MessageCode[m1.code]; - - // taille des données - - const nd1 = Object.keys(m1.extraVar).length; - const nd2 = Object.keys(m2.extraVar).length; - b = nd1 === nd2; - expect(b).toBeTruthy( - "journal : message n°" + i + ", code " + code1 + " : nombre de données incorrect " - + nd1 + ", devrait etre " + nd2, - ); - if (!b) { return; } - - // clés des données - - for (const j in m1.extraVar) { - b = m2.extraVar[j] !== undefined; - expect(b).toBeTruthy( - "journal : message n°" + i + ", code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] - + " ne devrait pas être présente"); - // if (!b) return; - } - - for (const j in m2.extraVar) { - b = m1.extraVar[j] !== undefined; - expect(b).toBeTruthy( - "journal : message n°" + i + ", code " + code1 + " : la donnée " + j + "=" + m2.extraVar[j] - + " devrait être présente"); - // if (!b) return; - } - - // type des données - - for (const j in m1.extraVar) { - b = typeof m1.extraVar[j] === typeof m2.extraVar[j]; - expect(b).toBeTruthy( - "journal : " + i + "ieme message, code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] - + " a un type " + (typeof m1.extraVar[j]) + " incorrect, devrait être du type " - + (typeof m2.extraVar[j])); - if (!b) { return; } - } - - // valeur des données - - for (const j in m1.extraVar) { - const d: any = m1.extraVar[j]; - if (typeof d === "number") { - b = equalEpsilon(d, m2.extraVar[j]); - } else { - b = d === m2.extraVar[j]; - } - expect(b).toBeTruthy( - "journal : " + i + "ieme message, code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] - + " a une valeur incorrecte, devrait être " + m2.extraVar[j]); - if (!b) { return; } - } - } -} diff --git a/spec/pab/pab_dimension.spec.ts b/spec/pab/pab_dimension.spec.ts index 33808a7aa1a7a38575865152a2a01e3630f6b731..1b217e1897744f0689e8e6147a55d5dd6eeeed4d 100644 --- a/spec/pab/pab_dimension.spec.ts +++ b/spec/pab/pab_dimension.spec.ts @@ -3,7 +3,7 @@ import { Result } from "../../src/util/result"; import { PabDimension, PabDimensionParams } from "../../src/pab/pab_dimension"; -import { check } from "../nubtest"; +import { checkResult } from "../test_func"; function pabDimensionTest(varTest: string) { describe("Calc(): ", () => { @@ -20,7 +20,7 @@ function pabDimensionTest(varTest: string) { const nub = new PabDimension(prms); prms[varTest].v = undefined; - check(nub.Calc(varTest), res); + checkResult(nub.Calc(varTest), res); }); }); } diff --git a/spec/pab/pab_puissance.spec.ts b/spec/pab/pab_puissance.spec.ts index 5da5561a996b3adf45c602ccf3d3a42571124e32..a8856b4b4caf71ab6c5ae604efea3a5b06da474d 100644 --- a/spec/pab/pab_puissance.spec.ts +++ b/spec/pab/pab_puissance.spec.ts @@ -3,7 +3,7 @@ import { Result } from "../../src/util/result"; import { PabPuissance, PabPuissanceParams } from "../../src/pab/pab_puissance"; -import { check } from "../nubtest"; +import { checkResult } from "../test_func"; function PabPuissanceTest(varTest: string) { describe("Calc(): ", () => { @@ -20,7 +20,7 @@ function PabPuissanceTest(varTest: string) { const nub = new PabPuissance(prms); prms[varTest].v = undefined; - check(nub.Calc(varTest, 1e-9), res); + checkResult(nub.Calc(varTest, 1e-9), res); }); }); } diff --git a/spec/regime_uniforme/regime_uniforme_circ.spec.ts b/spec/regime_uniforme/regime_uniforme_circ.spec.ts index 720976c225d74be59be2364f7ffa35093fc83e19..076ca634672d756293b6c8fe4e53a2ec9fc9d62f 100644 --- a/spec/regime_uniforme/regime_uniforme_circ.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_circ.spec.ts @@ -4,12 +4,8 @@ import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; -import { equalEpsilon, precDist } from "../nubtest"; - -function check(val1: Result, val2: number) { - // expect(val1).toBeCloseTo(val2); - expect(equalEpsilon(val1.vCalc, val2)).toBeTruthy("expected " + val2 + ", got " + val1.vCalc); -} +import { equalEpsilon, checkResult } from "../test_func"; +import { precDigits, precDist } from "../test_config"; describe("Class RegimeUniforme / section circulaire :", () => { describe("pas de débordement : ", () => { @@ -25,7 +21,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSect); const ru = new RegimeUniforme(sect); - check(ru.Calc("D", 1e-8), 6.001); + checkResult(ru.Calc("D", 1e-8), 6.001); }); it("Ks should be 40.003", () => { @@ -40,7 +36,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 40.003); + checkResult(ru.Calc("Ks", 1e-8), 40.003); }); it("If should be 0.001", () => { @@ -55,7 +51,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("If"), 0.001); + checkResult(ru.Calc("If", 0.0001), 0.001); }); it("Q should be 1.2", () => { @@ -70,7 +66,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 1.2); + checkResult(ru.Calc("Q"), 1.2); }); it("Y should be 0.6613", () => { @@ -85,7 +81,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Y"), 0.6613); + checkResult(ru.Calc("Y"), 0.6613); }); }); @@ -102,7 +98,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSect); const ru = new RegimeUniforme(sect); - check(ru.Calc("D", 1e-8), 2); + checkResult(ru.Calc("D", 1e-8), 2); }); it("Ks should be 13.551", () => { @@ -117,7 +113,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 13.551); + checkResult(ru.Calc("Ks", 1e-8), 13.551); }); it("If should be 0.001", () => { @@ -132,7 +128,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("If"), 0.001); + checkResult(ru.Calc("If"), 0.001); }); it("Q should be 1.2", () => { @@ -147,7 +143,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 1.2); + checkResult(ru.Calc("Q"), 1.2); }); it("Y should be 2", () => { @@ -162,7 +158,7 @@ describe("Class RegimeUniforme / section circulaire :", () => { const sect = new cSnCirc(paramSection); const ru = new RegimeUniforme(sect); - check(ru.Calc("Y"), 2); + checkResult(ru.Calc("Y"), 2); }); }); }); diff --git a/spec/regime_uniforme/regime_uniforme_puissance.spec.ts b/spec/regime_uniforme/regime_uniforme_puissance.spec.ts index 54c9221eaf4f138f26c098b1bc09b3d43dc60658..37ec2a7ef51c66176e8686675f96ac5875c9dac0 100644 --- a/spec/regime_uniforme/regime_uniforme_puissance.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_puissance.spec.ts @@ -5,11 +5,8 @@ import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; import { MessageCode } from "../../src/util/message"; -import { equalEpsilon, precDist } from "../nubtest"; - -function check(val1: Result, val2: number, eps: number = precDist) { - expect(equalEpsilon(val1.vCalc, val2, eps)).toBeTruthy("expected " + val2 + ", got " + val1.vCalc); -} +import { equalEpsilon, checkResult } from "../test_func"; +import { precDist, precDigits } from "../test_config"; describe("Class RegimeUniforme / section puissance :", () => { describe("pas de débordement :", () => { @@ -26,7 +23,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("k"), 0.635); + checkResult(ru.Calc("k"), 0.635); }); it("LargeurBerge should be 3.473", () => { @@ -42,7 +39,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurBerge"), 3.473); + checkResult(ru.Calc("LargeurBerge"), 3.473); }); it("Strickler should be 33.774", () => { @@ -58,7 +55,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Ks", 1e-8), 33.774); + checkResult(ru.Calc("Ks", 1e-8), 33.774); }); it("If should be 0.002", () => { @@ -74,7 +71,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("If", 0, 0.00001), 0.00071, 0.00001); + checkResult(ru.Calc("If", 0.001, 0.00001), 0.00071, 0.00001); }); it("Q should be 1.421", () => { @@ -90,7 +87,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Q"), 1.421); + checkResult(ru.Calc("Q"), 1.421); }); it("Y should be 0.742", () => { @@ -106,7 +103,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(paramCnl); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Y"), 0.742); + checkResult(ru.Calc("Y"), 0.742); }); }); @@ -142,7 +139,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("k"), 0.933); + checkResult(ru.Calc("k"), 0.933); }); it("LargeurBerge should be 0.721", () => { @@ -158,7 +155,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurBerge"), 0.721); + checkResult(ru.Calc("LargeurBerge"), 0.721); }); it("Strickler should be 4.367", () => { @@ -174,7 +171,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Ks", 1e-8), 4.367); + checkResult(ru.Calc("Ks", 1e-8), 4.367); }); it("Ks should be undefined", () => { @@ -228,7 +225,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("If"), 0.001); + checkResult(ru.Calc("If", 0.001), 0.001); }); it("Q should be 10.993", () => { @@ -244,7 +241,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Q"), 10.993); + checkResult(ru.Calc("Q"), 10.993); }); it("Y should be 0.742", () => { @@ -260,7 +257,7 @@ describe("Class RegimeUniforme / section puissance :", () => { const sect = new cSnPuiss(paramCnl); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("Y"), 0.742); + checkResult(ru.Calc("Y"), 0.742); }); }); }); diff --git a/spec/regime_uniforme/regime_uniforme_rect.spec.ts b/spec/regime_uniforme/regime_uniforme_rect.spec.ts index bf8c7b37c5242498290a730162d50575580ddfab..63ef6843ea4f2b7ce96ddb9c97e237c5e657b2ee 100644 --- a/spec/regime_uniforme/regime_uniforme_rect.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_rect.spec.ts @@ -4,11 +4,8 @@ import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; -import { equalEpsilon, precDist } from "../nubtest"; - -function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBeTruthy("expected " + val2 + ", got " + val1.vCalc); -} +import { equalEpsilon, checkResult } from "../test_func"; +import { precDist } from "../test_config"; describe("Class RegimeUniforme / section rectangulaire :", () => { describe("pas de débordement : ", () => { @@ -27,7 +24,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms, false); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurBerge"), 2.5); + checkResult(ru.Calc("LargeurBerge"), 2.5); }); it("Strickler should be 30.619", () => { @@ -43,7 +40,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 30.619); + checkResult(ru.Calc("Ks", 1e-8), 30.619); }); it("If should be 0.001", () => { @@ -60,7 +57,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const ru = new RegimeUniforme(sect, false); // nom variable à calculer, valeur de Ks - check(ru.Calc("If", 0, precDist), 0.001); + checkResult(ru.Calc("If", 0.001, precDist), 0.001); }); it("Q should be 1.568", () => { @@ -76,7 +73,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 1.568); + checkResult(ru.Calc("Q"), 1.568); }); it("Q should be 0.731", () => { @@ -92,7 +89,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 0.731); + checkResult(ru.Calc("Q"), 0.731); }); it("Y should be 0.663", () => { @@ -109,7 +106,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const ru = new RegimeUniforme(sect); // nom variable à calculer, valeur de Ks - check(ru.Calc("Y"), 0.663); + checkResult(ru.Calc("Y"), 0.663); }); }); @@ -130,10 +127,10 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms, false); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurBerge"), 2.5); + checkResult(ru.Calc("LargeurBerge"), 2.5); }); - it("Strickler should be 9.041", () => { + it("Strickler should be 9.04", () => { const prms = new ParamsSectionRectang(2, // tirant d'eau 2.5, // largeur de fond undefined, // Ks=Strickler @@ -146,7 +143,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 9.041); + checkResult(ru.Calc("Ks", 1e-8), 9.04); }); it("If should be 0.001", () => { @@ -163,7 +160,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const ru = new RegimeUniforme(sect, false); // nom variable à calculer, valeur de Ks - check(ru.Calc("If", 0, precDist), 0.001); + checkResult(ru.Calc("If", 0.001, precDist), 0.001); }); it("Q should be 5.31", () => { @@ -179,7 +176,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 5.31); + checkResult(ru.Calc("Q"), 5.31); }); it("Q should be 1.624", () => { @@ -195,7 +192,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const sect = new cSnRectang(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 1.624); + checkResult(ru.Calc("Q"), 1.624); }); it("Y should be 0.663", () => { @@ -212,7 +209,7 @@ describe("Class RegimeUniforme / section rectangulaire :", () => { const ru = new RegimeUniforme(sect); // nom variable à calculer, valeur de Ks - check(ru.Calc("Y"), 0.663); + checkResult(ru.Calc("Y"), 0.663); }); }); }); diff --git a/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts b/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts index 7bf9f87815e1bca8ad5141767845b9d2faa58fb9..626c04f557b82c7e49a96b46cbc130b8052f5ad7 100644 --- a/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts @@ -4,11 +4,8 @@ import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; -import { equalEpsilon, precDist } from "../nubtest"; - -function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBeTruthy("expected " + val2 + ", got " + val1.vCalc); -} +import { equalEpsilon, checkResult } from "../test_func"; +import { precDist } from "../test_config"; describe("Class RegimeUniforme / section trapèze :", () => { describe("pas de débordement :", () => { @@ -27,7 +24,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurFond", 0, precDist), 2.5); + checkResult(ru.Calc("LargeurFond", 0, precDist), 2.5); }); it("Fruit should be 0.56", () => { @@ -44,7 +41,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Fruit"), 0.56); + checkResult(ru.Calc("Fruit"), 0.56); }); it("Ks should be 24.14", () => { @@ -61,7 +58,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 24.14); + checkResult(ru.Calc("Ks", 1e-8), 24.14); }); it("If should be 0.001", () => { @@ -78,7 +75,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("If"), 0.001); + checkResult(ru.Calc("If", 0.001), 0.001); }); it("Q should be 1.2", () => { @@ -95,7 +92,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 1.2); + checkResult(ru.Calc("Q"), 1.2); }); it("Y should be 0.587", () => { @@ -112,7 +109,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Y"), 0.587); + checkResult(ru.Calc("Y"), 0.587); }); }); @@ -130,7 +127,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect, false); - check(ru.Calc("LargeurFond", 0, precDist), 0.03); + checkResult(ru.Calc("LargeurFond", 0, precDist), 0.03); }); it("Fruit should be 0.56", () => { @@ -147,7 +144,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Fruit"), 0.56); + checkResult(ru.Calc("Fruit"), 0.56); }); it("Ks should be 5.744", () => { @@ -163,7 +160,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Ks", 1e-8), 5.744); + checkResult(ru.Calc("Ks", 1e-8), 5.744); }); it("If should be 0.001", () => { @@ -179,7 +176,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("If"), 0.001); + checkResult(ru.Calc("If", 0.001), 0.001); }); it("Q should be 8.356", () => { @@ -196,7 +193,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Q"), 8.356); + checkResult(ru.Calc("Q"), 8.356); }); it("Y should be 0.587", () => { @@ -213,7 +210,7 @@ describe("Class RegimeUniforme / section trapèze :", () => { const sect = new cSnTrapez(prms); const ru = new RegimeUniforme(sect); - check(ru.Calc("Y"), 0.587); + checkResult(ru.Calc("Y"), 0.587); }); }); }); diff --git a/spec/remous/remous_rect_euler_pentefaible.spec.ts b/spec/remous/remous_rect_euler_pentefaible.spec.ts index c5ebf8edded33b311da7e17db49315e52f5fe3d1..9b1088bfa75bd2d7801b0797742255eadad06458 100644 --- a/spec/remous/remous_rect_euler_pentefaible.spec.ts +++ b/spec/remous/remous_rect_euler_pentefaible.spec.ts @@ -1,9 +1,10 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject } from "../test_func"; +import { precDist } from "../test_config"; +import { CalcResult } from "../../src/util/result"; describe("Class Remous / section rectangulaire :", () => { describe("méthode Euler explicite :", () => { @@ -240,36 +241,36 @@ describe("Class Remous / section rectangulaire :", () => { let rem = new CourbeRemous(prem); - let res = rem.calculRemous(undefined); + let res: CalcResult = rem.calculRemous(undefined); // données de validation : version Typescript (Oct 2017) méthode des trapèzes let f = { "0": 0.9872500000000014, "5": 0.9872500000000014, "10": 0.9872500000000014, "15": 0.9872500000000014, "20": 0.9880000000000013, "25": 0.9887500000000012, "30": 0.9895000000000012, "35": 0.9902500000000011, "40": 0.991000000000001, "45": 0.9917500000000009, "50": 0.9925000000000008, "55": 0.9932500000000007, "60": 0.9940000000000007, "65": 0.9947500000000006, "70": 0.9955000000000005, "75": 0.9962500000000004, "80": 0.9970000000000003, "85": 0.9977500000000002, "90": 0.9985000000000002, "95": 0.9992500000000001, "100": 1 }; - compareObject("Yfluvial", res["flu"], f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res["tor"]).length == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); let x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]; - compareArray("abscisses", res["trX"], x); + compareArray("abscisses", res.getExtraResult("trX"), x); let expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar["B"] = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar["Yc"] = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar["Yn"] = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, pas de ressaut, Yamont > Yc, Yc < Yaval < Yn", () => { @@ -298,31 +299,31 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version Typescript (Oct 2017) méthode trapèzes let f = { "0": 0.805499999999999, "5": 0.802249999999999, "10": 0.7984999999999991, "15": 0.7947499999999992, "20": 0.7909999999999993, "25": 0.7867499999999993, "30": 0.7824999999999993, "35": 0.7782499999999993, "40": 0.7739999999999994, "45": 0.7692499999999994, "50": 0.7644999999999995, "55": 0.7592499999999995, "60": 0.7539999999999996, "65": 0.7482499999999996, "70": 0.7424999999999997, "75": 0.7362499999999997, "80": 0.7299999999999998, "85": 0.7232499999999998, "90": 0.7159999999999999, "95": 0.7082499999999999, "100": 0.7 }; - compareObject("Yfluvial", res["flu"], f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res["tor"]).length == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); let x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]; - compareArray("abscisses", res["trX"], x); + compareArray("abscisses", res.getExtraResult("trX"), x); let expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar["B"] = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar["Yc"] = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar["Yn"] = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); }); diff --git a/spec/remous/remous_rect_euler_penteforte.spec.ts b/spec/remous/remous_rect_euler_penteforte.spec.ts index fa51807b18e9f938e02aaaf8fc8d1a07b1a1600a..770317eaefb6bcc669fbbe2da020f09ea341039f 100644 --- a/spec/remous/remous_rect_euler_penteforte.spec.ts +++ b/spec/remous/remous_rect_euler_penteforte.spec.ts @@ -1,9 +1,9 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject, equalEpsilon } from "../test_func"; +import { precDist } from "../test_config"; /* Certaines valeurs de ligne d'eau torrentielle étaient auparavant remplacées par une valeur fluviale @@ -40,36 +40,36 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version Typescript (Oct 2017) méthode des trapèzes const f = { 0: 0.9767500000000044, 5: 1.2360000000000044, 10: 1.4910000000000045, 15: 1.7437500000000046, 20: 1.9955000000000045, 25: 2.2465000000000046, 30: 2.497500000000005, 35: 2.7485000000000053, 40: 2.9985000000000053, 45: 3.2485000000000053, 50: 3.4985000000000053, 55: 3.7485000000000053, 60: 3.9985000000000053, 65: 4.248500000000004, 70: 4.498750000000004, 75: 4.749000000000003, 80: 4.999250000000003, 85: 5.249500000000002, 90: 5.4997500000000015, 95: 5.750000000000001, 100: 6 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = {}; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "amont"; m.extraVar.x = 0; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, ressaut après l'aval", () => { @@ -99,42 +99,42 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version Typescript (Oct 2017) méthode des trapèzes const f = {}; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { "0": 0.15, "5": 0.20725000000000002, "10": 0.23500000000000001, "15": 0.24675000000000002, "20": 0.251, "25": 0.25225, "30": 0.25249999999999995, "35": 0.2527499999999999, "40": 0.2529999999999999, "45": 0.2527499999999999, "50": 0.2529999999999999, "55": 0.2527499999999999, "60": 0.2529999999999999, "65": 0.2527499999999999, "70": 0.2529999999999999, "75": 0.2527499999999999, "80": 0.2529999999999999, "85": 0.2527499999999999, "90": 0.2529999999999999, "95": 0.2527499999999999, "100": 0.45 }; const t = { 0: 0.15, 5: 0.20725000000000002, 10: 0.23500000000000001, 15: 0.24675000000000002, 20: 0.251, 25: 0.25225, 30: 0.25249999999999995, 35: 0.2527499999999999, 40: 0.2529999999999999, 45: 0.2527499999999999, 50: 0.2529999999999999, 55: 0.2527499999999999, 60: 0.2529999999999999, 65: 0.2527499999999999, 70: 0.2529999999999999, 75: 0.2527499999999999, 80: 0.2529999999999999, 85: 0.2527499999999999, 90: 0.2529999999999999, 95: 0.2527499999999999, 100: 0.253 }; // dernière valeur modifiée pour la raison en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 95; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "aval"; m.extraVar.x = 100; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); // it("forte pente, ressaut (1 point) à l'intérieur du bief", () => { @@ -237,37 +237,37 @@ describe("Class Remous / section rectangulaire :", () => { // "1.5": 0.7845000000000006, "1.25": 0.7702500000000007, "0.75": 0.7417500000000007, // "0.5": 0.7275000000000007, "0.25": 0.7132500000000007 }; const f = { 0: 0.698, 1: 0.7560000000000007, 2: 0.8120000000000005, 3: 0.8670000000000002, 4: 0.9205000000000001, 5: 0.9735, 5.5: 1, 5.25: 0.98675, 4.75: 0.96025, 4.5: 0.9470000000000001, 4.25: 0.9337500000000001, 3.75: 0.9072500000000001, 3.5: 0.8940000000000001, 3.25: 0.8807500000000001, 2.75: 0.8532500000000003, 2.5: 0.8395000000000004, 2.25: 0.8257500000000004, 1.75: 0.7982500000000006, 1.5: 0.7845000000000006, 1.25: 0.7702500000000007, 0.75: 0.7417500000000007, 0.5: 0.7275000000000007, 0.25: 0.7132500000000007 }; // première valeur modifiée pour la raison en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0: 0.15, 1: 0.161, 2: 0.17200000000000001, 3: 0.18100000000000002, 0.25: 0.15275, 0.5: 0.1555, 0.75: 0.15825, 1.25: 0.16375, 1.5: 0.1665, 1.75: 0.16925, 2.25: 0.17425000000000002, 2.5: 0.17650000000000002, 2.75: 0.17875000000000002, 3.25: 0.18325000000000002, 3.5: 0.18550000000000003, 3.75: 0.9072500000000001 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 3.75; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yamont < Yn", () => { @@ -295,7 +295,7 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version Typescript (Oct 2017) méthode trapèzes - expect(Object.keys(res.flu).length === 0).toBeTruthy( + expect(res.extraResultLength("flu") == 0).toBeTruthy( "la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { @@ -306,31 +306,32 @@ describe("Class Remous / section rectangulaire :", () => { 16: 0.23600000000000013, 17: 0.23875000000000013, 18: 0.24100000000000013, 19: 0.24325000000000013, 20: 0.24500000000000013, 21: 0.24625000000000014, 22: 0.24750000000000014, 23: 0.2485000000000001, 24: 0.2492500000000001, 25: 0.2502500000000001, 26: 0.25050000000000006, 27: 0.25075000000000003, - 28: 0.251, 29: 0.25125, 30: 0.25149999999999995 }; - compareObject("Ytorrentiel", res.tor, t, 0.01); + 28: 0.251, 29: 0.25125, 30: 0.25149999999999995 + }; + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.01); const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yn < Yamont < Yc", () => { @@ -358,32 +359,32 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes - expect(Object.keys(res.flu).length === 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); + expect(res.extraResultLength("flu") == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.35, 0.100: 0.345, 0.200: 0.34, 0.300: 0.336, 0.400: 0.332, 0.500: 0.329, 0.600: 0.326, 0.700: 0.323, 0.800: 0.32, 0.900: 0.318, 1.000: 0.316, 1.100: 0.313, 1.200: 0.311, 1.300: 0.309, 1.400: 0.308, 1.500: 0.306, 1.600: 0.305, 1.700: 0.303, 1.800: 0.302, 1.900: 0.3, 2.000: 0.298, 2.100: 0.297, 2.200: 0.295, 2.300: 0.294, 2.400: 0.293, 2.500: 0.292, 2.600: 0.291, 2.700: 0.291, 2.800: 0.29, 2.900: 0.289, 3.000: 0.288, 3.100: 0.287, 3.200: 0.287, 3.300: 0.286, 3.400: 0.285, 3.500: 0.284, 3.600: 0.283, 3.700: 0.283, 3.800: 0.282, 3.900: 0.281, 4.000: 0.28, 4.100: 0.28, 4.200: 0.279, 4.300: 0.278, 4.400: 0.277, 4.500: 0.276, 4.600: 0.276, 4.700: 0.275, 4.800: 0.274, 4.900: 0.273, 5.000: 0.272, 5.100: 0.272, 5.200: 0.271, 5.300: 0.27, 5.400: 0.269, 5.500: 0.269, 5.600: 0.269, 5.700: 0.269, 5.800: 0.269, 5.900: 0.269, 6.000: 0.269, 6.100: 0.269, 6.200: 0.269, 6.300: 0.269, 6.400: 0.269, 6.500: 0.269, 6.600: 0.269, 6.700: 0.269, 6.800: 0.269, 6.900: 0.269, 7.000: 0.269, 7.100: 0.269, 7.200: 0.269, 7.300: 0.269, 7.400: 0.269, 7.500: 0.269, 7.600: 0.269, 7.700: 0.269, 7.800: 0.269, 7.900: 0.269, 8.000: 0.269, 8.100: 0.269, 8.200: 0.269, 8.300: 0.269, 8.400: 0.269, 8.500: 0.269, 8.600: 0.269, 8.700: 0.269, 8.800: 0.269, 8.900: 0.269, 9.000: 0.269, 9.100: 0.269, 9.200: 0.269, 9.300: 0.269, 9.400: 0.269, 9.500: 0.269, 9.600: 0.269, 9.700: 0.269, 9.800: 0.269, 9.900: 0.269, 10.000: 0.269 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800, 1.900, 2.000, 2.100, 2.200, 2.300, 2.400, 2.500, 2.600, 2.700, 2.800, 2.900, 3.000, 3.100, 3.200, 3.300, 3.400, 3.500, 3.600, 3.700, 3.800, 3.900, 4.000, 4.100, 4.200, 4.300, 4.400, 4.500, 4.600, 4.700, 4.800, 4.900, 5.000, 5.100, 5.200, 5.300, 5.400, 5.500, 5.600, 5.700, 5.800, 5.900, 6.000, 6.100, 6.200, 6.300, 6.400, 6.500, 6.600, 6.700, 6.800, 6.900, 7.000, 7.100, 7.200, 7.300, 7.400, 7.500, 7.600, 7.700, 7.800, 7.900, 8.000, 8.100, 8.200, 8.300, 8.400, 8.500, 8.600, 8.700, 8.800, 8.900, 9.000, 9.100, 9.200, 9.300, 9.400, 9.500, 9.600, 9.700, 9.800, 9.900, 10.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); }); diff --git a/spec/remous/remous_rect_rk4_pentefaible.spec.ts b/spec/remous/remous_rect_rk4_pentefaible.spec.ts index 5d4fa2ae4e4ac965df30c881dc2f1921d69fd93c..dac7b903c661499c5a3cdb65e0bd271ac642e0e2 100644 --- a/spec/remous/remous_rect_rk4_pentefaible.spec.ts +++ b/spec/remous/remous_rect_rk4_pentefaible.spec.ts @@ -1,9 +1,9 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject, equalEpsilon } from "../test_func"; +import { precDist } from "../test_config"; /* Le code de modification des lignes fluviale et torrentielle a été modifié, on enlève un point de plus @@ -43,43 +43,44 @@ describe("Class Remous / section rectangulaire :", () => { 100.000: 0.41, 95.000: 0.876, 90.000: 0.877, 85.000: 0.879, 80.000: 0.88, 75.000: 0.881, 70.000: 0.883, 65.000: 0.884, 60.000: 0.885, 55.000: 0.886, 50.000: 0.888, 45.000: 0.889, 40.000: 0.89, 35.000: 0.891, 30.000: 0.892, 25.000: 0.893, 20.000: 0.894, 15.000: 0.895, - 10.000: 0.896, 5.000: 0.897, 0.000: 0.898 }; - compareObject("Yfluvial", res.flu, f, 0.03); + 10.000: 0.896, 5.000: 0.897, 0.000: 0.898 + }; + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = {}; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "amont"; m.extraVar.x = 0; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, ressaut (1 point) à l'intérieur du bief", () => { @@ -109,42 +110,42 @@ describe("Class Remous / section rectangulaire :", () => { // let f = { 100.000: 0.42, 95.000: 0.583, 90.000: 0.604, 85.000: 0.621, 80.000: 0.636, 75.000: 0.65, 70.000: 0.662, 65.000: 0.673, 60.000: 0.683, 55.000: 0.692, 50.000: 0.701, 45.000: 0.709, 40.000: 0.717, 35.000: 0.724, 30.000: 0.731, 25.000: 0.737, 20.000: 0.743, 15.000: 0.749, 10.000: 0.755, 5.000: 0.76, 0.000: 0.15 }; const f = { 100.000: 0.42, 95.000: 0.583, 90.000: 0.604, 85.000: 0.621, 80.000: 0.636, 75.000: 0.65, 70.000: 0.662, 65.000: 0.673, 60.000: 0.683, 55.000: 0.692, 50.000: 0.701, 45.000: 0.709, 40.000: 0.717, 35.000: 0.724, 30.000: 0.731, 25.000: 0.737, 20.000: 0.743, 15.000: 0.749, 10.000: 0.755, 5.000: 0.76 }; // dernière valeur supprimée pour la raison en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.76 }; const t = { 0.000: 0.15 }; // dernière valeur supprimée pour la raison en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 15; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 5; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("faible pente, ressaut (plusieurs points) à l'intérieur du bief", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -173,37 +174,37 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 const f = { 5.000: 0.42, 4.750: 0.434, 4.500: 0.443, 4.250: 0.45, 4.000: 0.457, 3.750: 0.462, 3.500: 0.467, 3.250: 0.471, 3.000: 0.476, 2.750: 0.48, 2.500: 0.483, 2.250: 0.487, 2.000: 0.49, 1.750: 0.493, 1.500: 0.496, 1.250: 0.499, 1.000: 0.502, 0.750: 0.504, 0.500: 0.507, 0.250: 0.509, 0.000: 0.01 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0.000: 0.01, 0.250: 0.017, 0.500: 0.022, 0.750: 0.028, 1.000: 0.502 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 0.250, 0.500, 0.750, 1.000, 1.250, 1.500, 1.750, 2.000, 2.250, 2.500, 2.750, 3.000, 3.250, 3.500, 3.750, 4.000, 4.250, 4.500, 4.750, 5.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 1; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, pas de ressaut, Yamont > Yc, Yaval > Yn", () => { @@ -232,31 +233,31 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 const f = { 100.000: 1, 95.000: 0.999, 90.000: 0.999, 85.000: 0.998, 80.000: 0.997, 75.000: 0.997, 70.000: 0.996, 65.000: 0.996, 60.000: 0.995, 55.000: 0.994, 50.000: 0.994, 45.000: 0.993, 40.000: 0.993, 35.000: 0.992, 30.000: 0.991, 25.000: 0.991, 20.000: 0.99, 15.000: 0.99, 10.000: 0.989, 5.000: 0.989, 0.000: 0.988 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res.tor).length === 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, pas de ressaut, Yamont > Yc, Yc < Yaval < Yn", () => { @@ -285,31 +286,31 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 const f = { 100.000: 0.7, 95.000: 0.708, 90.000: 0.716, 85.000: 0.723, 80.000: 0.73, 75.000: 0.737, 70.000: 0.743, 65.000: 0.749, 60.000: 0.754, 55.000: 0.759, 50.000: 0.764, 45.000: 0.769, 40.000: 0.774, 35.000: 0.779, 30.000: 0.783, 25.000: 0.787, 20.000: 0.791, 15.000: 0.795, 10.000: 0.799, 5.000: 0.802, 0.000: 0.806 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res.tor).length === 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); }); diff --git a/spec/remous/remous_rect_rk4_penteforte.spec.ts b/spec/remous/remous_rect_rk4_penteforte.spec.ts index 2b0fc783d44ff1cf773d043614d1e58486c6327d..de0ffec37e4b863e97ca4411c737a3e8cbc5ca1b 100644 --- a/spec/remous/remous_rect_rk4_penteforte.spec.ts +++ b/spec/remous/remous_rect_rk4_penteforte.spec.ts @@ -1,9 +1,9 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject, equalEpsilon } from "../test_func"; +import { precDist } from "../test_config"; /* cas 1 : @@ -49,36 +49,36 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 const f = { 100.000: 6, 95.000: 5.75, 90.000: 5.5, 85.000: 5.25, 80.000: 5, 75.000: 4.75, 70.000: 4.5, 65.000: 4.25, 60.000: 4, 55.000: 3.749, 50.000: 3.499, 45.000: 3.249, 40.000: 2.999, 35.000: 2.748, 30.000: 2.498, 25.000: 2.247, 20.000: 1.996, 15.000: 1.744, 10.000: 1.491, 5.000: 1.237, 0.000: 0.977 }; - compareObject("Yfluvial", res.flu, f, 0.01); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.01); const t = {}; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "amont"; m.extraVar.x = 0; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, ressaut après l'aval", () => { @@ -108,42 +108,42 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 const f = {}; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.198, 10.000: 0.228, 15.000: 0.243, 20.000: 0.249, 25.000: 0.251, 30.000: 0.252, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.45 }; const t = { 0.000: 0.15, 5.000: 0.198, 10.000: 0.228, 15.000: 0.243, 20.000: 0.249, 25.000: 0.251, 30.000: 0.252, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 }; // dernière valeur remplacée pour la raison 1 en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE) m.extraVar.x = 95; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "aval"; m.extraVar.x = 100; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("forte pente, ressaut (1 point) à l'intérieur du bief", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -173,42 +173,42 @@ describe("Class Remous / section rectangulaire :", () => { // let f = { 100.000: 1, 95.000: 0.728, 90.000: 0.521 }; const f = { 100.000: 1, 95.000: 0.728 }; // dernière valeur supprimée pour la raison 2 en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.198, 10.000: 0.228, 15.000: 0.243, 20.000: 0.249, 25.000: 0.251, 30.000: 0.252, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.521 }; const t = { 0.000: 0.15, 5.000: 0.198, 10.000: 0.228, 15.000: 0.243, 20.000: 0.249, 25.000: 0.251, 30.000: 0.252, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253 }; // dernière valeur remplacée pour la raison 1 en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE) m.extraVar.x = 85; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 90; m.extraVar.xmax = 90; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("forte pente, ressaut (plusieurs points) à l'intérieur du bief", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -238,37 +238,37 @@ describe("Class Remous / section rectangulaire :", () => { // let f = { 5.500: 1, 5.250: 0.987, 5.000: 0.974, 4.750: 0.96, 4.500: 0.947, 4.250: 0.934, 4.000: 0.921, 3.750: 0.907, 3.500: 0.894, 3.250: 0.88, 3.000: 0.867, 2.750: 0.853, 2.500: 0.84, 2.250: 0.826, 2.000: 0.812, 1.750: 0.798, 1.500: 0.785, 1.250: 0.771, 1.000: 0.756, 0.750: 0.742, 0.500: 0.728, 0.250: 0.713, 0.000: 0.15 }; const f = { 5.500: 1, 5.250: 0.987, 5.000: 0.974, 4.750: 0.96, 4.500: 0.947, 4.250: 0.934, 4.000: 0.921, 3.750: 0.907, 3.500: 0.894, 3.250: 0.88, 3.000: 0.867, 2.750: 0.853, 2.500: 0.84, 2.250: 0.826, 2.000: 0.812, 1.750: 0.798, 1.500: 0.785, 1.250: 0.771, 1.000: 0.756, 0.750: 0.742, 0.500: 0.728, 0.250: 0.713, 0.000: 0.699 }; // dernière valeur remplacée pour la raison 1 en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0.000: 0.15, 0.250: 0.153, 0.500: 0.156, 0.750: 0.158, 1.000: 0.161, 1.250: 0.164, 1.500: 0.166, 1.750: 0.169, 2.000: 0.171, 2.250: 0.174, 2.500: 0.176, 2.750: 0.179, 3.000: 0.181, 3.250: 0.183, 3.500: 0.186, 3.750: 0.907 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 0.250, 0.500, 0.750, 1.000, 1.250, 1.500, 1.750, 2.000, 2.250, 2.500, 2.750, 3.000, 3.250, 3.500, 3.750, 4.000, 4.250, 4.500, 4.750, 5.000, 5.250, 5.500]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 3.75; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yamont < Yn", () => { @@ -296,32 +296,32 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 - expect(Object.keys(res.flu).length == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); + expect(res.extraResultLength("flu") == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.1, 5.000: 0.162, 10.000: 0.206, 15.000: 0.232, 20.000: 0.244, 25.000: 0.25, 30.000: 0.252, 35.000: 0.252, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 }; - compareObject("Ytorrentiel", res.tor, t, 0.01); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.01); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yn < Yamont < Yc", () => { @@ -349,32 +349,32 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode RungeKutta4 - expect(Object.keys(res.flu).length == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); + expect(res.extraResultLength("flu") == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.35, 0.100: 0.344, 0.200: 0.34, 0.300: 0.335, 0.400: 0.332, 0.500: 0.328, 0.600: 0.325, 0.700: 0.322, 0.800: 0.32, 0.900: 0.317, 1.000: 0.315, 1.100: 0.313, 1.200: 0.31, 1.300: 0.309, 1.400: 0.307, 1.500: 0.305, 1.600: 0.303, 1.700: 0.302, 1.800: 0.3, 1.900: 0.299, 2.000: 0.297, 2.100: 0.296, 2.200: 0.295, 2.300: 0.294, 2.400: 0.293, 2.500: 0.291, 2.600: 0.29, 2.700: 0.289, 2.800: 0.288, 2.900: 0.287, 3.000: 0.287, 3.100: 0.286, 3.200: 0.285, 3.300: 0.284, 3.400: 0.283, 3.500: 0.282, 3.600: 0.282, 3.700: 0.281, 3.800: 0.28, 3.900: 0.279, 4.000: 0.279, 4.100: 0.278, 4.200: 0.278, 4.300: 0.277, 4.400: 0.276, 4.500: 0.276, 4.600: 0.275, 4.700: 0.275, 4.800: 0.274, 4.900: 0.274, 5.000: 0.273, 5.100: 0.273, 5.200: 0.272, 5.300: 0.272, 5.400: 0.271, 5.500: 0.271, 5.600: 0.271, 5.700: 0.27, 5.800: 0.27, 5.900: 0.269, 6.000: 0.269, 6.100: 0.269, 6.200: 0.268, 6.300: 0.268, 6.400: 0.268, 6.500: 0.267, 6.600: 0.267, 6.700: 0.267, 6.800: 0.266, 6.900: 0.266, 7.000: 0.266, 7.100: 0.265, 7.200: 0.265, 7.300: 0.265, 7.400: 0.265, 7.500: 0.264, 7.600: 0.264, 7.700: 0.264, 7.800: 0.264, 7.900: 0.263, 8.000: 0.263, 8.100: 0.263, 8.200: 0.263, 8.300: 0.263, 8.400: 0.262, 8.500: 0.262, 8.600: 0.262, 8.700: 0.262, 8.800: 0.262, 8.900: 0.261, 9.000: 0.261, 9.100: 0.261, 9.200: 0.261, 9.300: 0.261, 9.400: 0.26, 9.500: 0.26, 9.600: 0.26, 9.700: 0.26, 9.800: 0.26, 9.900: 0.26, 10.000: 0.26 }; - compareObject("Ytorrentiel", res.tor, t, 0.01); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.01); const x = [0.000, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800, 1.900, 2.000, 2.100, 2.200, 2.300, 2.400, 2.500, 2.600, 2.700, 2.800, 2.900, 3.000, 3.100, 3.200, 3.300, 3.400, 3.500, 3.600, 3.700, 3.800, 3.900, 4.000, 4.100, 4.200, 4.300, 4.400, 4.500, 4.600, 4.700, 4.800, 4.900, 5.000, 5.100, 5.200, 5.300, 5.400, 5.500, 5.600, 5.700, 5.800, 5.900, 6.000, 6.100, 6.200, 6.300, 6.400, 6.500, 6.600, 6.700, 6.800, 6.900, 7.000, 7.100, 7.200, 7.300, 7.400, 7.500, 7.600, 7.700, 7.800, 7.900, 8.000, 8.100, 8.200, 8.300, 8.400, 8.500, 8.600, 8.700, 8.800, 8.900, 9.000, 9.100, 9.200, 9.300, 9.400, 9.500, 9.600, 9.700, 9.800, 9.900, 10.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); }); diff --git a/spec/remous/remous_rect_trapezes_pentefaible.spec.ts b/spec/remous/remous_rect_trapezes_pentefaible.spec.ts index 3fc514a0065ffdae4c0d63cb4fce2bbcff5bfd6c..83dbfe087257710e626136a3f90a613879c37d22 100644 --- a/spec/remous/remous_rect_trapezes_pentefaible.spec.ts +++ b/spec/remous/remous_rect_trapezes_pentefaible.spec.ts @@ -1,9 +1,9 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject, equalEpsilon } from "../test_func"; +import { precDist } from "../test_config"; /* Le code de modification des lignes fluviale et torrentielle a été modifié, on enlève un point de plus @@ -40,41 +40,41 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 100.000: 0.403, 95.000: 0.524, 90.000: 0.558, 85.000: 0.584, 80.000: 0.604, 75.000: 0.621, 70.000: 0.637, 65.000: 0.65, 60.000: 0.662, 55.000: 0.673, 50.000: 0.684, 45.000: 0.693, 40.000: 0.701, 35.000: 0.709, 30.000: 0.717, 25.000: 0.725, 20.000: 0.731, 15.000: 0.738, 10.000: 0.744, 5.000: 0.75, 0.000: 0.755 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = {}; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "amont"; m.extraVar.x = 0; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, ressaut (1 point) à l'intérieur du bief", () => { @@ -104,42 +104,42 @@ describe("Class Remous / section rectangulaire :", () => { // let f = { 100.000: 0.403, 95.000: 0.524, 90.000: 0.558, 85.000: 0.584, 80.000: 0.604, 75.000: 0.621, 70.000: 0.637, 65.000: 0.65, 60.000: 0.662, 55.000: 0.673, 50.000: 0.684, 45.000: 0.693, 40.000: 0.701, 35.000: 0.709, 30.000: 0.717, 25.000: 0.725, 20.000: 0.731, 15.000: 0.738, 10.000: 0.744, 5.000: 0.75, 0.000: 0.15 }; const f = { 100.000: 0.403, 95.000: 0.524, 90.000: 0.558, 85.000: 0.584, 80.000: 0.604, 75.000: 0.621, 70.000: 0.637, 65.000: 0.65, 60.000: 0.662, 55.000: 0.673, 50.000: 0.684, 45.000: 0.693, 40.000: 0.701, 35.000: 0.709, 30.000: 0.717, 25.000: 0.725, 20.000: 0.731, 15.000: 0.738, 10.000: 0.744, 5.000: 0.75 }; // dernière valeur supprimée pour la raison en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.75 }; const t = { 0.000: 0.15 }; // dernière valeur supprimée pour la raison en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 15; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 5; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("faible pente, ressaut (plusieurs points) à l'intérieur du bief (1)", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -180,37 +180,37 @@ describe("Class Remous / section rectangulaire :", () => { // dx = 0.25 const f = { 5.000: 0.403, 4.750: 0.43, 4.500: 0.44, 4.250: 0.448, 4.000: 0.455, 3.750: 0.46, 3.500: 0.465, 3.250: 0.47, 3.000: 0.474, 2.750: 0.479, 2.500: 0.482, 2.250: 0.486, 2.000: 0.489, 1.750: 0.492, 1.500: 0.495, 1.250: 0.498, 1.000: 0.501, 0.750: 0.504, 0.500: 0.506, 0.250: 0.508, 0.000: 0.01 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0.000: 0.01, 0.250: 0.022, 0.500: 0.027, 0.750: 0.033, 1.000: 0.501 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 0.250, 0.500, 0.750, 1.000, 1.250, 1.500, 1.750, 2.000, 2.250, 2.500, 2.750, 3.000, 3.250, 3.500, 3.750, 4.000, 4.250, 4.500, 4.750, 5.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 1; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("faible pente, ressaut (plusieurs points) à l'intérieur du bief (2)", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -239,37 +239,37 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 5.0000: 0.403, 4.9500: 0.415, 4.9000: 0.42, 4.8500: 0.423, 4.8000: 0.426, 4.7500: 0.429, 4.7000: 0.432, 4.6500: 0.434, 4.6000: 0.436, 4.5500: 0.438, 4.5000: 0.44, 4.4500: 0.441, 4.4000: 0.443, 4.3500: 0.445, 4.3000: 0.446, 4.2500: 0.448, 4.2000: 0.449, 4.1500: 0.45, 4.1000: 0.452, 4.0500: 0.453, 4.0000: 0.454, 3.9500: 0.455, 3.9000: 0.457, 3.8500: 0.458, 3.8000: 0.459, 3.7500: 0.46, 3.7000: 0.461, 3.6500: 0.462, 3.6000: 0.463, 3.5500: 0.464, 3.5000: 0.465, 3.4500: 0.466, 3.4000: 0.467, 3.3500: 0.468, 3.3000: 0.469, 3.2500: 0.47, 3.2000: 0.471, 3.1500: 0.471, 3.1000: 0.472, 3.0500: 0.473, 3.0000: 0.474, 2.9500: 0.475, 2.9000: 0.476, 2.8500: 0.476, 2.8000: 0.477, 2.7500: 0.478, 2.7000: 0.479, 2.6500: 0.479, 2.6000: 0.48, 2.5500: 0.481, 2.5000: 0.482, 2.4500: 0.482, 2.4000: 0.483, 2.3500: 0.484, 2.3000: 0.484, 2.2500: 0.485, 2.2000: 0.486, 2.1500: 0.487, 2.1000: 0.487, 2.0500: 0.488, 2.0000: 0.489, 1.9500: 0.489, 1.9000: 0.49, 1.8500: 0.49, 1.8000: 0.491, 1.7500: 0.492, 1.7000: 0.492, 1.6500: 0.493, 1.6000: 0.494, 1.5500: 0.494, 1.5000: 0.495, 1.4500: 0.495, 1.4000: 0.496, 1.3500: 0.497, 1.3000: 0.497, 1.2500: 0.498, 1.2000: 0.498, 1.1500: 0.499, 1.1000: 0.499, 1.0500: 0.5, 1.0000: 0.5, 0.9500: 0.501, 0.9000: 0.502, 0.8500: 0.502, 0.8000: 0.503, 0.7500: 0.503, 0.7000: 0.504, 0.6500: 0.504, 0.6000: 0.505, 0.5500: 0.505, 0.5000: 0.506, 0.4500: 0.506, 0.4000: 0.507, 0.3500: 0.507, 0.3000: 0.508, 0.2500: 0.508, 0.2000: 0.509, 0.1500: 0.509, 0.1000: 0.51, 0.0500: 0.51, 0.0000: 0.01 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0.0000: 0.01, 0.0500: 0.011, 0.1000: 0.013, 0.1500: 0.014, 0.2000: 0.015, 0.2500: 0.017, 0.3000: 0.018, 0.3500: 0.019, 0.4000: 0.02, 0.4500: 0.021, 0.5000: 0.022, 0.5500: 0.024, 0.6000: 0.025, 0.6500: 0.026, 0.7000: 0.027, 0.7500: 0.028, 0.8000: 0.029, 0.8500: 0.03, 0.9000: 0.502 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.0000, 0.0500, 0.1000, 0.1500, 0.2000, 0.2500, 0.3000, 0.3500, 0.4000, 0.4500, 0.5000, 0.5500, 0.6000, 0.6500, 0.7000, 0.7500, 0.8000, 0.8500, 0.9000, 0.9500, 1.0000, 1.0500, 1.1000, 1.1500, 1.2000, 1.2500, 1.3000, 1.3500, 1.4000, 1.4500, 1.5000, 1.5500, 1.6000, 1.6500, 1.7000, 1.7500, 1.8000, 1.8500, 1.9000, 1.9500, 2.0000, 2.0500, 2.1000, 2.1500, 2.2000, 2.2500, 2.3000, 2.3500, 2.4000, 2.4500, 2.5000, 2.5500, 2.6000, 2.6500, 2.7000, 2.7500, 2.8000, 2.8500, 2.9000, 2.9500, 3.0000, 3.0500, 3.1000, 3.1500, 3.2000, 3.2500, 3.3000, 3.3500, 3.4000, 3.4500, 3.5000, 3.5500, 3.6000, 3.6500, 3.7000, 3.7500, 3.8000, 3.8500, 3.9000, 3.9500, 4.0000, 4.0500, 4.1000, 4.1500, 4.2000, 4.2500, 4.3000, 4.3500, 4.4000, 4.4500, 4.5000, 4.5500, 4.6000, 4.6500, 4.7000, 4.7500, 4.8000, 4.8500, 4.9000, 4.9500, 5.0000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 0.9; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); @@ -299,31 +299,31 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 100.000: 1, 95.000: 0.999, 90.000: 0.999, 85.000: 0.998, 80.000: 0.997, 75.000: 0.997, 70.000: 0.996, 65.000: 0.996, 60.000: 0.995, 55.000: 0.994, 50.000: 0.994, 45.000: 0.993, 40.000: 0.992, 35.000: 0.992, 30.000: 0.991, 25.000: 0.991, 20.000: 0.99, 15.000: 0.989, 10.000: 0.989, 5.000: 0.988, 0.000: 0.988 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res.tor).length === 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, pas de ressaut, Yamont > Yc, Yc < Yaval < Yn", () => { @@ -352,31 +352,31 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 100.000: 0.7, 95.000: 0.708, 90.000: 0.716, 85.000: 0.723, 80.000: 0.73, 75.000: 0.737, 70.000: 0.743, 65.000: 0.749, 60.000: 0.754, 55.000: 0.76, 50.000: 0.765, 45.000: 0.77, 40.000: 0.775, 35.000: 0.779, 30.000: 0.783, 25.000: 0.787, 20.000: 0.792, 15.000: 0.795, 10.000: 0.799, 5.000: 0.803, 0.000: 0.806 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); - expect(Object.keys(res.tor).length === 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); + expect(res.extraResultLength("tor") == 0).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur"); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("faible pente, pas de fluvial, torrentiel tronqué, calcul Hs", () => { @@ -404,38 +404,38 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes - expect(Object.keys(res.flu).length === 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); + expect(res.extraResultLength("flu") == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.15, 5.000: 0.239, 10.000: 0.34 }; - compareObject("Ytorrentiel", res.tor, t, 0.008); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.008); const x = [0.000, 5.000, 10.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const extraHS = { 0.000: 1.6, 5.000: 0.808, 10.000: 0.618 }; - compareObject("extra (Hs)", res.tRes, extraHS, 0.001); + compareObject("extra (Hs)", res.getExtraResult("tRes"), extraHS, 0.001); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.953; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 15; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); diff --git a/spec/remous/remous_rect_trapezes_penteforte.spec.ts b/spec/remous/remous_rect_trapezes_penteforte.spec.ts index 20e2674c7c8d40cc63ab191d2f4be9fcde45143d..86363194bda5ba63df0024667d51e267b458d504 100644 --- a/spec/remous/remous_rect_trapezes_penteforte.spec.ts +++ b/spec/remous/remous_rect_trapezes_penteforte.spec.ts @@ -1,9 +1,9 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { cLog } from "../../src/util/log"; import { Message, MessageCode } from "../../src/util/message"; -import { compareArray, compareLog, compareObject, equalEpsilon, precDigits, precDist } from "../nubtest"; +import { compareArray, compareLog, compareObject, equalEpsilon } from "../test_func"; +import { precDist } from "../test_config"; /* cas 1 : @@ -49,36 +49,36 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 100.000: 6, 95.000: 5.75, 90.000: 5.5, 85.000: 5.25, 80.000: 4.999, 75.000: 4.749, 70.000: 4.499, 65.000: 4.249, 60.000: 3.998, 55.000: 3.748, 50.000: 3.498, 45.000: 3.248, 40.000: 2.997, 35.000: 2.747, 30.000: 2.497, 25.000: 2.246, 20.000: 1.995, 15.000: 1.744, 10.000: 1.491, 5.000: 1.237, 0.000: 0.977 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = {}; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "amont"; m.extraVar.x = 0; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, ressaut après l'aval", () => { @@ -108,43 +108,43 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = {}; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.207, 10.000: 0.235, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 }; // let t = { 0.000: 0.15, 5.000: 0.207, 10.000: 0.235, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.45 }; // dernière valeur modifiée pour la raison 1 en tête de fichier const t = { 0.000: 0.15, 5.000: 0.207, 10.000: 0.235, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 95; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_DEHORS); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_DEHORS); m.extraVar.sens = "aval"; m.extraVar.x = 100; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, ressaut (1 point) à l'intérieur du bief", () => { @@ -173,42 +173,42 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes const f = { 100.000: 1, 95.000: 0.729 }; - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); // let t = { 0.000: 0.15, 5.000: 0.207, 10.000: 0.235, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253, 95.000: 0.729 }; const t = { 0.000: 0.15, 5.000: 0.207, 10.000: 0.235, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, 90.000: 0.253 }; // dernière valeur supprimée pour la raison 2 en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); m = new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE); m.extraVar.x = 90; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 90; m.extraVar.xmax = 95; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); xit("forte pente, ressaut (plusieurs points) à l'intérieur du bief", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -238,37 +238,37 @@ describe("Class Remous / section rectangulaire :", () => { // let f = { 5.500: 1, 5.250: 0.987, 5.000: 0.974, 4.750: 0.96, 4.500: 0.947, 4.250: 0.933, 4.000: 0.92, 3.750: 0.906, 3.500: 0.893, 3.250: 0.88, 3.000: 0.866, 2.750: 0.853, 2.500: 0.839, 2.250: 0.826, 2.000: 0.812, 1.750: 0.798, 1.500: 0.784, 1.250: 0.77, 1.000: 0.756, 0.750: 0.742, 0.500: 0.727, 0.250: 0.712, 0.000: 0.15 }; const f = { 5.500: 1, 5.250: 0.987, 5.000: 0.974, 4.750: 0.96, 4.500: 0.947, 4.250: 0.933, 4.000: 0.92, 3.750: 0.906, 3.500: 0.893, 3.250: 0.88, 3.000: 0.866, 2.750: 0.853, 2.500: 0.839, 2.250: 0.826, 2.000: 0.812, 1.750: 0.798, 1.500: 0.784, 1.250: 0.77, 1.000: 0.756, 0.750: 0.742, 0.500: 0.727, 0.250: 0.712, 0.000: 0.699 }; // dernière valeur modifiée pour la raison 1 en tête de fichier - compareObject("Yfluvial", res.flu, f, 0.03); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03); const t = { 0.000: 0.15, 0.250: 0.153, 0.500: 0.156, 0.750: 0.158, 1.000: 0.161, 1.250: 0.163, 1.500: 0.166, 1.750: 0.168, 2.000: 0.17, 2.250: 0.173, 2.500: 0.175, 2.750: 0.177, 3.000: 0.18, 3.250: 0.182, 3.500: 0.184, 3.750: 0.906 }; - compareObject("Ytorrentiel", res.tor, t, 0.03); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.03); const x = [0.000, 0.250, 0.500, 0.750, 1.000, 1.250, 1.500, 1.750, 2.000, 2.250, 2.500, 2.750, 3.000, 3.250, 3.500, 3.750, 4.000, 4.250, 4.500, 4.750, 5.000, 5.250, 5.500]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_FLUVIAL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_FLUVIAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - m = new Message(MessageCode.ERROR_REMOUS_RESSAUT_HYDRO); + m = new Message(MessageCode.INFO_REMOUS_RESSAUT_HYDRO); m.extraVar.xmin = 0; m.extraVar.xmax = 3.75; expLog.add(m); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yamont < Yn", () => { @@ -296,38 +296,39 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes - expect(Object.keys(res.flu).length === 0).toBeTruthy( + expect(res.extraResultLength("flu") == 0).toBeTruthy( "la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.1, 5.000: 0.205, 10.000: 0.234, 15.000: 0.246, 20.000: 0.25, 25.000: 0.252, 30.000: 0.253, 35.000: 0.253, 40.000: 0.253, 45.000: 0.253, 50.000: 0.253, 55.000: 0.253, 60.000: 0.253, 65.000: 0.253, 70.000: 0.253, 75.000: 0.253, 80.000: 0.253, 85.000: 0.253, - 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 }; - compareObject("Ytorrentiel", res.tor, t, 0.01); + 90.000: 0.253, 95.000: 0.253, 100.000: 0.253 + }; + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.01); const x = [0.000, 5.000, 10.000, 15.000, 20.000, 25.000, 30.000, 35.000, 40.000, 45.000, 50.000, 55.000, 60.000, 65.000, 70.000, 75.000, 80.000, 85.000, 90.000, 95.000, 100.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); it("forte pente, pas de ressaut, Yaval < Yc, Yn < Yamont < Yc", () => { @@ -355,32 +356,32 @@ describe("Class Remous / section rectangulaire :", () => { // données de validation : version PHP (Oct 2017) méthode trapèzes - expect(Object.keys(res.flu).length === 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); + expect(res.extraResultLength("flu") == 0).toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur"); const t = { 0.000: 0.35, 0.100: 0.345, 0.200: 0.34, 0.300: 0.336, 0.400: 0.332, 0.500: 0.329, 0.600: 0.326, 0.700: 0.323, 0.800: 0.32, 0.900: 0.318, 1.000: 0.316, 1.100: 0.313, 1.200: 0.311, 1.300: 0.309, 1.400: 0.308, 1.500: 0.306, 1.600: 0.305, 1.700: 0.303, 1.800: 0.302, 1.900: 0.3, 2.000: 0.298, 2.100: 0.297, 2.200: 0.295, 2.300: 0.294, 2.400: 0.293, 2.500: 0.292, 2.600: 0.291, 2.700: 0.291, 2.800: 0.29, 2.900: 0.289, 3.000: 0.288, 3.100: 0.287, 3.200: 0.287, 3.300: 0.286, 3.400: 0.285, 3.500: 0.284, 3.600: 0.283, 3.700: 0.283, 3.800: 0.282, 3.900: 0.281, 4.000: 0.28, 4.100: 0.28, 4.200: 0.279, 4.300: 0.278, 4.400: 0.277, 4.500: 0.276, 4.600: 0.276, 4.700: 0.275, 4.800: 0.274, 4.900: 0.273, 5.000: 0.272, 5.100: 0.272, 5.200: 0.271, 5.300: 0.27, 5.400: 0.269, 5.500: 0.269, 5.600: 0.269, 5.700: 0.269, 5.800: 0.269, 5.900: 0.269, 6.000: 0.269, 6.100: 0.269, 6.200: 0.269, 6.300: 0.269, 6.400: 0.269, 6.500: 0.269, 6.600: 0.269, 6.700: 0.269, 6.800: 0.269, 6.900: 0.269, 7.000: 0.269, 7.100: 0.269, 7.200: 0.269, 7.300: 0.269, 7.400: 0.269, 7.500: 0.269, 7.600: 0.269, 7.700: 0.269, 7.800: 0.269, 7.900: 0.269, 8.000: 0.269, 8.100: 0.269, 8.200: 0.269, 8.300: 0.269, 8.400: 0.269, 8.500: 0.269, 8.600: 0.269, 8.700: 0.269, 8.800: 0.269, 8.900: 0.269, 9.000: 0.269, 9.100: 0.269, 9.200: 0.269, 9.300: 0.269, 9.400: 0.269, 9.500: 0.269, 9.600: 0.269, 9.700: 0.269, 9.800: 0.269, 9.900: 0.269, 10.000: 0.269 }; - compareObject("Ytorrentiel", res.tor, t, 0.01); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.01); const x = [0.000, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800, 1.900, 2.000, 2.100, 2.200, 2.300, 2.400, 2.500, 2.600, 2.700, 2.800, 2.900, 3.000, 3.100, 3.200, 3.300, 3.400, 3.500, 3.600, 3.700, 3.800, 3.900, 4.000, 4.100, 4.200, 4.300, 4.400, 4.500, 4.600, 4.700, 4.800, 4.900, 5.000, 5.100, 5.200, 5.300, 5.400, 5.500, 5.600, 5.700, 5.800, 5.900, 6.000, 6.100, 6.200, 6.300, 6.400, 6.500, 6.600, 6.700, 6.800, 6.900, 7.000, 7.100, 7.200, 7.300, 7.400, 7.500, 7.600, 7.700, 7.800, 7.900, 8.000, 8.100, 8.200, 8.300, 8.400, 8.500, 8.600, 8.700, 8.800, 8.900, 9.000, 9.100, 9.200, 9.300, 9.400, 9.500, 9.600, 9.700, 9.800, 9.900, 10.000]; - compareArray("abscisses", res.trX, x); + compareArray("abscisses", res.getExtraResult("trX"), x); const expLog = new cLog(); - let m = new Message(MessageCode.ERROR_REMOUS_LARGEUR_BERGE); + let m = new Message(MessageCode.INFO_REMOUS_LARGEUR_BERGE); m.extraVar.B = 2.5; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_CRITIQUE); + m = new Message(MessageCode.INFO_REMOUS_H_CRITIQUE); m.extraVar.Yc = 0.403; expLog.add(m); - m = new Message(MessageCode.ERROR_REMOUS_H_NORMALE); + m = new Message(MessageCode.INFO_REMOUS_H_NORMALE); m.extraVar.Yn = 0.253; expLog.add(m); expLog.add(new Message(MessageCode.ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL)); - expLog.add(new Message(MessageCode.ERROR_REMOUS_CALCUL_TORRENTIEL)); + expLog.add(new Message(MessageCode.INFO_REMOUS_CALCUL_TORRENTIEL)); - compareLog(rem.log, expLog); + compareLog(res.log, expLog); }); }); }); diff --git a/spec/remous/remous_trapez.spec.ts b/spec/remous/remous_trapez.spec.ts index 49594e031173e8e795a0a851b89d74dc2157f722..563c42cea8bbbd2bd51b57af7ac7f02d7e935d7a 100644 --- a/spec/remous/remous_trapez.spec.ts +++ b/spec/remous/remous_trapez.spec.ts @@ -1,9 +1,8 @@ -import { round } from "../../src/base"; import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; import { cLog } from "../../src/util/log"; -import { equalEpsilon, precDigits, precDist } from "../nubtest"; -import { compareArray, compareObject } from "../nubtest"; +import { equalEpsilon, compareArray, compareObject } from "../test_func"; +import { precDist } from "../test_config"; /* Certaines valeurs de ligne d'eau torrentielle étaient auparavant remplacées par une valeur fluviale @@ -39,14 +38,14 @@ describe("Class Remous / section trapèze :", () => { const res = rem.calculRemous(undefined); const f = { 9: 0.278, 10: 0.4 }; - compareObject("Yfluvial", res.flu, f, 0.002); + compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.002); // let t = { 0.000: 0.15, 1.000: 0.16369914454109, 2.000: 0.17743613485223, 3.000: 0.19117312516337, 4.000: 0.20491011547451, 5.000: 0.21864710578565, 6.000: 0.23238409609679, 7.000: 0.24688425253633, 8.000: 0.26214757510426, 9.000: 0.27817406380059, 10.000: 0.4 }; const t = { 0.000: 0.15, 1.000: 0.16369914454109, 2.000: 0.17743613485223, 3.000: 0.19117312516337, 4.000: 0.20491011547451, 5.000: 0.21864710578565, 6.000: 0.23238409609679, 7.000: 0.24688425253633, 8.000: 0.26214757510426, 9.000: 0.27817406380059, 10.000: 0.293 }; // dernière valeur modifiée pour la raison en tête de fichier - compareObject("Ytorrentiel", res.tor, t, 0.002); + compareObject("Ytorrentiel", res.getExtraResult("tor"), t, 0.002); const x = [0.000, 1.000, 2.000, 3.000, 4.000, 5.000, 6.000, 7.000, 8.000, 9.000, 10.000]; - compareArray("abcisses", res.trX, x); + compareArray("abcisses", res.getExtraResult("trX"), x); }); // it('pente forte, ressaut dans le bief sur plusieurs points', () => { @@ -113,7 +112,7 @@ describe("Class Remous / section trapèze :", () => { // données de validation : version PHP (oct 2017) const hs = { 0.000: 1.507, 5.000: 0.735, 10.000: 0.731, 15.000: 0.727, 20.000: 0.723, 25.000: 0.719, 30.000: 0.715, 35.000: 0.71, 40.000: 0.704, 45.000: 0.699, 50.000: 0.693, 55.000: 0.687, 60.000: 0.68, 65.000: 0.673, 70.000: 0.665, 75.000: 0.656, 80.000: 0.646, 85.000: 0.634, 90.000: 0.62, 95.000: 0.603, 100.000: 0.572 }; - compareObject("Hs", res.tRes, hs, 0.002); + compareObject("Hs", res.getExtraResult("tRes"), hs, 0.002); }); xit("Hs (test 2)", () => { // désactivé car échoue depuis les modifs apportées depuis la version PHP (calcul du ressaut hydraulique) @@ -144,7 +143,7 @@ describe("Class Remous / section trapèze :", () => { // données de validation : version PHP (oct 2017) // ici j'ai supprimé un point (x=2.5) const hs = { 0.000: 1.507, 2.600: 0.753, 2.700: 0.757, 2.800: 0.762, 2.900: 0.767, 3.000: 0.771, 3.100: 0.776, 3.200: 0.781, 3.300: 0.786, 3.400: 0.79, 3.500: 0.795, 3.600: 0.8, 3.700: 0.805, 3.800: 0.81, 3.900: 0.814, 4.000: 0.819, 4.100: 0.824, 4.200: 0.829, 4.300: 0.834, 4.400: 0.839, 4.500: 0.844, 4.600: 0.849, 4.700: 0.854, 4.800: 0.859, 4.900: 0.864, 5.000: 0.869, 5.100: 0.874, 5.200: 0.879, 5.300: 0.884, 5.400: 0.889, 5.500: 0.894, 5.600: 0.899, 5.700: 0.904, 5.800: 0.909, 5.900: 0.914, 6.000: 0.919, 6.100: 0.924, 6.200: 0.929, 6.300: 0.934, 6.400: 0.939, 6.500: 0.944, 6.600: 0.95, 6.700: 0.955, 6.800: 0.96, 6.900: 0.965, 7.000: 0.97, 7.100: 0.975, 7.200: 0.98, 7.300: 0.986, 7.400: 0.991, 7.500: 0.996, 7.600: 1.001, 7.700: 1.006, 7.800: 1.012, 7.900: 1.017, 8.000: 1.022 }; - compareObject("Hs", res.tRes, hs, 0.009); + compareObject("Hs", res.getExtraResult("tRes"), hs, 0.009); }); }); }); diff --git a/spec/remous/test-remous-fenetre.ts b/spec/remous/test-remous-fenetre.ts index 1a1a89fee7bb12e4a943dd83bc8a5c75034f544d..618f98fd26ef4e1fc0fdf3173d542c326d7a6975 100644 --- a/spec/remous/test-remous-fenetre.ts +++ b/spec/remous/test-remous-fenetre.ts @@ -1,9 +1,8 @@ // tslint:disable:no-console import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "../../src/remous"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; -import { cLog } from "../../src/util/log"; -import { Message, MessageCode, MessageSeverity } from "../../src/util/message"; -import { equalEpsilon, nub, precDist } from "../nubtest"; +import { equalEpsilon, compareArray } from "../test_func"; +import { Result, CalcResult } from "../../src/util/result"; /* Tentative de validation automatique du calcul des courbes de remous. @@ -16,21 +15,6 @@ import { equalEpsilon, nub, precDist } from "../nubtest"; $ npm run runtestremous */ -class Expect { - constructor(private b: boolean) { - - } - public toBeTruthy(m: string) { - if (!this.b) { - console.log(m); - } - } -} - -function expect(b: boolean): Expect { - return new Expect(b); -} - export function compareObject( s: string, objTest: { [key: number]: number }, @@ -70,24 +54,6 @@ export function compareObject( return true; } -export function compareArray(s: string, arrTest: string[], arrValid: string[]): boolean { - const n1 = arrTest.length; - const n2 = arrValid.length; - let b: boolean = n1 === n2; - expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); - if (!b) { return false; } - - for (let i = 0; i < arrTest.length; i++) { - const v1: number = +arrTest[i]; - const v2: number = +arrValid[i]; - b = equalEpsilon(v1, v2); - expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); - if (!b) { return false; } - } - - return true; -} - function logObject(obj: {}, m?: string) { // évite le message "Value below was evaluated just now" dans le debugger de Chrome if (m === undefined) { @@ -217,52 +183,64 @@ function testFenetre() { // calcul du bief const r = computeFenetreRect(Yamont, Yaval, longBief, false); - const res: { - "flu": { [key: number]: number; }, - "tor": { [key: number]: number; }, - "trX": string[], - "tRes": { [key: number]: number }, - } = r.res; + // const res: { + // "flu": { [key: number]: number; }, + // "tor": { [key: number]: number; }, + // "trX": string[], + // "tRes": { [key: number]: number }, + // } = r.res; + const res: CalcResult = r.res; + expect(res.ok).toBeTruthy("erreur de calcul de la courbe globale"); const remous = r.remous; // ligne fluviale totale, utilisée pour les conditions initiales - const ligneFluviale: { [key: number]: number; } = remous.calculFluvial(); + // const ligneFluviale: { [key: number]: number; } = remous.calculFluvial(); + const rLigneFluviale: Result = remous.calculFluvial(); + expect(rLigneFluviale.ok).toBeTruthy("erreur de calcul de la ligne fluviale"); + const ligneFluviale: { [key: number]: number; } = rLigneFluviale.extraResults["trY"]; // ligne torrentielle totale, utilisée pour les conditions initiales - const ligneTorrentielle: { [key: number]: number; } = remous.calculTorrentiel(); + // const ligneTorrentielle: { [key: number]: number; } = remous.calculTorrentiel(); + const rLigneTorrentielle: Result = remous.calculTorrentiel(); + expect(rLigneTorrentielle.ok).toBeTruthy("erreur de calcul de la ligne torrentielle"); + const ligneTorrentielle: { [key: number]: number; } = rLigneTorrentielle.extraResults["trY"]; console.log(remous.log.toString()); // let ms = r["remous"].log.messages; + const trX = res.getExtraResult("trX"); + const flu = res.getExtraResult("flu"); + const tor = res.getExtraResult("tor"); + // saveCSV(res); console.log("X"); - logObject(res.trX); - logArray("flu", res.flu); - logArray("tor", res.tor); + logObject(trX); + logArray("flu", flu); + logArray("tor", tor); // mouvement de la fenêtre console.log("\n\nMOUVEMENT DE LA FENETRE\n\n"); - const sizeFenetre = Math.round(res.trX.length / 3.5); + const sizeFenetre = Math.round(trX.length / 3.5); console.log("taille de la fenetre (points) " + sizeFenetre); if (sizeFenetre < 3) { throw new Error("pas de discrétisation trop grand !"); } - const nFlu = Object.keys(res.flu).length; + const nFlu = Object.keys(flu).length; if (nFlu < sizeFenetre * 2) { throw new Error("pb de calcul de la ligne fluviale : nb de points (" + nFlu + ") < fenetre * 2"); } - const nTor = Object.keys(res.tor).length; + const nTor = Object.keys(tor).length; if (nTor < sizeFenetre * 2) { throw new Error("pb de calcul de la ligne torrentielle : nb de points (" + nTor + ") < fenetre * 2"); } - const nX = res.trX.length; + const nX = trX.length; console.log("taille du bief (points)=" + nX); const ni = 13; @@ -271,8 +249,8 @@ function testFenetre() { console.log("i1", i1); const i2 = i1 + sizeFenetre - 1; - const xBief1: number = Number(res.trX[i1]); - const xBief2: number = Number(res.trX[i2]); + const xBief1: number = Number(trX[i1]); + const xBief2: number = Number(trX[i2]); console.log("test fenetre xBief=[" + xBief1 + "," + xBief2 + "]"); console.log("longueur fenetre " + (+xBief2 - +xBief1)); @@ -304,19 +282,23 @@ function testFenetre() { console.log("computeFenetre y am/av=" + yAmont + " " + yAval); const r2 = computeFenetreRect(yAmont, yAval, +xBief2 - +xBief1, i1 === ni); - const resFenetre = r2.res; + const resFenetre: CalcResult = r2.res; + expect(resFenetre.ok).toBeTruthy("erreur de calcul de la fenêtre"); + let trX_fenetre = resFenetre.getExtraResult("trX"); + let flu_fenetre = resFenetre.getExtraResult("flu"); + let tor_fenetre = resFenetre.getExtraResult("tor"); // validation du tableau d'abscisses - const validX: string[] = []; + const validX: number[] = []; for (let i = i1; i <= i2; i++) { - validX.push(String(+res.trX[i] - dxBief * i1)); + validX.push(+trX[i] - dxBief * i1); } - if (!compareArray("X", resFenetre.trX, validX)) { + if (!compareArray("X", trX_fenetre, validX)) { console.log("X valid"); logObject(validX); console.log("X fenetre"); - logObject(resFenetre.trX); + logObject(trX_fenetre); break; } /**/ @@ -328,19 +310,19 @@ function testFenetre() { const validFlu: { [key: number]: number; } = {}; for (let i = i1; i <= i2; i++) { - const x: number = +res.trX[i]; - const y: number = res.flu[x]; + const x: number = +trX[i]; + const y: number = flu[x]; if (y !== undefined) { validFlu[(i - i1) * dxBief] = y; } // validFlu[x] = y; } if (Object.keys(validFlu).length > 0) { - if (!compareObject("Flu", resFenetre.flu, validFlu, prec)) { + if (!compareObject("Flu", flu_fenetre, validFlu, prec)) { console.log("flu valid"); logObject(validFlu); console.log("flu fenetre"); - logObject(resFenetre.flu); + logObject(flu_fenetre); // break; } } @@ -350,19 +332,19 @@ function testFenetre() { const validTor: { [key: number]: number; } = {}; for (let i = i1; i <= i2; i++) { - const x: number = +res.trX[i]; - const y: number = res.tor[x]; + const x: number = +trX[i]; + const y: number = tor[x]; if (y !== undefined) { validTor[(i - i1) * dxBief] = y; } // validTor[x] = y; } if (Object.keys(validTor).length > 0) { - if (!compareObject("Tor", resFenetre.tor, validTor, prec)) { + if (!compareObject("Tor", tor_fenetre, validTor, prec)) { console.log("tor valid"); logObject(validTor); console.log("tor fenetre"); - logObject(resFenetre.tor); + logObject(tor_fenetre); // break; } } diff --git a/spec/section_param/section_param_circ_fluvial.spec.ts b/spec/section_param/section_param_circ_fluvial.spec.ts index 50c651bb557ab2c8928aeab3f6150d6c1b2d5019..b301178606bede9e0c634e2600f02ab43e42075f 100644 --- a/spec/section_param/section_param_circ_fluvial.spec.ts +++ b/spec/section_param/section_param_circ_fluvial.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionCirc; let sect: cSnCirc; @@ -31,10 +31,6 @@ function createSectionDebordement(prec: number): cSnCirc { return new cSnCirc(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée circulaire : ", () => { beforeEach(() => { sect = createSection(precDist); @@ -43,89 +39,89 @@ describe("Section paramétrée circulaire : ", () => { describe("fluvial / pas de débordement :", () => { // charge spécifique it("Hs should equal to 0.853", () => { - check(sect.Calc("Hs"), 0.853); + checkResult(sect.Calc("Hs"), 0.853); }); // charge critique it("Hsc should equal to 0.694", () => { - check(sect.Calc("Hsc"), 0.694); + checkResult(sect.Calc("Hsc"), 0.694); }); // largeur au miroir it("B should equal to 1.959", () => { - check(sect.Calc("B"), 1.959); + checkResult(sect.Calc("B"), 1.959); }); // périmètre mouillé it("P should equal to 2.738", () => { - check(sect.Calc("P"), 2.738); + checkResult(sect.Calc("P"), 2.738); }); // surface mouillée it("S should equal to 1.173", () => { - check(sect.Calc("S"), 1.173); + checkResult(sect.Calc("S"), 1.173); }); // rayon hydraulique it("R should equal to 0.428", () => { - check(sect.Calc("R"), 0.428); + checkResult(sect.Calc("R"), 0.428); }); // vitesse moyenne it("V should equal to 1.023", () => { - check(sect.Calc("V"), 1.023); + checkResult(sect.Calc("V"), 1.023); }); // nombre de Froude it("Fr should equal to 0.422", () => { - check(sect.Calc("Fr"), 0.422); + checkResult(sect.Calc("Fr"), 0.422); }); // tirant d'eau critique it("Yc should equal to 0.512", () => { - check(sect.Calc("Yc"), 0.512); + checkResult(sect.Calc("Yc"), 0.512); }); // tirant d'eau normal it("Yn should equal to 0.976", () => { - check(sect.Calc("Yn"), 0.976); + checkResult(sect.Calc("Yn"), 0.976); }); // tirant d'eau fluvial it("Yf should equal to 0.8", () => { - check(sect.Calc("Yf"), 0.8); + checkResult(sect.Calc("Yf"), 0.8); }); // tirant d'eau torrentiel it("Yt should equal to 0.361", () => { - check(sect.Calc("Yt"), 0.361); + checkResult(sect.Calc("Yt"), 0.361); }); // tirant d'eau conjugué it("Yco should equal to 0.307", () => { - check(sect.Calc("Yco"), 0.307); + checkResult(sect.Calc("Yco"), 0.307); }); // perte de charge it("J should equal to 0.002", () => { // sect = createSection(0.00001); - check(sect.Calc("J"), 0.002); + checkResult(sect.Calc("J"), 0.002); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to -0.00102", () => { sect = createSection(0.00001); - check(sect.Calc("I-J"), -0.00102); + checkResult(sect.Calc("I-J"), -0.00102); }); // impulsion hydraulique it("Imp should equal to 5076.304", () => { - check(sect.Calc("Imp"), 5076.304); + checkResult(sect.Calc("Imp"), 5076.304); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 8.505", () => { - check(sect.Calc("Tau0"), 8.505); + checkResult(sect.Calc("Tau0"), 8.505); }); }); }); @@ -138,89 +134,89 @@ describe("Section paramétrée circulaire : ", () => { describe("fluvial / débordement :", () => { // charge spécifique it("Hs should equal to 2.006", () => { - check(sect.Calc("Hs"), 2.006); + checkResult(sect.Calc("Hs"), 2.006); }); // charge critique it("Hsc should equal to 0.694", () => { - check(sect.Calc("Hsc"), 0.694); + checkResult(sect.Calc("Hsc"), 0.694); }); // largeur au miroir it("B should equal to 2", () => { - check(sect.Calc("B"), 2); + checkResult(sect.Calc("B"), 2); }); // périmètre mouillé it("P should equal to 5.142", () => { - check(sect.Calc("P"), 5.142); + checkResult(sect.Calc("P"), 5.142); }); // surface mouillée it("S should equal to 3.571", () => { - check(sect.Calc("S"), 3.571); + checkResult(sect.Calc("S"), 3.571); }); // rayon hydraulique it("R should equal to 0.694", () => { - check(sect.Calc("R"), 0.694); + checkResult(sect.Calc("R"), 0.694); }); // vitesse moyenne it("V should equal to 0.336", () => { - check(sect.Calc("V"), 0.336); + checkResult(sect.Calc("V"), 0.336); }); // nombre de Froude it("Fr should equal to 0.08", () => { - check(sect.Calc("Fr"), 0.08); + checkResult(sect.Calc("Fr"), 0.08); }); // tirant d'eau critique it("Yc should equal to 0.512", () => { - check(sect.Calc("Yc"), 0.512); + checkResult(sect.Calc("Yc"), 0.512); }); // tirant d'eau normal it("Yn should equal to 0.976", () => { - check(sect.Calc("Yn"), 0.976); + checkResult(sect.Calc("Yn"), 0.976); }); // tirant d'eau fluvial it("Yf should equal to 2", () => { - check(sect.Calc("Yf"), 2); + checkResult(sect.Calc("Yf"), 2); }); // tirant d'eau torrentiel it("Yt should equal to 0.232", () => { - check(sect.Calc("Yt"), 0.232); + checkResult(sect.Calc("Yt"), 0.232); }); // tirant d'eau conjugué it("Yco should equal to 0.24", () => { - check(sect.Calc("Yco"), 0.24); + checkResult(sect.Calc("Yco"), 0.24); }); // perte de charge it("J should equal to 0.0001", () => { sect = createSectionDebordement(0.00001); - check(sect.Calc("J"), 0.0001); + checkResult(sect.Calc("J"), 0.0001); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.001", () => { sect = createSectionDebordement(0.00001); - check(sect.Calc("I-J"), 0.001); + checkResult(sect.Calc("I-J"), 0.001); }); // impulsion hydraulique it("Imp should equal to 6943.271", () => { - check(sect.Calc("Imp"), 6943.271); + checkResult(sect.Calc("Imp"), 6943.271); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 0.782", () => { - check(sect.Calc("Tau0"), 0.782); + checkResult(sect.Calc("Tau0"), 0.782); }); }); }); diff --git a/spec/section_param/section_param_circ_torrentiel.spec.ts b/spec/section_param/section_param_circ_torrentiel.spec.ts index 917eb5e3354a24977d7691dd5f22a11191368590..35a11220ca9f03fac04cd86a49fc41ad91ccf705 100644 --- a/spec/section_param/section_param_circ_torrentiel.spec.ts +++ b/spec/section_param/section_param_circ_torrentiel.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionCirc; let sect: cSnCirc; @@ -18,10 +18,6 @@ function createSection(prec: number): cSnCirc { return new cSnCirc(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée circulaire : ", () => { beforeEach(() => { sect = createSection(precDist); @@ -30,89 +26,89 @@ describe("Section paramétrée circulaire : ", () => { describe("torrentiel :", () => { // charge spécifique it("Hs should equal to 4.501", () => { - check(sect.Calc("Hs"), 4.501); + checkResult(sect.Calc("Hs"), 4.501); }); // charge critique it("Hsc should equal to 2.263", () => { - check(sect.Calc("Hsc"), 2.263); + checkResult(sect.Calc("Hsc"), 2.263); }); // largeur au miroir it("B should equal to 1.960", () => { - check(sect.Calc("B"), 1.960); + checkResult(sect.Calc("B"), 1.960); }); // périmètre mouillé it("P should equal to 2.739", () => { - check(sect.Calc("P"), 2.739); + checkResult(sect.Calc("P"), 2.739); }); // surface mouillée it("S should equal to 1.173", () => { - check(sect.Calc("S"), 1.173); + checkResult(sect.Calc("S"), 1.173); }); // rayon hydraulique it("R should equal to 0.428", () => { - check(sect.Calc("R"), 0.428); + checkResult(sect.Calc("R"), 0.428); }); // vitesse moyenne it("V should equal to 8.522", () => { - check(sect.Calc("V"), 8.522); + checkResult(sect.Calc("V"), 8.522); }); // nombre de Froude it("Fr should equal to 3.516", () => { - check(sect.Calc("Fr"), 3.516); + checkResult(sect.Calc("Fr"), 3.516); }); // tirant d'eau critique it("Yc should equal to 1.581", () => { - check(sect.Calc("Yc"), 1.581); + checkResult(sect.Calc("Yc"), 1.581); }); // tirant d'eau normal it("Yn should equal to 4.624", () => { - check(sect.Calc("Yn"), 4.624); + checkResult(sect.Calc("Yn"), 4.624); }); // tirant d'eau fluvial it("Yf should equal to 4.43", () => { - check(sect.Calc("Yf"), 4.43); + checkResult(sect.Calc("Yf"), 4.43); }); // tirant d'eau torrentiel it("Yt should equal to 0.8", () => { - check(sect.Calc("Yt"), 0.8); + checkResult(sect.Calc("Yt"), 0.8); }); // tirant d'eau conjugué it("Yco should equal to 0.8", () => { - check(sect.Calc("Yco"), 0.8); + checkResult(sect.Calc("Yco"), 0.8); }); // perte de charge it("J should equal to 0.141", () => { // sect = createSection(0.00001); - check(sect.Calc("J"), 0.141); + checkResult(sect.Calc("J"), 0.141); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to -0.14", () => { // sect = createSection(0.00001); - check(sect.Calc("I-J"), -0.14); + checkResult(sect.Calc("I-J"), -0.14); }); // impulsion hydraulique it("Imp should equal to 89065.861", () => { - check(sect.Calc("Imp"), 89065.861); + checkResult(sect.Calc("Imp"), 89065.861); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 590.605", () => { - check(sect.Calc("Tau0"), 590.605); + checkResult(sect.Calc("Tau0"), 590.605); }); }); }); diff --git a/spec/section_param/section_param_puiss_fluvial.spec.ts b/spec/section_param/section_param_puiss_fluvial.spec.ts index 5b5df72221b9509e61c7508da5dee1a902348ea2..221092f4ffee3694762891fb2b80136207ba4fd2 100644 --- a/spec/section_param/section_param_puiss_fluvial.spec.ts +++ b/spec/section_param/section_param_puiss_fluvial.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionPuiss; let sect: cSnPuiss; @@ -33,10 +33,6 @@ function createSectionDebordement(prec: number): cSnPuiss { return new cSnPuiss(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée puissance :", () => { beforeEach(() => { sect = createSection(precDist); @@ -45,89 +41,89 @@ describe("Section paramétrée puissance :", () => { describe("fluvial / pas de débordement :", () => { // charge spécifique it("Hs should equal to 0.82", () => { - check(sect.Calc("Hs"), 0.82); + checkResult(sect.Calc("Hs"), 0.82); }); // charge critique it("Hsc should equal to 0.559", () => { - check(sect.Calc("Hsc"), 0.559); + checkResult(sect.Calc("Hsc"), 0.559); }); // largeur au miroir it("B should equal to 3.578", () => { - check(sect.Calc("B"), 3.578); + checkResult(sect.Calc("B"), 3.578); }); // périmètre mouillé it("P should equal to 4.223", () => { - check(sect.Calc("P"), 4.223); + checkResult(sect.Calc("P"), 4.223); }); // surface mouillée it("S should equal to 1.908", () => { - check(sect.Calc("S"), 1.908); + checkResult(sect.Calc("S"), 1.908); }); // rayon hydraulique it("R should equal to 0.452", () => { - check(sect.Calc("R"), 0.452); + checkResult(sect.Calc("R"), 0.452); }); // vitesse moyenne it("V should equal to 0.629", () => { - check(sect.Calc("V"), 0.629); + checkResult(sect.Calc("V"), 0.629); }); // nombre de Froude it("Fr should equal to 0.275", () => { - check(sect.Calc("Fr"), 0.275); + checkResult(sect.Calc("Fr"), 0.275); }); // tirant d'eau critique it("Yc should equal to 0.419", () => { - check(sect.Calc("Yc"), 0.419); + checkResult(sect.Calc("Yc"), 0.419); }); // tirant d'eau normal it("Yn should equal to 0.742", () => { - check(sect.Calc("Yn"), 0.742); + checkResult(sect.Calc("Yn"), 0.742); }); // tirant d'eau fluvial it("Yf should equal to 0.8", () => { - check(sect.Calc("Yf"), 0.8); + checkResult(sect.Calc("Yf"), 0.8); }); // tirant d'eau torrentiel it("Yt should equal to 0.265", () => { - check(sect.Calc("Yt"), 0.265); + checkResult(sect.Calc("Yt"), 0.265); }); // tirant d'eau conjugué it("Yco should equal to 0.189", () => { - check(sect.Calc("Yco"), 0.189); + checkResult(sect.Calc("Yco"), 0.189); }); // perte de charge it("J should equal to 0.0007", () => { sect = createSection(0.00001); - check(sect.Calc("J"), 0.0007); + checkResult(sect.Calc("J"), 0.0007); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.000335", () => { sect = createSection(0.000001); - check(sect.Calc("I-J"), 0.000335); + checkResult(sect.Calc("I-J"), 0.000335); }); // impulsion hydraulique it("Imp should equal to 6744.616", () => { - check(sect.Calc("Imp"), 6744.616); + checkResult(sect.Calc("Imp"), 6744.616); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 3.16", () => { - check(sect.Calc("Tau0"), 3.16); + checkResult(sect.Calc("Tau0"), 3.16); }); }); }); @@ -140,89 +136,89 @@ describe("Section paramétrée puissance :", () => { describe("fluvial / débordement :", () => { // charge spécifique it("Hs should equal to 2.001", () => { - check(sect.Calc("Hs"), 2.001); + checkResult(sect.Calc("Hs"), 2.001); }); // charge critique it("Hsc should equal to 0.559", () => { - check(sect.Calc("Hsc"), 0.559); + checkResult(sect.Calc("Hsc"), 0.559); }); // largeur au miroir it("B should equal to 4", () => { - check(sect.Calc("B"), 4); + checkResult(sect.Calc("B"), 4); }); // périmètre mouillé it("P should equal to 6.098", () => { - check(sect.Calc("P"), 6.098); + checkResult(sect.Calc("P"), 6.098); }); // surface mouillée it("S should equal to 7.542", () => { - check(sect.Calc("S"), 7.542); + checkResult(sect.Calc("S"), 7.542); }); // rayon hydraulique it("R should equal to 1.237", () => { - check(sect.Calc("R"), 1.237); + checkResult(sect.Calc("R"), 1.237); }); // vitesse moyenne it("V should equal to 0.159", () => { - check(sect.Calc("V"), 0.159); + checkResult(sect.Calc("V"), 0.159); }); // nombre de Froude it("Fr should equal to 0.037", () => { - check(sect.Calc("Fr"), 0.037); + checkResult(sect.Calc("Fr"), 0.037); }); // tirant d'eau critique it("Yc should equal to 0.419", () => { - check(sect.Calc("Yc"), 0.419); + checkResult(sect.Calc("Yc"), 0.419); }); // tirant d'eau normal it("Yn should equal to 0.742", () => { - check(sect.Calc("Yn"), 0.742); + checkResult(sect.Calc("Yn"), 0.742); }); // tirant d'eau fluvial it("Yf should equal to 2", () => { - check(sect.Calc("Yf"), 2); + checkResult(sect.Calc("Yf"), 2); }); // tirant d'eau torrentiel it("Yt should equal to 0.178", () => { - check(sect.Calc("Yt"), 0.178); + checkResult(sect.Calc("Yt"), 0.178); }); // tirant d'eau conjugué it("Yco should equal to 0.044", () => { - check(sect.Calc("Yco"), 0.044); + checkResult(sect.Calc("Yco"), 0.044); }); // perte de charge it("J should equal to 0.00059", () => { sect = createSection(0.00001); - check(sect.Calc("J"), 0.00059); + checkResult(sect.Calc("J"), 0.00059); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.00041", () => { sect = createSection(0.00001); - check(sect.Calc("I-J"), 0.00041); + checkResult(sect.Calc("I-J"), 0.00041); }); // impulsion hydraulique it("Imp should equal to 59384.242", () => { - check(sect.Calc("Imp"), 59384.242); + checkResult(sect.Calc("Imp"), 59384.242); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 0.145", () => { - check(sect.Calc("Tau0"), 0.145); + checkResult(sect.Calc("Tau0"), 0.145); }); }); }); diff --git a/spec/section_param/section_param_puiss_torrentiel.spec.ts b/spec/section_param/section_param_puiss_torrentiel.spec.ts index 6cc2be4a7041d2a29a7fe0c835b73838625a9a56..f49ce1bb8318ae2ec0136b543d4992d0c06176da 100644 --- a/spec/section_param/section_param_puiss_torrentiel.spec.ts +++ b/spec/section_param/section_param_puiss_torrentiel.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionPuiss; let sect: cSnPuiss; @@ -19,10 +19,6 @@ function createSection(prec: number): cSnPuiss { return new cSnPuiss(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée puissance :", () => { beforeEach(() => { sect = createSection(precDist); @@ -31,89 +27,89 @@ describe("Section paramétrée puissance :", () => { describe("torrentiel / pas de débordement :", () => { // charge spécifique it("Hs should equal to 2.2", () => { - check(sect.Calc("Hs"), 2.2); + checkResult(sect.Calc("Hs"), 2.2); }); // charge critique it("Hsc should equal to 1.616", () => { - check(sect.Calc("Hsc"), 1.616); + checkResult(sect.Calc("Hsc"), 1.616); }); // largeur au miroir it("B should equal to 3.578", () => { - check(sect.Calc("B"), 3.578); + checkResult(sect.Calc("B"), 3.578); }); // périmètre mouillé it("P should equal to 4.223", () => { - check(sect.Calc("P"), 4.223); + checkResult(sect.Calc("P"), 4.223); }); // surface mouillée it("S should equal to 1.908", () => { - check(sect.Calc("S"), 1.908); + checkResult(sect.Calc("S"), 1.908); }); // rayon hydraulique it("R should equal to 0.452", () => { - check(sect.Calc("R"), 0.452); + checkResult(sect.Calc("R"), 0.452); }); // vitesse moyenne it("V should equal to 5.241", () => { - check(sect.Calc("V"), 5.241); + checkResult(sect.Calc("V"), 5.241); }); // nombre de Froude it("Fr should equal to 2.291", () => { - check(sect.Calc("Fr"), 2.291); + checkResult(sect.Calc("Fr"), 2.291); }); // tirant d'eau critique it("Yc should equal to 1.186", () => { - check(sect.Calc("Yc"), 1.186); + checkResult(sect.Calc("Yc"), 1.186); }); // tirant d'eau normal it("Yn should equal to 1.916", () => { - check(sect.Calc("Yn"), 1.916); + checkResult(sect.Calc("Yn"), 1.916); }); // tirant d'eau fluvial it("Yf should equal to 2.126", () => { - check(sect.Calc("Yf"), 2.126); + checkResult(sect.Calc("Yf"), 2.126); }); // tirant d'eau torrentiel it("Yt should equal to 0.8", () => { - check(sect.Calc("Yt"), 0.8); + checkResult(sect.Calc("Yt"), 0.8); }); // tirant d'eau conjugué it("Yco should equal to 1.746", () => { - check(sect.Calc("Yco"), 1.746); + checkResult(sect.Calc("Yco"), 1.746); }); // perte de charge it("J should equal to 0.05", () => { // sect = createSection(0.00001); - check(sect.Calc("J"), 0.05); + checkResult(sect.Calc("J"), 0.05); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to -0.049", () => { // sect = createSection(0.00001); - check(sect.Calc("I-J"), -0.049); + checkResult(sect.Calc("I-J"), -0.049); }); // impulsion hydraulique it("Imp should equal to 58397.786", () => { - check(sect.Calc("Imp"), 58397.786); + checkResult(sect.Calc("Imp"), 58397.786); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 219.455", () => { - check(sect.Calc("Tau0"), 219.455); + checkResult(sect.Calc("Tau0"), 219.455); }); }); }); diff --git a/spec/section_param/section_param_rect_conv_newton.spec.ts b/spec/section_param/section_param_rect_conv_newton.spec.ts index 5a12b6238a608c6803493d454af86b0108430d39..9a526d05c970acaa7591c70826397b2da4039a49 100644 --- a/spec/section_param/section_param_rect_conv_newton.spec.ts +++ b/spec/section_param/section_param_rect_conv_newton.spec.ts @@ -2,15 +2,10 @@ import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { MessageCode } from "../../src/util/message"; -import { equalEpsilon, precDist } from "../nubtest"; let paramSection: ParamsSectionRectang; let sect: cSnRectang; -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée rectangulaire : ", () => { beforeEach(() => { paramSection = new ParamsSectionRectang(0.8, // tirant d'eau @@ -28,71 +23,88 @@ describe("Section paramétrée rectangulaire : ", () => { describe("non convergence de la méthode de Newton :", () => { it("hauteur critique", () => { - sect.Calc("Yc"); - expect(sect.log.messages.length).toEqual(1); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + const r: Result = sect.Calc("Yc"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); }); it("hauteur normale", () => { - sect.Calc("Yn"); - expect(sect.log.messages.length).toEqual(2); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE); + const r: Result = sect.Calc("Yn"); + // expect(r.log.messages.length).toEqual(2); + expect(r.ok).toBeFalsy("le calcul devrait avoir échoué"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE); + }); + + it("hauteur normale, pente nulle", () => { + sect.prms.If.v = 0; + const r: Result = sect.Calc("Yn"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_PENTE_NEG_NULLE_HNORMALE_INF); }); it("hauteur normale, pente négative", () => { sect.prms.If.v = -0.001; - sect.Calc("Yn"); - expect(sect.log.messages.length).toEqual(1); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_PENTE_NEG_NULLE_HNORMALE_INF); + const r: Result = sect.Calc("Yn"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_PENTE_NEG_NULLE_HNORMALE_INF); }); it("hauteur fluviale, Y < Yc", () => { - sect.Calc("Yf"); - expect(sect.log.messages.length).toEqual(3); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU); + const r: Result = sect.Calc("Yf"); + // expect(r.log.messages.length).toEqual(3); + expect(r.ok).toBeFalsy("le calcul devrait avoir échoué"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU); }); it("hauteur fluviale, Y > Yc", () => { sect.prms.Y.v = 2; - sect.Calc("Yf"); - expect(sect.log.messages.length).toEqual(1); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + const r: Result = sect.Calc("Yf"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); }); it("hauteur torrentielle, Y < Yc", () => { - sect.Calc("Yt"); - expect(sect.log.messages.length).toEqual(1); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + const r: Result = sect.Calc("Yt"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); }); it("hauteur torrentielle, Y > Yc", () => { sect.prms.Y.v = 2; - sect.Calc("Yt"); - expect(sect.log.messages.length).toEqual(2); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR); + const r: Result = sect.Calc("Yt"); + // expect(r.log.messages.length).toEqual(2); + expect(r.ok).toBeFalsy("le calcul devrait avoir échoué"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR); }); it("hauteur conjuguée, Froude < 1", () => { sect.prms.Y.v = 2; - sect.Calc("Yco"); - // console.log(sect.log.toString()); - expect(sect.log.messages.length).toEqual(3); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR); - expect(sect.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); + const r: Result = sect.Calc("Yco"); + // console.log(r.log.toString()); + // expect(r.log.messages.length).toEqual(3); + expect(r.ok).toBeFalsy("le calcul devrait avoir échoué"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR); + // expect(r.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); }); it("hauteur conjuguée, Froude > 1", () => { - sect.Calc("Yco"); - expect(sect.log.messages.length).toEqual(4); - expect(sect.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); - expect(sect.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU); - expect(sect.log.messages[3].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); + const r: Result = sect.Calc("Yco"); + // expect(r.log.messages.length).toEqual(4); + expect(r.ok).toBeFalsy("le calcul devrait avoir échoué"); + expect(r.log.messages.length).toEqual(1); + expect(r.log.messages[0].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[1].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); + // expect(r.log.messages[2].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU); + // expect(r.log.messages[3].code).toEqual(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); }); }); }); diff --git a/spec/section_param/section_param_rect_fluvial.spec.ts b/spec/section_param/section_param_rect_fluvial.spec.ts index 8ae7cca92cdc0cdddd1677f45e2f79a7e001b349..d3f318e0a652179da8cd616bbe6904a7f0803e1d 100644 --- a/spec/section_param/section_param_rect_fluvial.spec.ts +++ b/spec/section_param/section_param_rect_fluvial.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionRectang; let sect: cSnRectang; @@ -31,10 +31,6 @@ function createSectionDebordement(prec: number): cSnRectang { return new cSnRectang(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée rectangulaire : ", () => { beforeEach(() => { sect = createSection(precDist); @@ -43,89 +39,89 @@ describe("Section paramétrée rectangulaire : ", () => { describe("fluvial / pas de débordement :", () => { // charge spécifique it("Hs should equal to 0.818", () => { - check(sect.Calc("Hs"), 0.818); + checkResult(sect.Calc("Hs"), 0.818); }); // charge critique it("Hsc should equal to 0.43", () => { - check(sect.Calc("Hsc"), 0.43); + checkResult(sect.Calc("Hsc"), 0.43); }); // largeur au miroir it("B should equal to 2.5", () => { - check(sect.Calc("B"), 2.5); + checkResult(sect.Calc("B"), 2.5); }); // périmètre mouillé it("P should equal to 4.1", () => { - check(sect.Calc("P"), 4.1); + checkResult(sect.Calc("P"), 4.1); }); // surface mouillée it("S should equal to 2", () => { - check(sect.Calc("S"), 2); + checkResult(sect.Calc("S"), 2); }); // rayon hydraulique it("R should equal to 0.488", () => { - check(sect.Calc("R"), 0.488); + checkResult(sect.Calc("R"), 0.488); }); // vitesse moyenne it("V should equal to 0.6", () => { - check(sect.Calc("V"), 0.6); + checkResult(sect.Calc("V"), 0.6); }); // nombre de Froude it("Fr should equal to 0.214", () => { - check(sect.Calc("Fr"), 0.214); + checkResult(sect.Calc("Fr"), 0.214); }); // tirant d'eau critique it("Yc should equal to 0.286", () => { - check(sect.Calc("Yc"), 0.286); + checkResult(sect.Calc("Yc"), 0.286); }); // tirant d'eau normal it("Yn should equal to 0.663", () => { - check(sect.Calc("Yn"), 0.663); + checkResult(sect.Calc("Yn"), 0.663); }); // tirant d'eau fluvial it("Yf should equal to 0.8", () => { - check(sect.Calc("Yf"), 0.8); + checkResult(sect.Calc("Yf"), 0.8); }); // tirant d'eau torrentiel it("Yt should equal to 0.131", () => { - check(sect.Calc("Yt"), 0.131); + checkResult(sect.Calc("Yt"), 0.131); }); // tirant d'eau conjugué it("Yco should equal to 0.068", () => { - check(sect.Calc("Yco"), 0.068); + checkResult(sect.Calc("Yco"), 0.068); }); // perte de charge it("J should equal to 0.00059", () => { sect = createSection(0.00001); - check(sect.Calc("J"), 0.00059); + checkResult(sect.Calc("J"), 0.00059); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.00041", () => { sect = createSection(0.00001); - check(sect.Calc("I-J"), 0.00041); + checkResult(sect.Calc("I-J"), 0.00041); }); // impulsion hydraulique it("Imp should equal to 8568", () => { - check(sect.Calc("Imp"), 8568); + checkResult(sect.Calc("Imp"), 8568); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 2.804", () => { - check(sect.Calc("Tau0"), 2.804); + checkResult(sect.Calc("Tau0"), 2.804); }); }); }); @@ -138,89 +134,89 @@ describe("Section paramétrée rectangulaire : ", () => { describe("fluvial / débordement :", () => { // charge spécifique it("Hs should equal to 2.003", () => { - check(sect.Calc("Hs"), 2.003); + checkResult(sect.Calc("Hs"), 2.003); }); // charge critique it("Hsc should equal to 0.43", () => { - check(sect.Calc("Hsc"), 0.43); + checkResult(sect.Calc("Hsc"), 0.43); }); // largeur au miroir it("B should equal to 2.5", () => { - check(sect.Calc("B"), 2.5); + checkResult(sect.Calc("B"), 2.5); }); // périmètre mouillé it("P should equal to 6.5", () => { - check(sect.Calc("P"), 6.5); + checkResult(sect.Calc("P"), 6.5); }); // surface mouillée it("S should equal to 5", () => { - check(sect.Calc("S"), 5); + checkResult(sect.Calc("S"), 5); }); // rayon hydraulique it("R should equal to 0.769", () => { - check(sect.Calc("R"), 0.769); + checkResult(sect.Calc("R"), 0.769); }); // vitesse moyenne it("V should equal to 0.24", () => { - check(sect.Calc("V"), 0.24); + checkResult(sect.Calc("V"), 0.24); }); // nombre de Froude it("Fr should equal to 0.0542", () => { - check(sect.Calc("Fr"), 0.0542); + checkResult(sect.Calc("Fr"), 0.0542); }); // tirant d'eau critique it("Yc should equal to 0.286", () => { - check(sect.Calc("Yc"), 0.286); + checkResult(sect.Calc("Yc"), 0.286); }); // tirant d'eau normal it("Yn should equal to 0.663", () => { - check(sect.Calc("Yn"), 0.663); + checkResult(sect.Calc("Yn"), 0.663); }); // tirant d'eau fluvial it("Yf should equal to 2", () => { - check(sect.Calc("Yf"), 2); + checkResult(sect.Calc("Yf"), 2); }); // tirant d'eau torrentiel it("Yt should equal to 0.078", () => { - check(sect.Calc("Yt"), 0.078); + checkResult(sect.Calc("Yt"), 0.078); }); // tirant d'eau conjugué it("Yco should equal to 0.012", () => { - check(sect.Calc("Yco"), 0.012); + checkResult(sect.Calc("Yco"), 0.012); }); // perte de charge it("J should equal to 0.00059", () => { sect = createSection(0.00001); - check(sect.Calc("J"), 0.00059); + checkResult(sect.Calc("J"), 0.00059); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.0009", () => { sect = createSection(0.00001); - check(sect.Calc("I-J"), 0.0009); + checkResult(sect.Calc("I-J"), 0.0009); }); // impulsion hydraulique it("Imp should equal to 49338", () => { - check(sect.Calc("Imp"), 49338); + checkResult(sect.Calc("Imp"), 49338); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 0.385", () => { - check(sect.Calc("Tau0"), 0.385); + checkResult(sect.Calc("Tau0"), 0.385); }); }); }); diff --git a/spec/section_param/section_param_rect_torrentiel.spec.ts b/spec/section_param/section_param_rect_torrentiel.spec.ts index a5e7e374339f26e939bc788b1869d76dcbe974f1..caed1035417dbf3eb2c8e1f275db407fc32a936b 100644 --- a/spec/section_param/section_param_rect_torrentiel.spec.ts +++ b/spec/section_param/section_param_rect_torrentiel.spec.ts @@ -1,14 +1,10 @@ -import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionRectang; let sect: cSnRectang; -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée rectangulaire : ", () => { beforeEach(() => { paramSection = new ParamsSectionRectang(0.8, // tirant d'eau @@ -26,89 +22,89 @@ describe("Section paramétrée rectangulaire : ", () => { describe("torrentiel :", () => { // charge spécifique it("Hs should equal to 2.074", () => { - check(sect.Calc("Hs"), 2.074); + checkResult(sect.Calc("Hs"), 2.074); }); // charge critique it("Hsc should equal to 1.766", () => { - check(sect.Calc("Hsc"), 1.766); + checkResult(sect.Calc("Hsc"), 1.766); }); // largeur au miroir it("B should equal to 2.5", () => { - check(sect.Calc("B"), 2.5); + checkResult(sect.Calc("B"), 2.5); }); // périmètre mouillé it("P should equal to 4.1", () => { - check(sect.Calc("P"), 4.1); + checkResult(sect.Calc("P"), 4.1); }); // surface mouillée it("S should equal to 2", () => { - check(sect.Calc("S"), 2); + checkResult(sect.Calc("S"), 2); }); // rayon hydraulique it("R should equal to 0.488", () => { - check(sect.Calc("R"), 0.488); + checkResult(sect.Calc("R"), 0.488); }); // vitesse moyenne it("V should equal to 5", () => { - check(sect.Calc("V"), 5); + checkResult(sect.Calc("V"), 5); }); // nombre de Froude it("Fr should equal to 1.785", () => { - check(sect.Calc("Fr"), 1.785); + checkResult(sect.Calc("Fr"), 1.785); }); // tirant d'eau critique it("Yc should equal to 1.177", () => { - check(sect.Calc("Yc"), 1.177); + checkResult(sect.Calc("Yc"), 1.177); }); // tirant d'eau normal it("Yn should equal to 3.364", () => { - check(sect.Calc("Yn"), 3.364); + checkResult(sect.Calc("Yn"), 3.364); }); // tirant d'eau fluvial it("Yf should equal to 1.831", () => { - check(sect.Calc("Yf"), 1.831); + checkResult(sect.Calc("Yf"), 1.831); }); // tirant d'eau torrentiel it("Yt should equal to 0.8", () => { - check(sect.Calc("Yt"), 0.8); + checkResult(sect.Calc("Yt"), 0.8); }); // tirant d'eau conjugué it("Yco should equal to 1.659", () => { - check(sect.Calc("Yco"), 1.659); + checkResult(sect.Calc("Yco"), 1.659); }); // perte de charge it("J should equal to 0.041", () => { // paramCnl.v.Prec = 0.00001; - check(sect.Calc("J"), 0.041); + checkResult(sect.Calc("J"), 0.041); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to -0.04", () => { // paramCnl.v.Prec = 0.00001; - check(sect.Calc("I-J"), -0.04); + checkResult(sect.Calc("I-J"), -0.04); }); // impulsion hydraulique it("Imp should equal to 57848", () => { - check(sect.Calc("Imp"), 57848); + checkResult(sect.Calc("Imp"), 57848); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 194.718", () => { - check(sect.Calc("Tau0"), 194.718); + checkResult(sect.Calc("Tau0"), 194.718); }); }); }); diff --git a/spec/section_param/section_param_trapez_fluvial.spec.ts b/spec/section_param/section_param_trapez_fluvial.spec.ts index f2095057df8ce5a062b30602b27789004ce266a0..6d3a35f72b6a155ce0c852abd930d07923b5861b 100644 --- a/spec/section_param/section_param_trapez_fluvial.spec.ts +++ b/spec/section_param/section_param_trapez_fluvial.spec.ts @@ -1,6 +1,6 @@ -import { Result } from "../../src/util/result"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramSection: ParamsSectionTrapez; let sect: cSnTrapez; @@ -33,10 +33,6 @@ function createSectionDebordement(prec: number): cSnTrapez { return new cSnTrapez(paramSection); } -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée trapèze : ", () => { beforeEach(() => { sect = createSection(precDist); @@ -45,88 +41,88 @@ describe("Section paramétrée trapèze : ", () => { describe("fluvial / pas de débordement :", () => { // charge spécifique it("Hs should equal to 0.813", () => { - check(sect.Calc("Hs"), 0.813); + checkResult(sect.Calc("Hs"), 0.813); }); // charge critique it("Hsc should equal to 0.413", () => { - check(sect.Calc("Hsc"), 0.413); + checkResult(sect.Calc("Hsc"), 0.413); }); // largeur au miroir it("B should equal to 3.396", () => { - check(sect.Calc("B"), 3.396); + checkResult(sect.Calc("B"), 3.396); }); // périmètre mouillé it("P should equal to 4.334", () => { - check(sect.Calc("P"), 4.334); + checkResult(sect.Calc("P"), 4.334); }); // surface mouillée it("S should equal to 2.358", () => { - check(sect.Calc("S"), 2.358); + checkResult(sect.Calc("S"), 2.358); }); // rayon hydraulique it("R should equal to 0.544", () => { - check(sect.Calc("R"), 0.544); + checkResult(sect.Calc("R"), 0.544); }); // vitesse moyenne it("V should equal to 0.509", () => { - check(sect.Calc("V"), 0.509); + checkResult(sect.Calc("V"), 0.509); }); // nombre de Froude it("Fr should equal to 0.195", () => { - check(sect.Calc("Fr"), 0.195); + checkResult(sect.Calc("Fr"), 0.195); }); // tirant d'eau critique it("Yc should equal to 0.28", () => { - check(sect.Calc("Yc"), 0.28); + checkResult(sect.Calc("Yc"), 0.28); }); // tirant d'eau normal it("Yn should equal to 0.587", () => { - check(sect.Calc("Yn"), 0.587); + checkResult(sect.Calc("Yn"), 0.587); }); // tirant d'eau fluvial it("Yf should equal to 0.8", () => { - check(sect.Calc("Yf"), 0.8); + checkResult(sect.Calc("Yf"), 0.8); }); // tirant d'eau torrentiel it("Yt should equal to 0.127", () => { - check(sect.Calc("Yt"), 0.127); + checkResult(sect.Calc("Yt"), 0.127); }); // tirant d'eau conjugué it("Yco should equal to 0.061", () => { - check(sect.Calc("Yco"), 0.061); + checkResult(sect.Calc("Yco"), 0.061); }); // perte de charge it("J should equal to 0.00036", () => { let sect = createSection(0.00001); - check(sect.Calc("J"), 0.00036); + checkResult(sect.Calc("J"), 0.00036); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.001", () => { - check(sect.Calc("I-J"), 0.001); + checkResult(sect.Calc("I-J"), 0.001); }); // impulsion hydraulique it("Imp should equal to 9396.158", () => { - check(sect.Calc("Imp"), 9396.158); + checkResult(sect.Calc("Imp"), 9396.158); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 1.944", () => { - check(sect.Calc("Tau0"), 1.944); + checkResult(sect.Calc("Tau0"), 1.944); }); }); }); @@ -140,88 +136,88 @@ describe("Section paramétrée trapèze : ", () => { describe("fluvial / débordement :", () => { // charge spécifique it("Hs should equal to 2.002", () => { - check(sect.Calc("Hs"), 2.002); + checkResult(sect.Calc("Hs"), 2.002); }); // charge critique it("Hsc should equal to 0.413", () => { - check(sect.Calc("Hsc"), 0.413); + checkResult(sect.Calc("Hsc"), 0.413); }); // largeur au miroir it("B should equal to 3.62", () => { - check(sect.Calc("B"), 3.62); + checkResult(sect.Calc("B"), 3.62); }); // périmètre mouillé it("P should equal to 6.792", () => { - check(sect.Calc("P"), 6.792); + checkResult(sect.Calc("P"), 6.792); }); // surface mouillée it("S should equal to 6.68", () => { - check(sect.Calc("S"), 6.68); + checkResult(sect.Calc("S"), 6.68); }); // rayon hydraulique it("R should equal to 0.983", () => { - check(sect.Calc("R"), 0.983); + checkResult(sect.Calc("R"), 0.983); }); // vitesse moyenne it("V should equal to 0.18", () => { - check(sect.Calc("V"), 0.18); + checkResult(sect.Calc("V"), 0.18); }); // nombre de Froude it("Fr should equal to 0.042", () => { - check(sect.Calc("Fr"), 0.042); + checkResult(sect.Calc("Fr"), 0.042); }); // tirant d'eau critique it("Yc should equal to 0.28", () => { - check(sect.Calc("Yc"), 0.28); + checkResult(sect.Calc("Yc"), 0.28); }); // tirant d'eau normal it("Yn should equal to 0.587", () => { - check(sect.Calc("Yn"), 0.587); + checkResult(sect.Calc("Yn"), 0.587); }); // tirant d'eau fluvial it("Yf should equal to 2", () => { - check(sect.Calc("Yf"), 2); + checkResult(sect.Calc("Yf"), 2); }); // tirant d'eau torrentiel it("Yt should equal to 0.077", () => { - check(sect.Calc("Yt"), 0.077); + checkResult(sect.Calc("Yt"), 0.077); }); // tirant d'eau conjugué it("Yco should equal to 0.009", () => { - check(sect.Calc("Yco"), 0.009); + checkResult(sect.Calc("Yco"), 0.009); }); // perte de charge it("J should equal to 0.00002", () => { let sect = createSection(0.00001); - check(sect.Calc("J"), 0.00002); + checkResult(sect.Calc("J"), 0.00002); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to 0.001", () => { - check(sect.Calc("I-J"), 0.001); + checkResult(sect.Calc("I-J"), 0.001); }); // impulsion hydraulique it("Imp should equal to 63915.169", () => { - check(sect.Calc("Imp"), 63915.169); + checkResult(sect.Calc("Imp"), 63915.169); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 0.199", () => { - check(sect.Calc("Tau0"), 0.199); + checkResult(sect.Calc("Tau0"), 0.199); }); }); }); diff --git a/spec/section_param/section_param_trapez_torrentiel.spec.ts b/spec/section_param/section_param_trapez_torrentiel.spec.ts index 2b03327234fb8c9ba651cca021b7a495d069494f..a0e8c4ceba5f7608ee3128d36019c5114ebddc44 100644 --- a/spec/section_param/section_param_trapez_torrentiel.spec.ts +++ b/spec/section_param/section_param_trapez_torrentiel.spec.ts @@ -1,14 +1,10 @@ -import { Result } from "../../src/util/result"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; -import { equalEpsilon, precDist } from "../nubtest"; +import { precDist } from "../test_config"; +import { checkResult } from "../test_func"; let paramCnl: ParamsSectionTrapez; let sect: cSnTrapez; -function check(val1: number, val2: number) { - expect(equalEpsilon(val1, val2)).toBeTruthy("expected " + val2 + ", got " + val1); -} - describe("Section paramétrée trapèze :", () => { beforeEach(() => { paramCnl = new ParamsSectionTrapez(2.5, // largeur de fond @@ -27,88 +23,88 @@ describe("Section paramétrée trapèze :", () => { describe("torrentiel :", () => { // charge spécifique it("Hs should equal to 1.716", () => { - check(sect.Calc("Hs"), 1.716); + checkResult(sect.Calc("Hs"), 1.716); }); // charge critique it("Hsc should equal to 1.534", () => { - check(sect.Calc("Hsc"), 1.534); + checkResult(sect.Calc("Hsc"), 1.534); }); // largeur au miroir it("B should equal to 3.396", () => { - check(sect.Calc("B"), 3.396); + checkResult(sect.Calc("B"), 3.396); }); // périmètre mouillé it("P should equal to 4.334", () => { - check(sect.Calc("P"), 4.334); + checkResult(sect.Calc("P"), 4.334); }); // surface mouillée it("S should equal to 2.358", () => { - check(sect.Calc("S"), 2.358); + checkResult(sect.Calc("S"), 2.358); }); // rayon hydraulique it("R should equal to 0.544", () => { - check(sect.Calc("R"), 0.544); + checkResult(sect.Calc("R"), 0.544); }); // vitesse moyenne it("V should equal to 4.24", () => { - check(sect.Calc("V"), 4.24); + checkResult(sect.Calc("V"), 4.24); }); // nombre de Froude it("Fr should equal to 1.625", () => { - check(sect.Calc("Fr"), 1.625); + checkResult(sect.Calc("Fr"), 1.625); }); // tirant d'eau critique it("Yc should equal to 1.074", () => { - check(sect.Calc("Yc"), 1.074); + checkResult(sect.Calc("Yc"), 1.074); }); // tirant d'eau normal it("Yn should equal to 2.275", () => { - check(sect.Calc("Yn"), 2.275); + checkResult(sect.Calc("Yn"), 2.275); }); // tirant d'eau fluvial it("Yf should equal to 1.502", () => { - check(sect.Calc("Yf"), 1.502); + checkResult(sect.Calc("Yf"), 1.502); }); // tirant d'eau torrentiel it("Yt should equal to 0.8", () => { - check(sect.Calc("Yt"), 0.8); + checkResult(sect.Calc("Yt"), 0.8); }); // tirant d'eau conjugué it("Yco should equal to 1.398", () => { - check(sect.Calc("Yco"), 1.398); + checkResult(sect.Calc("Yco"), 1.398); }); // perte de charge it("J should equal to 0.025", () => { // paramCnl.v.Prec = 0.00001; - check(sect.Calc("J"), 0.025); + checkResult(sect.Calc("J"), 0.025); }); // Variation linéaire de l'énergie spécifique it("I-J should equal to -0.024", () => { - check(sect.Calc("I-J"), -0.024); + checkResult(sect.Calc("I-J"), -0.024); }); // impulsion hydraulique it("Imp should equal to 51187.203", () => { - check(sect.Calc("Imp"), 51187.203); + checkResult(sect.Calc("Imp"), 51187.203); }); // force tractrice (contrainte de cisaillement) it("Tau0 should equal to 135.020", () => { - check(sect.Calc("Tau0"), 135.020); + checkResult(sect.Calc("Tau0"), 135.020); }); }); }); diff --git a/spec/structure/rectangular_structure.ts b/spec/structure/rectangular_structure.ts index deee528562ccb15569b504fa57592847b9813da4..e960a7135be139759e2677ced7a28866cb055f16 100644 --- a/spec/structure/rectangular_structure.ts +++ b/spec/structure/rectangular_structure.ts @@ -4,7 +4,7 @@ import { Result } from "../../src/util/result"; import { RectangularStructure } from "../../src/structure/rectangular_structure"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; -import { precDigits } from "../nubtest"; +import { precDigits } from "../test_config"; /** * Récupération du nom de la classe diff --git a/spec/structure/structure.spec.ts b/spec/structure/structure.spec.ts index 575f95863f8dafa798a91e82e49b7463bf9a9c16..1c764d056c924e95878ba26b401b06fb0f8b9e63 100644 --- a/spec/structure/structure.spec.ts +++ b/spec/structure/structure.spec.ts @@ -3,11 +3,7 @@ import { Result } from "../../src/util/result"; import { Structure, StructureFlowMode, StructureFlowRegime, StructureParams } from "../../src/structure/structure"; -import { equalEpsilon } from "../nubtest"; - -function check(val1: Result, val2: number) { - expect(equalEpsilon(val1.vCalc, val2)).toBe(true); -} +import { checkResult } from "../test_func"; class StructureTest extends Structure { @@ -82,28 +78,28 @@ describe("Class Structure: ", () => { }); describe("Calc()", () => { - const flagsNull = {Mode: StructureFlowMode.NULL, Regime: StructureFlowRegime.NULL}; + const flagsNull = { Mode: StructureFlowMode.NULL, Regime: StructureFlowRegime.NULL }; it("h1=h2 => Q=0", () => { structTest.prms.h2.v = structTest.prms.h1.v; - check(structTest.Calc("Q"), 0); + checkResult(structTest.Calc("Q"), 0); expect(structTest.Calc("Q").extraVar).toEqual(flagsNull); structTest.prms.h2.v = 15; }); it("W=0 => Q=0", () => { structTest.prms.W.v = 0; - check(structTest.Calc("Q"), 0); + checkResult(structTest.Calc("Q"), 0); expect(structTest.Calc("Q").extraVar).toEqual(flagsNull); structTest.prms.W.v = Infinity; }); it("Q=0 => h1=h2", () => { structTest.prms.Q.v = 0; - check(structTest.Calc("h1"), structTest.prms.h2.v); + checkResult(structTest.Calc("h1"), structTest.prms.h2.v); expect(structTest.Calc("h1").extraVar).toEqual(flagsNull); structTest.prms.Q.v = 1; }); it("Q=0 => W=0", () => { structTest.prms.Q.v = 0; - check(structTest.Calc("W"), 0); + checkResult(structTest.Calc("W"), 0); expect(structTest.Calc("W").extraVar).toEqual(flagsNull); structTest.prms.Q.v = 1; }); diff --git a/spec/structure/structure_cem88d.spec.ts b/spec/structure/structure_cem88d.spec.ts index bae6c610ac9b8b9234bab8f31a0f8b22f61e1229..779ee7423d1ff6d3781bd4c14bfde3f70556f469 100644 --- a/spec/structure/structure_cem88d.spec.ts +++ b/spec/structure/structure_cem88d.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCem88d } from "../../src/structure/structure_cem88d"; @@ -19,7 +18,7 @@ describe("Class StructureCem88d: ", () => { const Q: number[] = [0.000000, 0.617586, 1.235173, 1.852759, 2.470345, 3.087931, 3.705518, 4.296608, 4.831177, 5.302464, 5.700445, 6.007777, 6.175863, 6.175863]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -32,7 +31,7 @@ describe("Class StructureCem88d: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.PARTIAL, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -45,7 +44,7 @@ describe("Class StructureCem88d: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/structure_cem88v.spec.ts b/spec/structure/structure_cem88v.spec.ts index 0ab80754a6f4085eea91813080934d6b857665ee..e7b440612f8ebfc0464817761bd8fbbe0a7ac042 100644 --- a/spec/structure/structure_cem88v.spec.ts +++ b/spec/structure/structure_cem88v.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCem88v } from "../../src/structure/structure_cem88v"; @@ -18,7 +17,7 @@ describe("Class StructureCem88v: ", () => { const Q: number[] = [.000000, 0.328260, 0.641822, 0.823867, 1.117381, 1.720738, 2.225472, 2.575336, 2.873893, 3.113250, 3.280545, 3.349403, 3.149324, 3.149324]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -31,7 +30,7 @@ describe("Class StructureCem88v: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.PARTIAL, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -44,7 +43,7 @@ describe("Class StructureCem88v: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/structure_cunge80.spec.ts b/spec/structure/structure_cunge80.spec.ts index 8e4bc0324455f3819d7c5a2676b1d86e945705a2..31fd7bb11e06a8c2fedadc99586edea3052bd6f0 100644 --- a/spec/structure/structure_cunge80.spec.ts +++ b/spec/structure/structure_cunge80.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCunge80 } from "../../src/structure/structure_cunge80"; @@ -19,7 +18,7 @@ describe("Class StructureCunge80: ", () => { const Q: number[] = [0.000000, 0.237709, 0.475418, 0.713127, 0.950836, 1.188545, 1.426254, 1.663963, 1.901673, 2.139382, 2.377091, 2.377091, 2.377091, 2.377091]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -32,7 +31,7 @@ describe("Class StructureCunge80: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -45,7 +44,7 @@ describe("Class StructureCunge80: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/structure_orifice_free.spec.ts b/spec/structure/structure_orifice_free.spec.ts index 44e1a7c3cefdb0aae57af592417e42a2d3e348a8..04323a813216e56b81fd778c45772ff35cf82cdc 100644 --- a/spec/structure/structure_orifice_free.spec.ts +++ b/spec/structure/structure_orifice_free.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureOrificeFree } from "../../src/structure/structure_orifice_free"; @@ -19,7 +18,7 @@ describe("Class StructureOrificeFree: ", () => { const Q: number[] = [0.000000, 0.582266, 1.164532, 1.746798, 2.329064, 2.911330, 3.493596, 4.075861, 4.658127, 5.240393, 5.822659, 6.404925, 6.987191, 6.987191]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -32,7 +31,7 @@ describe("Class StructureOrificeFree: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.FREE, StructureFlowRegime.FREE, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -45,7 +44,7 @@ describe("Class StructureOrificeFree: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.FREE, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/structure_orifice_submerged.spec.ts b/spec/structure/structure_orifice_submerged.spec.ts index bf4cd9e8a5e710e013fc69cf1356701eac7b4107..3f18b07f1f1dbedb6c8886f32c97771719e8fc68 100644 --- a/spec/structure/structure_orifice_submerged.spec.ts +++ b/spec/structure/structure_orifice_submerged.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureOrificeSubmerged } from "../../src/structure/structure_orifice_submerged"; @@ -19,7 +18,7 @@ describe("Class StructureOrificeSubmerged: ", () => { const Q: number[] = [0.000000, 0.237709, 0.475418, 0.713127, 0.950836, 1.188545, 1.426254, 1.663963, 1.901673, 2.139382, 2.377091, 2.614800, 2.852509, 2.852509]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -32,7 +31,7 @@ describe("Class StructureOrificeSubmerged: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -45,7 +44,7 @@ describe("Class StructureOrificeSubmerged: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/structure_weir_free.spec.ts b/spec/structure/structure_weir_free.spec.ts index 1aa66d3a3dd4a6fc2efc17c93c2281d2474ae889..49bd92967d325fc580dc1bfb31c668f85f915a12 100644 --- a/spec/structure/structure_weir_free.spec.ts +++ b/spec/structure/structure_weir_free.spec.ts @@ -1,7 +1,6 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureWeirFree } from "../../src/structure/structure_weir_free"; @@ -19,7 +18,7 @@ describe("Class StructureWeirFree: ", () => { const Q: number[] = [0.000000, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191, 6.987191]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -32,7 +31,7 @@ describe("Class StructureWeirFree: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.FREE, StructureFlowRegime.FREE, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -45,7 +44,7 @@ describe("Class StructureWeirFree: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.FREE, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/structure/test_rectangular_structure.ts b/spec/structure/test_rectangular_structure.ts index 118442634104b6ebc154721d692be1205d3b56fd..77742fc64b5ccfcaac670eea6fa0e05b0a79e066 100644 --- a/spec/structure/test_rectangular_structure.ts +++ b/spec/structure/test_rectangular_structure.ts @@ -2,7 +2,7 @@ import { Result } from "../../src/util/result"; import { RectangularStructure } from "../../src/structure/rectangular_structure"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { expect, it } from "../mock_jasmine"; -import { precDigits } from "../nubtest"; +import { precDigits } from "../test_config"; import { Describer } from "./rectangular_structure"; export function itCalcQ( diff --git a/spec/structure/test_structure_cem88d.ts b/spec/structure/test_structure_cem88d.ts index 0e00540709e76a6062e40cf4f27fdb8d2b78439c..75b888335df45667732855186d49601563540f34 100644 --- a/spec/structure/test_structure_cem88d.ts +++ b/spec/structure/test_structure_cem88d.ts @@ -1,7 +1,5 @@ -import { Result } from "../../src/util/result"; import { RectangularStructureParams, StructureCem88d } from "../../src/structure/structure_cem88d"; import { describe, xdescribe } from "../mock_jasmine"; -import { precDigits } from "../nubtest"; import { itCalcQ } from "./test_rectangular_structure"; const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0); @@ -16,7 +14,7 @@ describe("Class StructureCem88d: ", () => { const Q: number[] = [0.000000, 0.617586, 1.235173, 1.852759, 2.470345, 3.087931, 3.705518, 4.296608, 4.831177, 5.302464, 5.700445, 6.007777, 6.175863, 6.175863]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -25,7 +23,7 @@ describe("Class StructureCem88d: ", () => { const h1: number[] = [1.050000, 1.300000, 1.500000]; const Q: number[] = [2.470345, 5.684601, 6.651906]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i]); } }); @@ -34,7 +32,7 @@ describe("Class StructureCem88d: ", () => { const h1: number[] = [1.100000, 1.500000]; const Q: number[] = [4.366994, 9.764896]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i]); } }); diff --git a/spec/structure/test_structure_cem88v.ts b/spec/structure/test_structure_cem88v.ts index c1be649b6d7927e23fca0d4cec6d1b0cfab11728..a996471ce38b2c620cd2e4a65962028a520478ef 100644 --- a/spec/structure/test_structure_cem88v.ts +++ b/spec/structure/test_structure_cem88v.ts @@ -1,7 +1,5 @@ -import { Result } from "../../src/util/result"; import { RectangularStructureParams, StructureCem88v } from "../../src/structure/structure_cem88v"; import { describe, xdescribe } from "../mock_jasmine"; -import { precDigits } from "../nubtest"; import { itCalcQ } from "./test_rectangular_structure"; const structPrm: RectangularStructureParams = new RectangularStructureParams(1, 1, 1, 2, 0.6, 0); @@ -15,7 +13,7 @@ describe("Class StructureCem88v: ", () => { const Q: number[] = [.000000, 0.328260, 0.641822, 0.823867, 1.117381, 1.720738, 2.225472, 2.575336, 2.873893, 3.113250, 3.280545, 3.349403, 3.149324, 3.149324]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -24,7 +22,7 @@ describe("Class StructureCem88v: ", () => { const h1: number[] = [1.05, 1.3, 1.5]; const Q: number[] = [1.365897, 3.623277, 4.214572]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i]); } }); @@ -33,7 +31,7 @@ describe("Class StructureCem88v: ", () => { const h1: number[] = [1.100000, 1.500000]; const Q: number[] = [2.086781, 5.207945]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i]); } }); diff --git a/spec/structure/test_structure_cunge80.ts b/spec/structure/test_structure_cunge80.ts index 60d794187f28671e8c6135946d09b535338a6584..7969dc9d92212d1e20e702445b972cdf8e85b096 100644 --- a/spec/structure/test_structure_cunge80.ts +++ b/spec/structure/test_structure_cunge80.ts @@ -1,4 +1,3 @@ -import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCunge80 } from "../../src/structure/structure_cunge80"; @@ -17,7 +16,7 @@ describe("Class StructureCunge80: ", () => { const Q: number[] = [0.000000, 0.237709, 0.475418, 0.713127, 0.950836, 1.188545, 1.426254, 1.663963, 1.901673, 2.139382, 2.377091, 2.377091, 2.377091, 2.377091]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1, W[i], Q[i]); } }); @@ -30,7 +29,7 @@ describe("Class StructureCunge80: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); @@ -43,7 +42,7 @@ describe("Class StructureCunge80: ", () => { const regime: StructureFlowRegime[] = [ StructureFlowRegime.SUBMERGED, StructureFlowRegime.FREE]; - for (let i = 0; i < Q.length; i++ ) { + for (let i = 0; i < Q.length; i++) { itCalcQ(structTest, h1[i], W, Q[i], mode[i], regime[i]); } }); diff --git a/spec/test_config.ts b/spec/test_config.ts new file mode 100644 index 0000000000000000000000000000000000000000..51ce698d48f90c4654848d5ad8cf2c12e5ff7d16 --- /dev/null +++ b/spec/test_config.ts @@ -0,0 +1,9 @@ +/** + * précision de calcul (nombre de décimales) + */ +export let precDigits = 3; + +/** + * précision de calcul (max de abs(v-v')) + */ +export let precDist: number = Math.pow(10, -precDigits); diff --git a/spec/test_func.ts b/spec/test_func.ts new file mode 100644 index 0000000000000000000000000000000000000000..1cf84cdd4627d8f03e5c4ba494515ead74e0c05b --- /dev/null +++ b/spec/test_func.ts @@ -0,0 +1,203 @@ +/** + * IMPORTANT ! + * décommenter la ligne suivante (import { expect } from "./mock_jasmine") dans le cas d'une fonction + * qui utilise la fonction expect() de Jasmine mais qui doit être exécutée en dehors de tests Jasmine + */ +//import { expect } from "./mock_jasmine" + +import { cLog } from "../src/util/log"; +import { Message, MessageCode } from "../src/util/message"; +import { precDist } from "./test_config"; +import { Result } from "../src/util/result"; +import { precDigits } from "./test_config" + +/** + * Compare deux valeurs réelles à un epsilon près + * @param val1 Première valeur à comparer + * @param val2 Deuxième valeur à comparer + * @param epsilon Erreur de comparaison acceptable + * @return Vrai si les valeurs sont égales, faux sinon + */ +export function equalEpsilon(val1: number, val2: number, epsilon: number = precDist) { + return Math.abs(val1 - val2) < epsilon; +} + +/** + * compare 2 objets + * @param s message + * @param objTest objet à tester + * @param objValid objet de référence + * @param epsilon tolérance pour les comparaisons de nombres + */ +export function compareObject( + s: string, + objTest: { [key: number]: number }, + objValid: { [key: number]: number }, + epsilon: number, +) { + const n1 = Object.keys(objTest).length; + const n2 = Object.keys(objValid).length; + let b: boolean = n1 === n2; + expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); + if (!b) { return; } + + for (let i = 0; i < n1; i++) { + const v1: number = objTest[+Object.keys(objTest)[i]]; + const v2: number = objValid[+Object.keys(objValid)[i]]; + b = equalEpsilon(v1, v2, epsilon); + expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); + if (!b) { return; } + } +} + +/** + * compare 2 tableaux + * @param s message + * @param arrTest tableau à tester + * @param arrValid tableau de référence + * @return false en cas d'échec + */ +export function compareArray(s: string, arrTest: number[], arrValid: number[]): boolean { + const n1 = arrTest.length; + const n2 = arrValid.length; + let b: boolean = n1 === n2; + expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); + if (!b) { return false; } + + for (let i = 0; i < arrTest.length; i++) { + const v1: number = arrTest[i]; + const v2: number = arrValid[i]; + b = equalEpsilon(v1, v2); + expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); + if (!b) { return false; } + } + + return true; +} +// export function compareArray2(s: string, arrTest: string[], arrValid: string[]): boolean { +// const n1 = arrTest.length; +// const n2 = arrValid.length; +// let b: boolean = n1 === n2; +// expect(b).toBeTruthy(s + ": longueur incorrecte " + n1 + ", devrait etre " + n2); +// if (!b) { return false; } + +// for (let i = 0; i < arrTest.length; i++) { +// const v1: number = +arrTest[i]; +// const v2: number = +arrValid[i]; +// b = equalEpsilon(v1, v2); +// expect(b).toBeTruthy(s + " : " + i + "ieme valeur incorrecte " + v1 + ", devrait etre " + v2); +// if (!b) { return false; } +// } + +// return true; +// } + +/** + * compare 2 journaux + */ +export function compareLog(logTest: cLog, logValid: cLog) { + // console.log(JSON.stringify(logTest)); + // console.log("journal :\n" + logTest.toString()); + + // taille + + const n1 = logTest.messages.length; + const n2 = logValid.messages.length; + let b: boolean = n1 === n2; + expect(b).toBeTruthy("journal : nombre de messages incorrect (" + n1 + "), devrait etre " + n2); + if (!b) { return; } + + // codes + + for (let i = 0; i < n1; i++) { + const m1: Message = logTest.messages[i]; + const m2: Message = logValid.messages[i]; + b = m1.code === m2.code; + expect(b).toBeTruthy( + "journal : message n°" + i + ", code " + MessageCode[m1.code] + + " incorrect, devrait être " + MessageCode[m2.code], + ); + if (!b) { return; } + } + + // données + + for (let i = 0; i < n1; i++) { + const m1: Message = logTest.messages[i]; + const m2: Message = logValid.messages[i]; + const code1 = MessageCode[m1.code]; + + // taille des données + + const nd1 = Object.keys(m1.extraVar).length; + const nd2 = Object.keys(m2.extraVar).length; + b = nd1 === nd2; + expect(b).toBeTruthy( + "journal : message n°" + i + ", code " + code1 + " : nombre de données incorrect " + + nd1 + ", devrait etre " + nd2, + ); + if (!b) { return; } + + // clés des données + + for (const j in m1.extraVar) { + b = m2.extraVar[j] !== undefined; + expect(b).toBeTruthy( + "journal : message n°" + i + ", code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] + + " ne devrait pas être présente"); + // if (!b) return; + } + + for (const j in m2.extraVar) { + b = m1.extraVar[j] !== undefined; + expect(b).toBeTruthy( + "journal : message n°" + i + ", code " + code1 + " : la donnée " + j + "=" + m2.extraVar[j] + + " devrait être présente"); + // if (!b) return; + } + + // type des données + + for (const j in m1.extraVar) { + b = typeof m1.extraVar[j] === typeof m2.extraVar[j]; + expect(b).toBeTruthy( + "journal : " + i + "ieme message, code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] + + " a un type " + (typeof m1.extraVar[j]) + " incorrect, devrait être du type " + + (typeof m2.extraVar[j])); + if (!b) { return; } + } + + // valeur des données + + for (const j in m1.extraVar) { + const d: any = m1.extraVar[j]; + if (typeof d === "number") { + b = equalEpsilon(d, m2.extraVar[j]); + } else { + b = d === m2.extraVar[j]; + } + expect(b).toBeTruthy( + "journal : " + i + "ieme message, code " + code1 + " : la donnée " + j + "=" + m1.extraVar[j] + + " a une valeur incorrecte, devrait être " + m2.extraVar[j]); + if (!b) { return; } + } + } +} + +export function checkResult(val1: Result, val2: number, prec: number = undefined) { + expect(val1.ok).toBeTruthy("Result : computation error on Result " + val1.toString()); + if (val1.ok) { + /* + * on demande une précision de vérification inférieure à la précision de calcul + * pour ne pas échouer sur un arrondi sur le dernier chiffre + * par ex : + * précision demandée 0.001 + * valeur attendue 1.301 + * valeur calculée 1.3016, arrondie à 1.302, faisant échouer le test + */ + if (prec == undefined) + prec = Math.max(0, precDigits - 1); + + expect(val1.vCalc).toBeCloseTo(val2, prec); + } +} diff --git a/spec/tsconfig.spec.json b/spec/tsconfig.spec.json index 86e4fca2e4fc36961b7a48563ddcb38ce153c982..4ad9f932db919296038ef06a0f8dee00c062686d 100644 --- a/spec/tsconfig.spec.json +++ b/spec/tsconfig.spec.json @@ -5,6 +5,8 @@ "../spec/**/*.ts" ], "exclude": [ - "../spec/test-remous-fenetre.ts" + "../spec/test-remous-fenetre.ts", + "../spec/test.ts", + "../spec/test_func.ts" ] } diff --git a/src/cond_distri.ts b/src/cond_distri.ts index 6ab4a1f2e70c35754daa5d98aff9f45f907ed0e6..e4ebdbfef33486495a1a2010d0dce0147e3b930f 100644 --- a/src/cond_distri.ts +++ b/src/cond_distri.ts @@ -69,7 +69,6 @@ export class ConduiteDistrib extends Nub { * @return valeur calculée */ Equation(sVarCalc: string): Result { - let res: Result; let v: number; let K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule diff --git a/src/pab/pab_dimension.ts b/src/pab/pab_dimension.ts index d95c0e45e08bdea1f01db1b4bdd1a143827202bd..5c84d9fea338d98e12d7a6d180efa30d64ce7800 100644 --- a/src/pab/pab_dimension.ts +++ b/src/pab/pab_dimension.ts @@ -1,6 +1,6 @@ import { Result } from "../util/result"; import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, ParamsEquation } from "../param"; -import { NumericalString } from "../index"; +import { NumericalString } from "../util/numericalstring"; import { Nub } from "../nub"; export class PabDimensionParams extends ParamsEquation { diff --git a/src/pab/pab_puissance.ts b/src/pab/pab_puissance.ts index 4ee44dade1fefea24c8177bcdc69445ca050c996..df65b5086619ca734b95f790505ccbe2468dc19e 100644 --- a/src/pab/pab_puissance.ts +++ b/src/pab/pab_puissance.ts @@ -1,6 +1,6 @@ import { Result } from "../util/result"; import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, ParamsEquation } from "../param"; -import { NumericalString } from "../index"; +import { NumericalString } from "../util/numericalstring"; import { Nub } from "../nub"; export class PabPuissanceParams extends ParamsEquation { diff --git a/src/section/hauteur.ts b/src/section/hauteur.ts index 3322f01e8c0f8feef1c09a3310407be1fed458c6..cb2cbae3bef69740cc2a5c0492fdbeb17c91b021 100644 --- a/src/section/hauteur.ts +++ b/src/section/hauteur.ts @@ -191,7 +191,6 @@ export class cHautCorrespondante extends acNewton { /** * 1/S^2 associé au tirant d'eau connu */ - // private rS2: number; private _rS2: Result; /** diff --git a/src/section/newton.ts b/src/section/newton.ts index e0eeb420d85d95106b6b8794a1e2ad8104684f68..1751609c51d43cd7f39f3f270cb69a2d7bd7d73d 100644 --- a/src/section/newton.ts +++ b/src/section/newton.ts @@ -6,7 +6,7 @@ import { Message, MessageCode } from "../util/message"; export abstract class acNewton extends Debug { protected rTol: number; protected Dx: number; - private iCpt: number; // = 0; + private iCpt: number; private iCptMax: number; private rRelax = 1; /// Coefficient de relaxation private rFnPrec = 0; /// Mémorisation du Fn précédent pour détecter le changement de signe @@ -58,7 +58,6 @@ export abstract class acNewton extends Debug { return (Math.abs(rFn) < this.rTol); } - /** * Fonction récursive de calcul de la suite du Newton * @param rX x @@ -66,21 +65,16 @@ export abstract class acNewton extends Debug { */ private doNewton(rX: number): Result { this.iCpt++; - this.debug("NEWTON : iter " + this.iCpt + " rX " + rX); const rFN = this.CalcFn(rX); if (!rFN.ok) return rFN; const rFn = rFN.vCalc; - this.debug("NEWTON : iter " + this.iCpt + " f(rX) " + rFn); // if (this.FuzzyEqual(rFn) || this.iCpt >= this.iCptMax) // return new Result(rX); if (this.FuzzyEqual(rFn)) // convergence - { - this.debug("NEWTON : iter " + this.iCpt + " CONV res=" + rX); return new Result(rX); - } if (this.iCpt >= this.iCptMax) { // non convergence const m = new Message(MessageCode.ERROR_NEWTON_NON_CONVERGENCE); @@ -94,7 +88,6 @@ export abstract class acNewton extends Debug { return rDER; const rDer = rDER.vCalc; - this.debug("NEWTON : iter " + this.iCpt + " der " + rDer); if (rDer != 0) { if (XOR(rFn < 0, this.rFnPrec < 0)) { this.iOscil++; @@ -128,7 +121,6 @@ export abstract class acNewton extends Debug { // Echec de la résolution // return undefined; - // return new Result(undefined); const m = new Message(MessageCode.ERROR_NEWTON_DERIVEE_NULLE); return new Result(m); } @@ -137,12 +129,4 @@ export abstract class acNewton extends Debug { this.iCpt = 0; return this.doNewton(rX); } - - /** - * Pour savoir si le Newton a convergé - * @return true si oui, false sinon - */ - // public hasConverged(): boolean { - // return this.iCpt < this.iCptMax; - // } } diff --git a/src/section/section_circulaire.ts b/src/section/section_circulaire.ts index 32031b51cefda3272c5c189739798ffb5e99044a..942dc121bace709f1c1c86fccb8877428e2a6398 100644 --- a/src/section/section_circulaire.ts +++ b/src/section/section_circulaire.ts @@ -118,7 +118,6 @@ export class cSnCirc extends acSection { // let res = d * Math.sin(this.Calc_AlphaY(yb, d)); let res = d * Math.sin(rAY.vCalc); - this.debug("Calc_LargeurBerge res=" + res); return new Result(res); } @@ -127,16 +126,7 @@ export class cSnCirc extends acSection { * @return B */ protected Calc_B(): Result { - this.debug("circ.Calc_B() : LargeurBerge " + this.prms.LargeurBerge.toString()); - this.debug("circ.Calc_B() : D " + this.prms.D.toString()); - this.debug("circ.Calc_B() : Y " + this.prms.Y.toString()); - if (this.isDebordement()) { - this.debug("circ.Calc_B() : débordement"); - //if (!this.prms.LargeurBerge.isDefined()) - // this.prms.LargeurBerge.v = this.Calc_LargeurBerge(); - // return super.Calc_B_Debordement(); - return this.Calc_LargeurBerge(); } diff --git a/src/section/section_trapez.ts b/src/section/section_trapez.ts index 57c353e4ecc77a5c23c58ac21e87772ffe61f7b1..f415776cb960cf1e5384e4ce6d3c9efcd23237a4 100644 --- a/src/section/section_trapez.ts +++ b/src/section/section_trapez.ts @@ -55,12 +55,8 @@ export class cSnTrapez extends acSection { return this.prms.Y.v > this.prms.YB.v; } - // Calc_B(bBerge = false): number { protected Calc_B(): Result { - // if (!bBerge && this.isDebordement()) - if (this.isDebordement()) - //return this.prms.LargeurBerge.v; - { + if (this.isDebordement()) { const v = this.prms.LargeurFond.v + 2 * this.prms.Fruit.v * this.prms.YB.v; return new Result(v); } diff --git a/src/section/section_type.ts b/src/section/section_type.ts index f57ea846fbf0ac253224651a8bb550d35fc5a5f6..1e910e39e41c2237ee4fac5f05150342d85eb76f 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -74,13 +74,6 @@ export abstract class cParamsCanal extends ParamsEquation { get YB(): ParamDefinition { return this._YB; } - - // /** - // * Longueur du bief - // */ - // get Long() { - // return this._Long; - // } } @@ -120,11 +113,7 @@ export abstract class ParamsSection extends cParamsCanal { export abstract class acSection extends ComputeNode { [key: string]: any; // pour pouvoir faire this['methode](); - // public HautCritique: number; /// Tirant d'eau critique private _hautCritique: Result; // Tirant d'eau critique - // public HautNormale: number; /// Tirant d'eau normal - - //protected oLog: cLog; /// Pour l'affichage du journal de calcul /** * true si la section est fermée (on considère alors qu'il existe une fente de Preissmann) @@ -168,7 +157,6 @@ export abstract class acSection extends ComputeNode { */ constructor(prms: ParamsSection, dbg: boolean = false) { super(prms, dbg); - //this.oLog = new cLog(); // this._v = oP.v; // copie la référence au tableau // this.prms.Y.v = 0; @@ -177,7 +165,6 @@ export abstract class acSection extends ComputeNode { // this.CalcGeo("B"); // à ce point, il manque des paramètres pour certaines sections (ex : fruit pour trapèze) this._newtonDbg = dbg; - // this._newtonDbg = true; } protected setParametersCalculability() { @@ -203,10 +190,6 @@ export abstract class acSection extends ComputeNode { this._newtonMaxIter = n; } - // public get log(): cLog { - // return this.oLog; - // } - public get HautCritique() { return this._hautCritique; } @@ -219,14 +202,9 @@ export abstract class acSection extends ComputeNode { this.debug("reset(" + bGeo + ")"); this.arCalc = {}; if (bGeo) { - // this.debug("reset Geo"); this.arCalcGeo = {}; this.bSnFermee = false; } - // this.debug("reset arCalc :"); - // this.debug(this.arCalc); - // this.debug("reset arCalcGeo :"); - // this.debug(this.arCalcGeo); } /** @@ -279,9 +257,13 @@ export abstract class acSection extends ComputeNode { switch (sDonnee) { case 'I-J': // Variation linéaire de l'énergie spécifique (I-J) en m/m // this.arCalc[sDonnee] = this.prms.If.v - this.Calc("J"); - var res: Result = this.Calc("J"); - if (res.ok) - this.arCalc[sDonnee] = this.prms.If.v - res.vCalc; + var rJ: Result = this.Calc("J"); + if (rJ.ok) { + this.arCalc[sDonnee] = this.prms.If.v - rJ.vCalc; + var res = new Result(this.arCalc[sDonnee]); + } + else + res = rJ; break; default: @@ -306,7 +288,7 @@ export abstract class acSection extends ComputeNode { } this._indentCalc--; - // this.debug('this.Y=' + this.prms.Y.toString()); + this.debug('this.Y=' + this.prms.Y.toString()); // return this.arCalc[sDonnee]; return res; @@ -401,7 +383,6 @@ export abstract class acSection extends ComputeNode { * @return La dérivée de la surface hydraulique en cas de débordement */ private Calc_dS_Debordement(): Result { - // return this.prms.LargeurBerge.v; return this.CalcGeo("B"); } @@ -631,23 +612,23 @@ export abstract class acSection extends ComputeNode { * @return Charge spécifique critique */ private Calc_Hsc(): Result { + let res: Result; + this.Swap(true); // On mémorise les données hydrauliques en cours // On calcule la charge avec la hauteur critique // var Hsc = this.Calc("Hs", this.CalcGeo("Yc")); const rYC: Result = this.CalcGeo("Yc"); if (!rYC.ok) - return rYC; - - const rHSC: Result = this.Calc("Hs", rYC.vCalc); - if (!rHSC.ok) - return rHSC; + res = rYC; + else + res = this.Calc("Hs", rYC.vCalc); // On restitue les données initiales this.Swap(false); // return Hsc; - return rHSC; + return res; } /** @@ -659,11 +640,9 @@ export abstract class acSection extends ComputeNode { this._hautCritique = hautCritique.Newton(this.prms.YB.v); // if (this.HautCritique == undefined || !hautCritique.hasConverged()) { - // if (!this._hautCritique.ok || !hautCritique.hasConverged()) { if (!this._hautCritique.ok) { let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCRITIQUE); // this.oLog.add(m); - // this._hautCritique.addMessage(m); this._hautCritique = new Result(m); } return this._hautCritique; @@ -674,7 +653,6 @@ export abstract class acSection extends ComputeNode { * @return tirant d'eau normal */ private Calc_Yn(): Result { - // this.debug("in calc_Yn"); if (this.prms.If.v <= 0) { let m = new Message(MessageCode.ERROR_SECTION_PENTE_NEG_NULLE_HNORMALE_INF); // this.oLog.add(m); @@ -691,11 +669,9 @@ export abstract class acSection extends ComputeNode { let rYN = oHautNormale.Newton(rYC.vCalc); // if (res == undefined || !oHautNormale.hasConverged()) { - // if (!rYN.ok || !oHautNormale.hasConverged()) { if (!rYN.ok) { let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HNORMALE); // this.oLog.add(m); - // rYN.addMessage(m); rYN = new Result(m); } @@ -715,20 +691,18 @@ export abstract class acSection extends ComputeNode { if (this.prms.Y.v > rGeoYC.vCalc) return new Result(this.prms.Y.v); + const oHautCorrespondante = new cHautCorrespondante(this, this._newtonMaxIter, this._newtonDbg); + const rYC: Result = this.Calc("Yc"); if (!rYC.ok) return rYC; - - var oHautCorrespondante = new cHautCorrespondante(this, this._newtonMaxIter, this._newtonDbg); // let res = oHautCorrespondante.Newton(this.Calc("Yc") * 2); let rYF = oHautCorrespondante.Newton(rYC.vCalc * 2); // if (res == undefined || !oHautCorrespondante.hasConverged()) { - // if (!rYF.ok || !oHautCorrespondante.hasConverged()) { if (!rYF.ok) { let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HFLU); // this.oLog.add(m); - //rYF.addMessage(m); rYF = new Result(m); } @@ -752,11 +726,9 @@ export abstract class acSection extends ComputeNode { // let res = oHautCorrespondante.Newton(this.CalcGeo("Yc") / 2); let rYT = oHautCorrespondante.Newton(rGeoYC.vCalc / 2); // if (res == undefined || !oHautCorrespondante.hasConverged()) { - // if (!rYT.ok || !oHautCorrespondante.hasConverged()) { if (!rYT.ok) { let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HTOR); // this.oLog.add(m); - // rYT.addMessage(m); rYT = new Result(m); } @@ -768,40 +740,45 @@ export abstract class acSection extends ComputeNode { * @return tirant d'eau conjugué */ private Calc_Yco(): Result { + let res: Result; + this.Swap(true); + const oHautConj = new cHautConjuguee(this, this._newtonMaxIter, this._newtonDbg); + const rFR: Result = this.Calc("Fr"); if (!rFR.ok) - return rFR; - - // Choisir une valeur initiale du bon côté de la courbe - // if (this.Calc("Fr") < 1) { - if (rFR.vCalc < 1) { - // Ecoulement fluvial, on cherche la conjuguée à partir du tirant d'eau torrentiel - var Y0: Result = this.Calc("Yt"); - } + res = rFR; else { - // Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial - Y0 = this.Calc("Yf"); - } - if (!Y0.ok) - return Y0; - - var oHautConj = new cHautConjuguee(this, this._newtonMaxIter, this._newtonDbg); - // let Yco = oHautConj.Newton(Y0); - let Yco: Result = oHautConj.Newton(Y0.vCalc); - - // if (Yco == undefined || !oHautConj.hasConverged()) { - // if (!Yco.ok || !oHautConj.hasConverged()) { - if (!Yco.ok) { - let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); - // this.oLog.add(m); - // Yco.addMessage(m); - Yco = new Result(m); + // Choisir une valeur initiale du bon côté de la courbe + // if (this.Calc("Fr") < 1) { + if (rFR.vCalc < 1) { + // Ecoulement fluvial, on cherche la conjuguée à partir du tirant d'eau torrentiel + var Y0: Result = this.Calc("Yt"); + } + else { + // Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial + Y0 = this.Calc("Yf"); + } + if (!Y0.ok) + res = Y0; + else { + // let Yco = oHautConj.Newton(Y0); + const Yco: Result = oHautConj.Newton(Y0.vCalc); + + // if (Yco == undefined || !oHautConj.hasConverged()) { + if (!Yco.ok) { + let m = new Message(MessageCode.ERROR_SECTION_NON_CONVERGENCE_NEWTON_HCONJUG); + // this.oLog.add(m); + res = new Result(m); + } + else + res = Yco; + } } this.Swap(false); - return Yco; + return res; } /**