parallel_structure.spec.ts 5.33 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
11
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
12
import { StructureKivi, StructureKiviParams } from "../../src/structure/structure_kivi";
13
import { Result } from "../../src/util/result";
Dorchies David's avatar
Dorchies David committed
14
import { precDigits } from "../test_config";
15
import { checkResult } from "../test_func";
16
import { CreateParalleleStructureTest, testParallelStructures } from "./functions";
Dorchies David's avatar
Dorchies David committed
17
import { CreateStructTest } from "./structure_test";
18

19
function createEnv() {
20
    const ps = new ParallelStructure(
21
22
23
24
25
26
        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
27
28
    ps.addChild(CreateStructTest());
    ps.addChild(CreateStructTest());
29
    return ps;
30
}
31

32
let pstruct: ParallelStructure;
33

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

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

Dorchies David's avatar
Dorchies David committed
81
describe("Class ParallelStructure: ", () => {
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    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)
        */
108
109
110
111
112
        const parallelStructure: ParallelStructure = new ParallelStructure(
            new ParallelStructureParams(0, 102, 101.5), // Q = 0, Z1 = 102, Z2 = 101.5
            false // debug
        );
        testParallelStructures(CreateParalleleStructureTest(parallelStructure));
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    });

    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
132
133
            ps3.calculatedParam = ps3.structures[0].prms.ZDV;
            expect(ps3.CalcSerie().vCalc).toBeCloseTo(101.57, 2);
134
135
        });
    });
136
});