parallel_structure.spec.ts 3.77 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, ParamDefinition, ParamsEquation } from "../../src/param";
Grand Francois's avatar
Grand Francois committed
10
import { CreateStructure, LoiDebit, StructureType } from "../../src/structure/factory_structure";
11
12
import { ParallelStructure } from "../../src/structure/parallel_structure";
import { ParallelStructureParams } from "../../src/structure/parallel_structure_params";
13
14
15
import { Structure } from "../../src/structure/structure";
import { Describer } from "../../src/util/describer";
import { EnumEx } from "../../src/util/enum";
16
17
18
19
20
21
22
23
24
import { Result } from "../../src/util/result";
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
);

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

29
30
31
32
33
34
35
36
37
38
39
pstruct.addStructure(structTest);
pstruct.addStructure(structTest);

describe("Class ParallelStructure: ", () => {
    describe("Calc()", () => {
        itParallelStructure("Q", 30, 15);
        itParallelStructure("Z1", 30, 15);
        itParallelStructure("Z2", 15, 15);
    });
});

40
41
42
43
44
45
46
/**
 * 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) {
47
48
49
    it(`${sVarCalc} should be ${rVcalc}`, () => {
        const res: Result = pstruct.Calc(sVarCalc);
        checkResult(res, rVcalc);
50
        if (Q !== undefined) {
Grand Francois's avatar
Grand Francois committed
51
            for (let i = 1; i < res.nbResults; i++) {
52
53
54
                checkResult(res.extractResult(i), Q);
            }
        }
55
56
    });
}
57
58
59
60
61
62
63
64
65
66
67

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

// Ajout d'une structure de chaque type dans ParallelStructure
68
for (const s of EnumEx.getValues(StructureType)) {
Grand Francois's avatar
Grand Francois committed
69
70
71
72
73
    for (const i of EnumEx.getValues(LoiDebit)) {
        try {
            ps2.addStructure(CreateStructure(s, i));
        }
        catch (e) {
74
            // Pour les combinaisons StructureType X LoiDebit impossibles rejetées par la Factory
Grand Francois's avatar
Grand Francois committed
75
76
        }
    }
77
}
78
79
80
81
82

ps2.prms.Q.v = ps2.Calc("Q").vCalc;

// tslint:disable-next-line:prefer-for-of
describe("Class ParallelStructure: ", () => {
Grand Francois's avatar
Grand Francois committed
83
    for (let i = 0; i < ps2.structures.length; i++) {
84
        const st: Structure = ps2.structures[i];
Grand Francois's avatar
Grand Francois committed
85
        describe(`this.structures[${i}]: Structure${LoiDebit[i]}: `, () => {
86
87
88
89
90
91
92
            // tslint:disable-next-line:forin
            for (const prm of st.prms) {
                if (prm.calculability === ParamCalculability.DICHO &&
                    prm.symbol !== "Z1" && prm.symbol !== "Z2") {
                    const ref: number = prm.v;
                    const res: Result = ps2.Calc(i + "." + prm.symbol);
                    prm.v = ref; // Go back to initial value for following tests
93
94
95
96
97
98
99
100
101
                    if ((i === 2 || i === 4) && prm.symbol === "ZDV") {
                        xit(`Calc(${prm.symbol}) should return ${ref}`, () => {
                            checkResult(res, ref);
                        });
                    } else {
                        it(`Calc(${prm.symbol}) should return ${ref}`, () => {
                            checkResult(res, ref);
                        });
                    }
102
103
104
105
106
                }
            }
        });
    }
});