parallel_structure.spec.ts 6.06 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 { ParamCalculability } from "../../src/param/param-definition";
10
11
import { CreateStructure } from "../../src/structure/factory_structure";
import { LoiDebit, StructureType, loiAdmissibles } from "../../src/structure/structure_props";
12
13
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
14
15
16
import { Structure } from "../../src/structure/structure";
import { Describer } from "../../src/util/describer";
import { EnumEx } from "../../src/util/enum";
Dorchies David's avatar
Dorchies David committed
17
import { MessageCode } from "../../src/util/message";
18
import { Result } from "../../src/util/result";
Dorchies David's avatar
Dorchies David committed
19
import { precDigits } from "../test_config";
20
21
22
23
24
25
26
27
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
);

28
29
30
31
/*
 * Tests avec deux structures test identiques
 */

32
33
34
35
36
pstruct.addStructure(structTest);
pstruct.addStructure(structTest);

describe("Class ParallelStructure: ", () => {
    describe("Calc()", () => {
Dorchies David's avatar
Dorchies David committed
37
38
        it("should return 1 result", () => {
            const res: Result = pstruct.Calc("Q");
39
            expect(pstruct.Calc("Q").nbResultElements).toEqual(1);
Dorchies David's avatar
Dorchies David committed
40
        });
41
42
43
44
45
46
        itParallelStructure("Q", 30, 15);
        itParallelStructure("Z1", 30, 15);
        itParallelStructure("Z2", 15, 15);
    });
});

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)
 */
function itParallelStructure(sVarCalc: string, rVcalc: number, Q?: number) {
54
    it(`${sVarCalc} should be ${rVcalc}`, () => {
Dorchies David's avatar
Dorchies David committed
55
        checkResult(pstruct.Calc(sVarCalc), rVcalc);
56
    });
Dorchies David's avatar
Dorchies David committed
57
58
59
60
    if (Q !== undefined) {
        for (let i = 0; i < pstruct.structures.length; i++) {
            it(`ExtraResult[${i}.Q] should be ${Q}`, () => {
                expect(
61
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q`]
Dorchies David's avatar
Dorchies David committed
62
63
64
65
                ).toBeCloseTo(Q, Math.max(0, precDigits - 1));
            });
            it(`ExtraResult[${i}.Q_Mode] should be 0`, () => {
                expect(
66
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q_Mode`]
Dorchies David's avatar
Dorchies David committed
67
68
69
70
                ).toEqual(0);
            });
            it(`ExtraResult[${i}.Q_Regime] should be 0`, () => {
                expect(
71
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`${i}.Q_Regime`]
Dorchies David's avatar
Dorchies David committed
72
73
74
75
76
                ).toEqual(0);
            });

        }
    }
77
}
78
79
80
81
82
83
84
85
86
87

/*
 * 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
);

Dorchies David's avatar
Dorchies David committed
88
89
90
91
92
93
94
95
96
97
// 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);
Grand Francois's avatar
Grand Francois committed
98
99
        }
    }
100

Dorchies David's avatar
Dorchies David committed
101
    ps2.prms.Q.v = ps2.Calc("Q").vCalc;
102

Grand Francois's avatar
Grand Francois committed
103
    for (let i = 0; i < ps2.structures.length; i++) {
104
        const st: Structure = ps2.structures[i];
Dorchies David's avatar
Dorchies David committed
105
        describe(`this.structures[${i}]: ${StructureType[iStTypes[i]]} Structure${LoiDebit[iLoiDebits[i]]}: `, () => {
106
107
108
109
110
111
112
113
114
115
            // 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
116
            for (const prm of st.prms) {
Dorchies David's avatar
Dorchies David committed
117
118
119
120
121
                if (
                    prm.calculability === ParamCalculability.DICHO &&
                    prm.symbol !== "Z1" && prm.symbol !== "Z2"
                ) {
                    const ref: number = prm.v;
122
123
124
125
126
127
                    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"));
128
                        });
Dorchies David's avatar
Dorchies David committed
129
130
131
132
133
134
135
136
137
138
139
                    } 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);
                        });
140
                    } else {
Dorchies David's avatar
Dorchies David committed
141
142
143
144
                        // Cas normal : On teste la valeur calculée
                        it(`Calc(${prm.symbol}) should return ${ref}`, () => {
                            checkResult(ps2.Calc(i + "." + prm.symbol), ref);
                        });
145
                    }
Dorchies David's avatar
Dorchies David committed
146
                    prm.v = ref; // Go back to initial value for following tests
147
148
149
150
151
                }
            }
        });
    }
});