parallel_structure.spec.ts 4.08 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 { loiAdmissiblesOuvrages, StructureType } from "../../src/structure/structure_props";
14
import { EnumEx } from "../../src/util/enum";
15
import { Result } from "../../src/util/result";
Dorchies David's avatar
Dorchies David committed
16
import { precDigits } from "../test_config";
17
import { checkResult } from "../test_func";
Dorchies David's avatar
Dorchies David committed
18
import { testParallelStructures } from "./functions";
19
20
21
22
23
24
25
import { structTest } from "./structure_test";

const pstruct: ParallelStructure = new ParallelStructure(
    new ParallelStructureParams(30, 30, 15), // Q = 30, Z1 = 30, Z2 = 15
    false // debug
);

26
27
28
29
/*
 * Tests avec deux structures test identiques
 */

Mathias Chouet's avatar
Mathias Chouet committed
30
31
pstruct.addChild(structTest);
pstruct.addChild(structTest);
32
33
34

describe("Class ParallelStructure: ", () => {
    describe("Calc()", () => {
Dorchies David's avatar
Dorchies David committed
35
36
        it("should return 1 result", () => {
            const res: Result = pstruct.Calc("Q");
37
            expect(pstruct.Calc("Q").nbResultElements).toEqual(1);
Dorchies David's avatar
Dorchies David committed
38
        });
39
40
41
        itParallelStructure("Q", 30, 15);
        itParallelStructure("Z1", 30, 15);
        itParallelStructure("Z2", 15, 15);
42
43
44
45
46
47
48
49
        itParallelStructure({
            uid: pstruct.structures[0].uid,
            symbol: "ZDV"
        }, 0, 15);
        itParallelStructure({
            uid: pstruct.structures[1].uid,
            symbol: "ZDV"
        }, 0, 15);
Dorchies David's avatar
Dorchies David committed
50
        it("shoud return an error Q too high", () => {
51
            pstruct.prms.Q.v = 14;
52
53
54
55
            const res: Result = pstruct.Calc({
                uid: pstruct.structures[1].uid,
                symbol: "ZDV"
            });
56
            expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE);
Dorchies David's avatar
Dorchies David committed
57
        });
58
59
60
    });
});

61
62
63
64
65
66
/**
 * 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)
 */
67
function itParallelStructure(sVarCalc: any, rVcalc: number, Q?: number) {
68
    it(`${sVarCalc} should be ${rVcalc}`, () => {
Dorchies David's avatar
Dorchies David committed
69
        checkResult(pstruct.Calc(sVarCalc), rVcalc);
70
    });
Dorchies David's avatar
Dorchies David committed
71
72
    if (Q !== undefined) {
        for (let i = 0; i < pstruct.structures.length; i++) {
73
            it(`ExtraResult[ouvrage[${i}].Q] should be ${Q}`, () => {
Dorchies David's avatar
Dorchies David committed
74
                expect(
75
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q`]
Dorchies David's avatar
Dorchies David committed
76
77
                ).toBeCloseTo(Q, Math.max(0, precDigits - 1));
            });
78
            it(`ExtraResult[ouvrage[${i}].Q_Mode] should be 0`, () => {
Dorchies David's avatar
Dorchies David committed
79
                expect(
80
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowMode`]
Dorchies David's avatar
Dorchies David committed
81
82
                ).toEqual(0);
            });
83
            it(`ExtraResult[ouvrage[${i}].Q_Regime] should be 0`, () => {
Dorchies David's avatar
Dorchies David committed
84
                expect(
85
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowRegime`]
Dorchies David's avatar
Dorchies David committed
86
87
88
89
                ).toEqual(0);
            });
        }
    }
90
}
91
92
93
94
95
96
97
98
99
100

/*
 * 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
101
102
103
104
105
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)) {
106
        for (const la of loiAdmissiblesOuvrages[StructureType[s]]) {
Mathias Chouet's avatar
Mathias Chouet committed
107
            ps2.addChild(CreateStructure(la, ps2, false));
Dorchies David's avatar
Dorchies David committed
108
109
            iLoiDebits.push(la);
            iStTypes.push(s);
Grand Francois's avatar
Grand Francois committed
110
111
        }
    }
Mathias Chouet's avatar
Mathias Chouet committed
112
    testParallelStructures(ps2, iLoiDebits);
113
});