macrorugo.spec.ts 4.43 KB
Newer Older
1
2
3
4
5
6
7
8
/**
 * 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";

9
import { ParamCalculability, ParamValueMode } from "../../src";
10
import { MacroRugo, MacroRugoFlowType, MacrorugoParams } from "../../src/macrorugo/macrorugo";
Dorchies David's avatar
Dorchies David committed
11
import { checkPercent, checkResult } from "../test_func";
12

13
function macroRugoInstanceEmergent(): MacroRugo {
14
15
16
17
18
19
    return new MacroRugo(
        new MacrorugoParams(
            12.5,   // ZF1
            6,      // L
            1,      // B
            0.05,   // If
20
            1.57,    // Q
21
22
23
24
25
26
27
28
29
30
            0.6,    // h
            0.01,   // Ks
            0.05,   // C
            0.5,    // D
            0.8,    // k
            1.5     // Cd0
        )
    );
}

31
32
33
34
35
36
37
38
39
function macroRugoInstanceSubmerged(): MacroRugo {
    const nub: MacroRugo = macroRugoInstanceEmergent();
    nub.prms.Y.v = 0.8;
    nub.prms.PBH.v = 0.6;
    nub.prms.Q.v = 4.737;
    return nub;
}

function testMacroRugo(nubFactory: () => MacroRugo, varTest: string, valRef: number) {
40
    describe("Calc(): ", () => {
41
        it(`${varTest} should be ${valRef}`, () => {
42
            const nub = nubFactory();
43
            nub.prms.Q.v = nub.Calc("Q").vCalc;
44
45
46
47
            const p = nub.getParameter(varTest);
            p.v = undefined;
            p.valueMode = ParamValueMode.CALCUL;
            checkResult(nub.Calc(varTest, 0.1), valRef);
48
49
50
51
52
53
        });
    });
}

describe("Class MacroRugo: ", () => {

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    describe("Emerged conditions", () => {
        it(`resolveU0(2.58) should be around 0`, () => {
            const nubit = macroRugoInstanceEmergent();
            // tslint:disable-next-line:no-string-literal
            expect(nubit["resolveU0"](2.58)).toBeCloseTo(0, 1);
        });

        it(`resolveQ(1.547827) should be around 0`, () => {
            const nubit = macroRugoInstanceEmergent();
            // tslint:disable-next-line:no-string-literal
            expect(nubit["resolveQ"](1.547827)).toBeCloseTo(0, 1);
        });

        it(`Calc("Q") should be around 1.548`, () => {
            checkResult(macroRugoInstanceEmergent().Calc("Q", 0.1), 1.548, 1);
        });

        it(`Calc("Q", 0.1).extraResults.ZF2 should be around 12.2`, () => {
            expect(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.ZF2).toBeCloseTo(12.2, 3);
        });

        it(`Calc("Q", 0.1).extraResults.Vdeb should be around 2.579818`, () => {
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.Vdeb, 2.579818, 0.03);
        });
78

79
80
81
82
83
84
85
86
87
        it(`Calc("Q", 0.1).extraResults.V should be around 2.694279`, () => {
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.V, 2.694279, 0.03);
        });

        it(`Calc("Q", 0.1).extraResults.Fr should be around 1.369611`, () => {
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.Fr, 1.369611, 0.03);
        });

        it(`Calc("Q", 0.1).extraResults.P should be around 759.240352`, () => {
88
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.PV, 759.240352, 0.03);
89
90
91
        });

        it(`Calc("Q", 0.1).extraResults.FlowType should be MacroRugoFlowType.EMERGENT`, () => {
92
93
            expect(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.ENUM_MacroRugoFlowType)
                .toBe(MacroRugoFlowType.EMERGENT);
94
95
96
        });

        it(`Calc("Q", 0.1).extraResults.Q2 should be around 0.868672`, () => {
97
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.Q_GuideTech, 0.868672, 0.03);
98
99
100
        });

        it(`Calc("Q", 0.1).extraResults.V2 should be around 1.991299`, () => {
101
            checkPercent(macroRugoInstanceEmergent().Calc("Q", 0.1).extraResults.V_GuideTech, 1.991299, 0.03);
102
103
104
105
106
107
108
        });

        const nub = macroRugoInstanceEmergent();
        for (const prm of nub.prms) {
            if ([ParamCalculability.DICHO, ParamCalculability.EQUATION].includes(prm.calculability)) {
                testMacroRugo(macroRugoInstanceEmergent, prm.symbol, prm.v);
            }
109
        }
110
111
112
113
114
115
116
117
118
    });
    describe("Submerged conditions", () => {
        it(`resolveQ(4.737) should be around 0`, () => {
            const nubit = macroRugoInstanceSubmerged();
            // tslint:disable-next-line:no-string-literal
            expect(nubit["resolveQ"](4.737)).toBeCloseTo(0, 1);
        });

    });
119
});