parallel_structure.spec.ts 5.98 KB
Newer Older
1
2
3
4
5
6
/**
 * 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
 */
Grand Francois's avatar
Grand Francois committed
7
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
8

9
import { MessageCode } from "../../src/index";
10
import { CreateStructure } from "../../src/structure/factory_structure";
11
12
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
13
import { StructureKivi, StructureKiviParams } from "../../src/structure/structure_kivi";
14
import { loiAdmissiblesOuvrages, StructureType } from "../../src/structure/structure_props";
15
import { EnumEx } from "../../src/util/enum";
16
import { Result } from "../../src/util/result";
Dorchies David's avatar
Dorchies David committed
17
import { precDigits } from "../test_config";
18
import { checkResult } from "../test_func";
Dorchies David's avatar
Dorchies David committed
19
import { testParallelStructures } from "./functions";
Dorchies David's avatar
Dorchies David committed
20
import { CreateStructTest } from "./structure_test";
21

22
function createEnv() {
23
    const ps = new ParallelStructure(
24
25
26
27
28
29
        new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15
        false // debug
    );
    /*
     * Tests avec deux structures test identiques
     */
Dorchies David's avatar
Dorchies David committed
30
31
    ps.addChild(CreateStructTest());
    ps.addChild(CreateStructTest());
32
    return ps;
33
}
34

35
let pstruct: ParallelStructure;
36

37
function getVarCalc(pstructLoc: ParallelStructure, structIndex: number, sVarCalc: string): any {
38
39
40
41
42
43
44
45
46
    if (structIndex !== null) {
        return {
            uid: pstructLoc.structures[structIndex].uid,
            symbol: sVarCalc
        };
    } else {
        return sVarCalc;
    }
}
47

48
49
50
51
52
53
/**
 * 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)
 */
54
function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: number, Q?: number) {
55
    it(`${sVarCalc} should be ${rVcalc}`, () => {
56
57
        const VC1: any = getVarCalc(pstruct, structIndex, sVarCalc);
        checkResult(pstruct.Calc(VC1), rVcalc);
58
    });
Dorchies David's avatar
Dorchies David committed
59
    if (Q !== undefined) {
60
61
62
63
        const pstructLocal = createEnv();
        for (let i = 0; i < pstructLocal.structures.length; i++) {
            it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q] should be ${Q}`, () => {
                const VC2: any = getVarCalc(pstruct, structIndex, sVarCalc);
Dorchies David's avatar
Dorchies David committed
64
                expect(
65
                    pstruct.Calc(VC2).resultElement.extraResults[`ouvrage[${i}].Q`]
Dorchies David's avatar
Dorchies David committed
66
67
                ).toBeCloseTo(Q, Math.max(0, precDigits - 1));
            });
68
69
            it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Mode] should be 0`, () => {
                const VC3 = getVarCalc(pstruct, structIndex, sVarCalc);
Dorchies David's avatar
Dorchies David committed
70
                expect(
71
                    pstruct.Calc(VC3).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowMode`]
Dorchies David's avatar
Dorchies David committed
72
73
                ).toEqual(0);
            });
74
75
            it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Regime] should be 0`, () => {
                const VC4 = getVarCalc(pstruct, structIndex, sVarCalc);
Dorchies David's avatar
Dorchies David committed
76
                expect(
77
                    pstruct.Calc(VC4).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowRegime`]
Dorchies David's avatar
Dorchies David committed
78
79
80
81
                ).toEqual(0);
            });
        }
    }
82
}
83

Dorchies David's avatar
Dorchies David committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function CreateParalleleStructureTest(): {ps: ParallelStructure, LoiDebits: number[]} {
    const ps2: ParallelStructure = new ParallelStructure(
        new ParallelStructureParams(0, 102, 101.5), // Q = 0, Z1 = 102, Z2 = 101.5
        false // debug
    );
    // 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 loiAdmissiblesOuvrages[StructureType[s]]) {
            ps2.addChild(CreateStructure(la, ps2, false));
            iLoiDebits.push(la);
            iStTypes.push(s);
        }
    }
    return {ps: ps2, LoiDebits: iLoiDebits};
}

Dorchies David's avatar
Dorchies David committed
102
describe("Class ParallelStructure: ", () => {
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    describe("Calc()", () => {
        beforeEach(() => {
            pstruct = createEnv();
        });
        it("should return 1 result", () => {
            const p1 = createEnv();
            const res: Result = p1.Calc("Q");
            expect(p1.Calc("Q").nbResultElements).toEqual(1);
        });
        itParallelStructure(null, "Q", 30, 15);
        itParallelStructure(null, "Z1", 30, 15);
        itParallelStructure(null, "Z2", 15, 15);
        itParallelStructure(0, "ZDV", 0, 15);
        itParallelStructure(1, "ZDV", 0, 15);
        it("shoud return an error Q too high", () => {
            pstruct.prms.Q.v = 14;
            const res: Result = pstruct.Calc({
                uid: pstruct.structures[1].uid,
                symbol: "ZDV"
            });
            expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE);
        });

        /*
        * Tests avec toutes les équations et toutes les variables (cf. jalhyd#38)
        */
Dorchies David's avatar
Dorchies David committed
129
130

        testParallelStructures(CreateParalleleStructureTest);
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    });

    describe("#94 Lois d'ouvrage: Erreur de calcul de ZDV", () => {
        it(`Calc(ZDV) should return 101.57`, () => {
            const ps3: ParallelStructure = new ParallelStructure(
                new ParallelStructureParams(0.5, 102, 101.5), // Q = 0.5, Z1 = 102, Z2 = 101.5
                false // debug
            );
            const structTestKivi3: StructureKivi = new StructureKivi(
                new StructureKiviParams(
                    0, 0, 0, 0,     // Q, ZDV, Z1, Z2
                    1,          // L
                    0.4,        // alpha
                    0.001,      // béta
                    95.7         // ZRAM : cote Radier Amont
                ),
                false
            );
            ps3.addChild(structTestKivi3);
Dorchies David's avatar
Dorchies David committed
150
151
            ps3.calculatedParam = ps3.structures[0].prms.ZDV;
            expect(ps3.CalcSerie().vCalc).toBeCloseTo(101.57, 2);
152
153
        });
    });
154
});
155
156