An error occurred while loading the file. Please try again.
-
Dorchies David authored81539e62
/**
* IMPORTANT !
* Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
* Pour exécuter ce code dans le débugger.
* Faire de même avec le fichier test_func.ts
*/
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
import { ParamCalculability } from "../../src/param/param-definition";
import { CreateStructure, loiAdmissibles, LoiDebit, StructureType } from "../../src/structure/factory_structure";
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
import { Structure } from "../../src/structure/structure";
import { Describer } from "../../src/util/describer";
import { EnumEx } from "../../src/util/enum";
import { MessageCode } from "../../src/util/message";
import { Result } from "../../src/util/result";
import { precDigits } from "../test_config";
import { checkResult } from "../test_func";
import { structTest } from "./structure_test";
const pstruct: ParallelStructure = new ParallelStructure(
new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15
false // debug
);
/*
* Tests avec deux structures test identiques
*/
pstruct.addStructure(structTest);
pstruct.addStructure(structTest);
describe("Class ParallelStructure: ", () => {
describe("Calc()", () => {
it("should return 1 result", () => {
const res: Result = pstruct.Calc("Q");
expect(pstruct.Calc("Q").nbResultElements).toEqual(1);
});
itParallelStructure("Q", 30, 15);
itParallelStructure("Z1", 30, 15);
itParallelStructure("Z2", 15, 15);
});
});
/**
* Test sur ParallelStructure
* @param sVarCalc Variable à calculer
* @param rVcalc Valeur de référence à retrouver
* @param Q Débit de chacune des structures (pour structures identiques uniquement)
*/
function itParallelStructure(sVarCalc: string, rVcalc: number, Q?: number) {
it(`${sVarCalc} should be ${rVcalc}`, () => {
checkResult(pstruct.Calc(sVarCalc), rVcalc);
});
if (Q !== undefined) {
for (let i = 0; i < pstruct.structures.length; i++) {
it(`ExtraResult[${i}.Q] should be ${Q}`, () => {
expect(
pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q`]
).toBeCloseTo(Q, Math.max(0, precDigits - 1));
});
it(`ExtraResult[${i}.Q_Mode] should be 0`, () => {
expect(
pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q_Mode`]
).toEqual(0);
});
it(`ExtraResult[${i}.Q_Regime] should be 0`, () => {
expect(
pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q_Regime`]
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
).toEqual(0);
});
}
}
}
/*
* Tests avec toutes les équations et toutes les variables (cf. jalhyd#38)
*/
const ps2: ParallelStructure = new ParallelStructure(
new ParallelStructureParams(0, 102, 101.5), // Q = 0, Z1 = 102, Z2 = 101.5
false // debug
);
// tslint:disable-next-line:prefer-for-of
describe("Class ParallelStructure: ", () => {
// Ajout d'une structure de chaque type dans ParallelStructure
const iLoiDebits: number[] = [];
const iStTypes: number[] = [];
for (const s of EnumEx.getValues(StructureType)) {
for (const la of loiAdmissibles[StructureType[s]]) {
ps2.addStructure(CreateStructure(s, la, false));
iLoiDebits.push(la);
iStTypes.push(s);
}
}
ps2.prms.Q.v = ps2.Calc("Q").vCalc;
for (let i = 0; i < ps2.structures.length; i++) {
const st: Structure = ps2.structures[i];
describe(`this.structures[${i}]: ${StructureType[iStTypes[i]]} Structure${LoiDebit[iLoiDebits[i]]}: `, () => {
// Tests sur les résultats complémentaires
it(`Calc(Q).extraResults[${i}.Q] should return ${ps2.structures[i].Calc("Q").vCalc}`, () => {
expect(
ps2.Calc("Q").extraResults[`${i}.Q`]
).toBe(
ps2.structures[i].Calc("Q").vCalc
);
});
// Tests de calcul des paramètres des ouvrages
for (const prm of st.prms) {
if (
prm.calculability === ParamCalculability.DICHO &&
prm.symbol !== "Z1" && prm.symbol !== "Z2"
) {
const ref: number = prm.v;
if (prm.symbol === "W" && prm.v === Infinity) {
// Le calcul de l'ouverture sur les seuils doit renvoyer une exception (cas impossible)
it(`Calc(${prm.symbol}) should return exception`, () => {
expect(
() => { ps2.Calc(i + "." + prm.symbol); }
).toThrow(new Error("Structure:Calc : Calcul de W impossible sur un seuil"));
});
} else if (
iStTypes[i] === StructureType.VanneRectangulaire &&
!ps2.structures[i].isZDVcalculable &&
prm.symbol === "ZDV"
) {
// Les lois CEM88D et CUNGE80 ne font pas intervenir ZDV dans le calcul d'un orifice noyé
it(`Calc(${prm.symbol}) should return an error`, () => {
expect(
ps2.Calc(i + "." + prm.symbol).code
).toBe(MessageCode.ERROR_STRUCTURE_ZDV_PAS_CALCULABLE);
});
} else {
// Cas normal : On teste la valeur calculée
141142143144145146147148149150151
it(`Calc(${prm.symbol}) should return ${ref}`, () => {
checkResult(ps2.Calc(i + "." + prm.symbol), ref);
});
}
prm.v = ref; // Go back to initial value for following tests
}
}
});
}
});