macrorugo.spec.ts 5.47 KiB
/**
 * 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, ParamValueMode } from "../../src/index";
import { MacroRugo, MacroRugoFlowType, MacrorugoParams } from "../../src/macrorugo/macrorugo";
import { checkResult } from "../test_func";
*** Emergent conditions Cd=1.5***
ks=0.010000
D=0.500000
k=0.700000
Cd0=1.500000
S=0.050000
B=1.000000
h=0.600000
C=0.130000
Q=0.493722  fVal=0.000000
cote_bas = 12.200000
Vdeb = 0.822870
Fr = 0.530417
P = 242.170537
flowcond = emergent
Vmax = 1.799472
V_technique = 1.991299
q_technique = 0.561860
function macroRugoInstanceEmergentCd15(): MacroRugo {
    return new MacroRugo(
        new MacrorugoParams(
            12.5,   // ZF1
            6,      // L
            1,      // B
            0.05,   // If
            0.493722,    // Q
            0.6,    // h
            0.01,   // Ks
            0.13,   // C
            0.5,    // D
            0.7,    // k
            1.5     // Cd0
const macroRugoExtraResultEmergentCd15: { [key: string]: number|MacroRugoFlowType } = {
    ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT,
    Fr: 0.530417,
    PV: 242.170537,
    Q_GuideTech: 0.561860,
    V_GuideTech: 1.991299,
    Vdeb: 0.822870,
    Vmax: 1.799472,
    ZF2: 12.2
*** Emergent conditions Cd=2***
ks=0.010000
D=0.500000
k=0.700000
Cd0=2.000000
S=0.050000
B=1.000000
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
h=0.600000 C=0.130000 Q=0.376808 fVal=0.000000 cote_bas = 12.200000 Vdeb = 0.628013 Fr = 0.404814 P = 184.824088 flowcond = emergent Vmax = 1.536115 V_technique = 1.592932 q_technique = 0.414154 */ function macroRugoInstanceEmergentCd2(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd15(); nub.prms.Cd0.v = 2; nub.prms.Q.v = 0.376808; return nub; } const macroRugoExtraResultEmergentCd2: { [key: string]: number|MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.EMERGENT, Fr: 0.404814, PV: 184.824088, Q_GuideTech: 0.414154, V_GuideTech: 1.592932, Vdeb: 0.628013, Vmax: 1.536115, ZF2: 12.2 }; /* *** Submerged conditions *** ks=0.010000 D=0.500000 k=0.700000 Cd0=1.500000 S=0.050000 B=1.000000 h=0.800000 C=0.130000 Q=0.908068 fVal=0.000000 cote_bas = 12.200000 Vdeb = 1.135085 Fr = 0.633645 P = 445.407266 flowcond = immerge q_technique = 0.940450 */ function macroRugoInstanceSubmerged(): MacroRugo { const nub: MacroRugo = macroRugoInstanceEmergentCd15(); nub.prms.Y.v = 0.8; nub.prms.Q.v = 0.908068; return nub; } const macroRugoExtraResultSubmerged: { [key: string]: number|MacroRugoFlowType } = { ENUM_MacroRugoFlowType: MacroRugoFlowType.SUBMERGED, Fr: 0.633645, PV: 445.407266, Q_GuideTech: 0.940450, Vdeb: 1.135085, ZF2: 12.2 }; function MacroRugoFactory(sInstance: string): MacroRugo { switch (sInstance) { case "EmergentCd15": { return macroRugoInstanceEmergentCd15();
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
} case "EmergentCd2": { return macroRugoInstanceEmergentCd2(); } case "Submerged": { return macroRugoInstanceSubmerged(); } default: { throw new Error("Instance name error"); } } } function testMacroRugo(sInstance: string, varTest: string, valRef: number) { it(`Calc(${varTest}) should be ${valRef}`, () => { const nub = MacroRugoFactory(sInstance); nub.prms.Q.v = nub.Calc("Q").vCalc; const p = nub.getParameter(varTest); p.v = undefined; p.valueMode = ParamValueMode.CALCUL; checkResult(nub.Calc(varTest, 0.1), valRef); }); } function testMacroRugoConfig(sInstance: string, Q0: number, fVal0: number, mrExtraRes: { [key: string]: number }) { describe(`Condition ${sInstance}` , () => { it(`resolveQ(${Q0}) should be ${fVal0}`, () => { const nubit = MacroRugoFactory(sInstance); // tslint:disable-next-line:no-string-literal expect(nubit["resolveQ"](Q0)).toBeCloseTo(fVal0, 5); }); const nub = MacroRugoFactory(sInstance); for (const prm of nub.prms) { if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) { testMacroRugo(sInstance, prm.symbol, prm.v); } } for (const sExtraRes in mrExtraRes) { if (mrExtraRes.hasOwnProperty(sExtraRes)) { it(`${sExtraRes} should be ${mrExtraRes[sExtraRes]}`, () => { expect(MacroRugoFactory(sInstance).Calc("Q").extraResults[sExtraRes]) .toBeCloseTo(mrExtraRes[sExtraRes], 5); }); } } }); } describe("Class MacroRugo: ", () => { testMacroRugoConfig("EmergentCd15", 0.901710, 0.379574, macroRugoExtraResultEmergentCd15); testMacroRugoConfig("EmergentCd2", 0.768677, 0.418044, macroRugoExtraResultEmergentCd2); // Le test passe en debug mais pas sous Jasmine !?? // describe(`Condition Submerged` , () => { // it(`resolveAlpha_t(0.07) should be 0.074752`, () => { // // tslint:disable-next-line:no-string-literal // expect(macroRugoInstanceSubmerged()["resolveAlpha_t"](0.07)).toBeCloseTo(0.074752, 5); // }); // }); testMacroRugoConfig("Submerged", 1.202280, 0.145051, macroRugoExtraResultSubmerged); });