parallel_structure.spec.ts 3.87 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

Dorchies David's avatar
Dorchies David committed
9
import { MessageCode } from "../../src";
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
 */

30
31
32
33
34
pstruct.addStructure(structTest);
pstruct.addStructure(structTest);

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);
Dorchies David's avatar
Dorchies David committed
42
43
44
        itParallelStructure("0.ZDV", 0, 15);
        itParallelStructure("1.ZDV", 0, 15);
        it("shoud return an error Q too high", () => {
45
46
47
            pstruct.prms.Q.v = 14;
            const res: Result = pstruct.Calc("1.ZDV");
            expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE);
Dorchies David's avatar
Dorchies David committed
48
        });
49
50
51
    });
});

52
53
54
55
56
57
58
/**
 * 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) {
59
    it(`${sVarCalc} should be ${rVcalc}`, () => {
Dorchies David's avatar
Dorchies David committed
60
        checkResult(pstruct.Calc(sVarCalc), rVcalc);
61
    });
Dorchies David's avatar
Dorchies David committed
62
63
    if (Q !== undefined) {
        for (let i = 0; i < pstruct.structures.length; i++) {
64
            it(`ExtraResult[ouvrage[${i}].Q] should be ${Q}`, () => {
Dorchies David's avatar
Dorchies David committed
65
                expect(
66
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q`]
Dorchies David's avatar
Dorchies David committed
67
68
                ).toBeCloseTo(Q, Math.max(0, precDigits - 1));
            });
69
            it(`ExtraResult[ouvrage[${i}].Q_Mode] should be 0`, () => {
Dorchies David's avatar
Dorchies David committed
70
                expect(
71
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowMode`]
Dorchies David's avatar
Dorchies David committed
72
73
                ).toEqual(0);
            });
74
            it(`ExtraResult[ouvrage[${i}].Q_Regime] should be 0`, () => {
Dorchies David's avatar
Dorchies David committed
75
                expect(
76
                    pstruct.Calc(sVarCalc).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowRegime`]
Dorchies David's avatar
Dorchies David committed
77
78
79
80
                ).toEqual(0);
            });
        }
    }
81
}
82
83
84
85
86
87
88
89
90
91

/*
 * 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
92
93
94
95
96
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)) {
97
        for (const la of loiAdmissiblesOuvrages[StructureType[s]]) {
98
            ps2.addStructure(CreateStructure(s, la, ps2, false));
Dorchies David's avatar
Dorchies David committed
99
100
            iLoiDebits.push(la);
            iStTypes.push(s);
Grand Francois's avatar
Grand Francois committed
101
102
        }
    }
Dorchies David's avatar
Dorchies David committed
103
    testParallelStructures(ps2, iStTypes, iLoiDebits);
104
});