Commit c8a13b42 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Add specs for SPP / YAXN

parent 405eefc8
......@@ -5,6 +5,7 @@ import { CreateStructure } from "../src/structure/factory_structure";
import { ParallelStructure } from "../src/structure/parallel_structure";
import { ParallelStructureParams } from "../src/structure/parallel_structure_params";
import { LoiDebit } from "../src/structure/structure_props";
import { MessageCode } from "../src/util/message";
import { YAXN } from "../src/yaxn";
import { YAXNParams } from "../src/yaxn_params";
......@@ -99,7 +100,7 @@ describe("Class SPP: ", () => {
});
it("non-integer exponent with negative coefficient", () => {
it("Calc(X) find negative C for integer N", () => {
const spp = new SPP(new SPPParams(-27));
const c1 = new YAXN(new YAXNParams(1, 666, 3));
spp.addChild(c1);
......@@ -107,4 +108,67 @@ describe("Class SPP: ", () => {
expect(spp.CalcSerie().vCalc).toBeCloseTo(-3, 3);
});
describe("error cases − ", () => {
it("Calc(Y), non-integer N on negative X in child should lead to error log", () => {
const spp = new SPP(new SPPParams(666));
const c1 = new YAXN(new YAXNParams(1, -4, 3.2));
spp.addChild(c1);
spp.calculatedParam = spp.prms.Y;
const res = spp.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_SOMETHING_FAILED);
expect(c1.result.log.messages.length).toBe(1);
expect(c1.result.log.messages[0].code).toBe(MessageCode.ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER);
});
it("Calc(X), non-integer N on negative X in non-calculated child should lead to error log", () => {
const spp = new SPP(new SPPParams(536636.0711158155));
const c1 = new YAXN(new YAXNParams(-495973.326926908, 986950.0910993216, 3.8095699869980315));
const c2 = new YAXN(new YAXNParams(694194.424256592, -985042.6786260167, -0.22419216942446418));
spp.addChild(c1);
spp.addChild(c2);
spp.calculatedParam = c1.prms.X;
const res = spp.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.ok).toBe(false);
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_SOMETHING_FAILED);
expect(c2.result.log.messages.length).toBe(1);
expect(c2.result.log.messages[0].code).toBe(MessageCode.ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER);
});
it("Calc(X), non-integer N on negative X in calculated child should lead to error log", () => {
const spp = new SPP(new SPPParams(536636.0711158155));
const c1 = new YAXN(new YAXNParams(-495973.326926908, 986950.0910993216, 3.8095699869980315));
const c2 = new YAXN(new YAXNParams(694194.424256592, -985042.6786260167, -0.22419216942446418));
spp.addChild(c1);
spp.addChild(c2);
spp.calculatedParam = c2.prms.X;
const res = spp.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.ok).toBe(false);
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER);
expect(c2.result.log.messages.length).toBe(1);
expect(c2.result.log.messages[0].code).toBe(MessageCode.ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER);
});
it("division by zero in parent should lead to error log", () => {
const spp = new SPP(new SPPParams(1));
spp.operation = SPPOperation.PRODUCT;
const c1 = new YAXN(new YAXNParams(2, 666, 3));
spp.addChild(c1);
const c2 = new YAXN(new YAXNParams(0, 1, 1));
spp.addChild(c2);
spp.calculatedParam = c1.prms.X;
const res = spp.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_DIVISION_BY_ZERO);
});
});
});
import { MessageCode } from "../src/index";
import { YAXN } from "../src/yaxn";
import { YAXNParams } from "../src/yaxn_params";
......@@ -17,12 +18,13 @@ describe("Class YAXN: ", () => {
expect(nub.result.vCalc).toBeCloseTo(2.5, 3);
});
it("non-integer N should trigger error", () => {
expect(() => {
const nub = new YAXN(new YAXNParams(10, 4, 3.2));
nub.calculatedParam = nub.prms.Y;
nub.CalcSerie();
}).toThrow();
it("non-integer N on negative X should lead to error log", () => {
const nub = new YAXN(new YAXNParams(10, -4, 3.2));
nub.calculatedParam = nub.prms.Y;
const res = nub.CalcSerie();
expect(res.vCalc).toBeUndefined();
expect(res.log.messages.length).toBe(1);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_NON_INTEGER_POWER_ON_NEGATIVE_NUMBER);
});
});
......@@ -86,7 +86,7 @@ export class SPP extends Nub {
if (cRes.ok) {
vPartielle *= cRes.vCalc;
} else {
this.result.globalLog.add(new Message(MessageCode.ERROR_SOMETHING_FAILED));
this.result.log.add(new Message(MessageCode.ERROR_SOMETHING_FAILED));
return this.result;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment