Commit 2c96123d authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Update fuzzy tests for SPP/YAXN and Trigo

parent 1ff170bf
import { CalculatorType } from "../src/compute-node";
import { Grille, Session, SPP, YAXN, YAXNParams } from "../src/index";
import { Grille, ParamDomainValue, Session, SPP, YAXN, YAXNParams } from "../src/index";
import { MacrorugoCompound } from "../src/macrorugo/macrorugo_compound";
import { Nub } from "../src/nub";
import { CloisonAval } from "../src/pab/cloison_aval";
......@@ -9,7 +9,7 @@ import { Props } from "../src/props";
import { SectionNub } from "../src/section/section_nub";
import { CreateStructure } from "../src/structure/factory_structure";
import { ParallelStructure } from "../src/structure/parallel_structure";
import { Trigo } from "../src/trigo";
import { Trigo, TrigoOperation } from "../src/trigo";
import { checkResultConsistency, SetJasmineCurrentSpec } from "./test_func";
/**
......@@ -39,7 +39,8 @@ const nubsNotTested: CalculatorType[] = [
CalculatorType.Structure,
CalculatorType.Section,
CalculatorType.CloisonAval,
CalculatorType.Solveur
CalculatorType.Solveur,
CalculatorType.YAXN
];
const nubsWithStructures: CalculatorType[] = [
......@@ -61,15 +62,34 @@ const calTypes =
).map((e) => +e);
function randomizeParameter(p: ParamDefinition) {
p.singleValue = Math.max(-1E6, p.domain.minValue)
let min = p.domain.minValue;
let max = p.domain.maxValue;
// special case for SPP to avoid +/-Infinity with high powers
if (p.parentNub instanceof YAXN && p.symbol === "N") {
min = -10;
max = 10;
}
// special case for Trigo to avoid +/-Infinity with cosh/sinh
if (
p.parentNub instanceof Trigo
&& p.symbol === "X"
&& [ TrigoOperation.COSH, TrigoOperation.SINH ].includes((p.parentNub as Trigo).operation)
) {
min = -500;
max = 500;
}
p.singleValue = Math.max(-1E6, min)
+ Math.random()
* (
Math.min(1E6, p.domain.maxValue)
- Math.max(-1E6, p.domain.minValue)
Math.min(1E6, max)
- Math.max(-1E6, min)
);
if (Math.random() < fuzzyCfg.propInvertedPrm) {
p.singleValue = 1 / p.currentValue;
}
if (p.domain.domain === ParamDomainValue.INTEGER) {
p.singleValue = Math.floor(p.singleValue);
}
}
function printPrms(n: Nub): string {
......@@ -101,7 +121,7 @@ function setRandomSection(sn: SectionNub) {
sn.setSection(newSect);
}
function setRandomOperation(sn: Trigo) {
function setRandomTrigoOperation(sn: Trigo) {
const op = Math.floor(Math.random() * 6);
sn.operation = op;
}
......@@ -111,12 +131,17 @@ function setRandomTrigoUnit(sn: Trigo) {
sn.unit = un;
}
function setRandomSppOperation(sn: SPP) {
const op = Math.floor(Math.random() * 2);
sn.operation = op;
}
function addRandomYAXNs(n: SPP, nYMax: number = 3) {
const nY = Math.floor(Math.random() * nYMax) + 1;
for (let i = 0; i < nY; i++) {
n.addChild(
new YAXN(
new YAXNParams(Math.random() * 10, Math.random() * 10, Math.random() * 10)
new YAXNParams(Math.random() * 10, Math.random() * 10, Math.floor(Math.random() * 10))
)
);
}
......@@ -172,11 +197,12 @@ function CreateTestNub(iCalType: number): Nub {
setRandomSection(n as SectionNub);
}
if (iCalType === CalculatorType.Trigo) {
setRandomOperation(n as Trigo);
setRandomTrigoOperation(n as Trigo);
setRandomTrigoUnit(n as Trigo);
}
if (iCalType === CalculatorType.SPP) {
addRandomYAXNs(n as SPP);
setRandomSppOperation(n as SPP);
}
for (const p of n.parameterIterator) {
if (p.visible) {
......@@ -204,8 +230,7 @@ describe("Fuzz testing", () => {
}
});
for (const iCalType of calTypes) {
// if ([CalculatorType.MacroRugoCompound].includes(iCalType)) {
if (!nubsNotTested.includes(iCalType)) {
if (!nubsNotTested.includes(iCalType) /* && iCalType === CalculatorType.Trigo */) {
describe(CalculatorType[iCalType], () => {
for (let i = 0; i < fuzzyCfg.nTests; i++) {
describe(`Test ${i}`, () => {
......
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