cond_distri.spec.ts 1.79 KB
Newer Older
Mathias Chouet's avatar
Mathias Chouet committed
1
2
3
import { YAXB } from "../src/axb";
import { YAXBParams } from "../src/axb_params";
import { MessageCode } from "../src/index";
4

Mathias Chouet's avatar
Mathias Chouet committed
5
describe("Class YAXB: ", () => {
6

Mathias Chouet's avatar
Mathias Chouet committed
7
8
9
10
11
    it("Y should be 10", () => {
        const nub = new YAXB(new YAXBParams(666, 2, 3, 4));
        nub.calculatedParam = nub.prms.Y;
        nub.CalcSerie();
        expect(nub.result.vCalc).toBe(10);
12
13
    });

Mathias Chouet's avatar
Mathias Chouet committed
14
15
16
17
18
    it("A should be 2", () => {
        const nub = new YAXB(new YAXBParams(10, 666, 3, 4));
        nub.calculatedParam = nub.prms.A;
        nub.CalcSerie();
        expect(nub.result.vCalc).toBe(2);
19
20
    });

Mathias Chouet's avatar
Mathias Chouet committed
21
22
23
24
25
    it("X should be 3", () => {
        const nub = new YAXB(new YAXBParams(10, 2, 666, 4));
        nub.calculatedParam = nub.prms.X;
        nub.CalcSerie();
        expect(nub.result.vCalc).toBe(3);
26
27
    });

Mathias Chouet's avatar
Mathias Chouet committed
28
29
30
31
32
    it("B should be 4", () => {
        const nub = new YAXB(new YAXBParams(10, 2, 3, 666));
        nub.calculatedParam = nub.prms.B;
        nub.CalcSerie();
        expect(nub.result.vCalc).toBe(4);
33
34
    });

Mathias Chouet's avatar
Mathias Chouet committed
35
36
37
38
39
40
41
    it("calc A with X = 0 should trigger error", () => {
        const nub = new YAXB(new YAXBParams(10, 666, 0, 4));
        nub.calculatedParam = nub.prms.A;
        nub.CalcSerie();
        expect(nub.result.ok).toBe(false);
        expect(nub.result.resultElement.log.messages.length).toBe(1);
        expect(nub.result.resultElement.log.messages[0].code).toBe(MessageCode.ERROR_DIVISION_BY_ZERO);
42
43
    });

Mathias Chouet's avatar
Mathias Chouet committed
44
45
46
47
48
49
50
    it("calc X with A = 0 should trigger error", () => {
        const nub = new YAXB(new YAXBParams(10, 0, 666, 4));
        nub.calculatedParam = nub.prms.X;
        nub.CalcSerie();
        expect(nub.result.ok).toBe(false);
        expect(nub.result.resultElement.log.messages.length).toBe(1);
        expect(nub.result.resultElement.log.messages[0].code).toBe(MessageCode.ERROR_DIVISION_BY_ZERO);
51
    });
Mathias Chouet's avatar
Mathias Chouet committed
52

53
});