parallel_structure.spec.ts 3.46 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 { CreateStructure } from "../../src/structure/factory_structure";
10
11
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
Dorchies David's avatar
Dorchies David committed
12
import { loiAdmissibles, StructureType } from "../../src/structure/structure_props";
13
import { EnumEx } from "../../src/util/enum";
14
import { Result } from "../../src/util/result";
Dorchies David's avatar
Dorchies David committed
15
import { precDigits } from "../test_config";
16
import { checkResult } from "../test_func";
Dorchies David's avatar
Dorchies David committed
17
import { testParallelStructures } from "./functions";
18
19
20
21
22
23
24
import { structTest } from "./structure_test";

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

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

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

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

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

/*
 * 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
84
85
86
87
88
89
90
91
92
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
93
94
        }
    }
Dorchies David's avatar
Dorchies David committed
95
    testParallelStructures(ps2, iStTypes, iLoiDebits);
96
});