Commit 89d34483 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

YAXN: restrict N to integers, add specs

parent a9bf6490
import { YAXN } from "../src/yaxn";
import { YAXNParams } from "../src/yaxn_params";
describe("Class YAXN: ", () => {
it("Y should be 65.625", () => {
const nub = new YAXN(new YAXNParams(4.2, 2.5, 3));
nub.calculatedParam = nub.prms.Y;
nub.CalcSerie();
expect(nub.result.vCalc).toBe(65.625);
});
it("X should be 2.5", () => {
const nub = new YAXN(new YAXNParams(4.2, 666, 3, 65.625));
nub.calculatedParam = nub.prms.X;
nub.CalcSerie();
expect(nub.result.vCalc).toBe(2.5);
});
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();
});
});
......@@ -569,6 +569,15 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
}
break;
case ParamDomainValue.INTEGER:
if (! Number.isInteger(v)) {
const f = new Message(MessageCode.ERROR_PARAMDEF_VALUE_INTEGER);
f.extraVar.symbol = this.symbol;
f.extraVar.value = v;
throw f;
}
break;
default:
const e = new Message(MessageCode.ERROR_PARAMDOMAIN_INVALID);
e.extraVar.symbol = this.symbol;
......
......@@ -5,30 +5,23 @@ import { Message, MessageCode } from "../util/message";
* domaine de définition du paramètre
*/
export enum ParamDomainValue {
/**
* >0, =0, <0 (-inf -> +inf)
*/
/** >0, =0, <0 (-inf -> +inf) */
ANY,
/**
* >=0
*/
/** >=0 */
POS_NULL,
/**
* > 0
*/
/** > 0 */
POS,
/**
* <>0
*/
/** <>0 */
NOT_NULL,
/**
* intervalle
*/
INTERVAL
/** intervalle */
INTERVAL,
/** nombre entier relatif */
INTEGER
}
export class ParamDomain {
......@@ -41,6 +34,7 @@ export class ParamDomain {
case ParamDomainValue.ANY:
case ParamDomainValue.NOT_NULL:
case ParamDomainValue.INTEGER:
return { min: -Infinity, max: Infinity };
case ParamDomainValue.POS:
......
......@@ -19,17 +19,17 @@ export class YAXNParams extends ParamsEquation {
/** N */
private _N: ParamDefinition;
constructor(rA: number, rX: number, rN: number) {
constructor(rA: number, rX: number, rN: number, rY?: number) {
super();
this._Y = new ParamDefinition(this, "Y", ParamDomainValue.ANY, undefined, undefined, undefined, false);
this._A = new ParamDefinition(this, "A", ParamDomainValue.ANY, undefined, rA);
this._X = new ParamDefinition(this, "X", ParamDomainValue.ANY, undefined, rX, ParamFamily.ANY);
this._N = new ParamDefinition(this, "N", ParamDomainValue.ANY, undefined, rN);
this._N = new ParamDefinition(this, "N", ParamDomainValue.INTEGER, undefined, rN);
this._Y = new ParamDefinition(this, "Y", ParamDomainValue.ANY, undefined, rY, undefined, false);
this.addParamDefinition(this._Y);
this.addParamDefinition(this._A);
this.addParamDefinition(this._X);
this.addParamDefinition(this._N);
this.addParamDefinition(this._Y);
}
get Y() {
......
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