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

Work on #128 - refactor results

simplify Result and ResultElement
remove ExtraResult
temporary retrocompatibility methods
parent 66ada0aa
......@@ -9,7 +9,9 @@ describe("Class Nub: ", () => {
expect(nub.Calc("C").vCalc).toBeCloseTo(3, precDigits);
});
it("should return a result.vCalc equal to 1", () => {
expect(nub.Calc("A").vCalc).toBeCloseTo(1, precDigits);
const r = nub.Calc("A");
const v = r.vCalc;
expect(v).toBeCloseTo(1, precDigits);
});
it("should return a result.vCalc equal to 2", () => {
expect(nub.Calc("B").vCalc).toBeCloseTo(2, precDigits);
......
......@@ -55,7 +55,8 @@ describe("Class ConduiteDistrib: ", () => {
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("D", 0), 2.12847);
const r = nub.Calc("D", 0);
checkResult(r, 2.12847);
});
});
......
import { ExtraResults, ParamDefinition, ParamDomainValue, Result, ResultElement } from "../../src/index";
import { ParamDefinition, ParamDomainValue, Result, ResultElement } from "../../src/index";
/**
* IMPORTANT !
......@@ -31,7 +31,7 @@ function testResultValues(vals: number[]): Result {
}
let n = 0;
for (const v of r.valuesIterator) {
for (const v of r.getCalculatedValues()) {
expect(v).toEqual(vals[n++]);
}
......@@ -40,7 +40,7 @@ function testResultValues(vals: number[]): Result {
return r;
}
function testExtraResultsValues(vals: number[]): ExtraResults {
/* function testExtraResultsValues(vals: number[]): ExtraResults {
const ers: ExtraResults = new ExtraResults("aa");
for (const v of vals) {
......@@ -55,14 +55,14 @@ function testExtraResultsValues(vals: number[]): ExtraResults {
expect(n).toEqual(vals.length);
return ers;
}
} */
describe("INamedIterableValues : ", () => {
describe("ParamDefinition : ", () => {
it("test 1", () => {
const name = "aa";
const p: ParamDefinition = new ParamDefinition(null, name, ParamDomainValue.ANY);
expect(p.name).toEqual(name);
expect(p.symbol).toEqual(name);
});
it("test 2", () => {
......@@ -88,52 +88,26 @@ describe("INamedIterableValues : ", () => {
it("test 1", () => {
const name = "aa";
const r: Result = new Result(0);
r.name = name;
expect(r.name).toEqual(name);
r.symbol = name;
expect(r.symbol).toEqual(name);
});
it("test 2", () => {
const vals: number[] = [];
const r = testResultValues(vals);
expect(r.hasMultipleValues).toBeFalsy();
expect(r.hasMultipleValues()).toBeFalsy();
});
it("test 3", () => {
const vals: number[] = [0];
const r = testResultValues(vals);
expect(r.hasMultipleValues).toBeFalsy();
expect(r.hasMultipleValues()).toBeFalsy();
});
it("test 3", () => {
const vals: number[] = [0, 1];
const r = testResultValues(vals);
expect(r.hasMultipleValues).toBeTruthy();
});
});
describe("ExtraResults : ", () => {
it("test 1", () => {
const name = "aa";
const ers: ExtraResults = new ExtraResults(name);
expect(ers.name).toEqual(name);
});
it("test 2", () => {
const vals: number[] = [];
const ers = testExtraResultsValues(vals);
expect(ers.hasMultipleValues).toBeFalsy();
});
it("test 3", () => {
const vals: number[] = [0];
const ers = testExtraResultsValues(vals);
expect(ers.hasMultipleValues).toBeFalsy();
});
it("test 4", () => {
const vals: number[] = [0, 1];
const ers = testExtraResultsValues(vals);
expect(ers.hasMultipleValues).toBeTruthy();
expect(r.hasMultipleValues()).toBeTruthy();
});
});
});
......@@ -166,7 +166,8 @@ function testMacroRugo(sInstance: string, varTest: string, valRef: number) {
const p = nub.getParameter(varTest);
p.v = undefined;
p.valueMode = ParamValueMode.CALCUL;
checkResult(nub.Calc(varTest, 0.1), valRef);
const r = nub.Calc(varTest, 0.1);
checkResult(r, valRef);
});
}
......
......@@ -25,8 +25,9 @@ describe("class CloisonAval", () => {
s = ca.structures[0] as StructureVanLevVillemonte;
});
it("Calc(Z1) should return 75.077 and extraResults.ZDV should be 73.95", () => {
expect(ca.CalcSerie().vCalc).toBeCloseTo(75.077, 3);
expect(ca.CalcSerie().extraResults.ZDV).toBeCloseTo(73.95, 2);
const r = ca.CalcSerie();
expect(r.vCalc).toBeCloseTo(75.077, 3);
expect(r.extraResults.ZDV).toBeCloseTo(73.95, 2);
});
it("ZDV min bound Calc(Z1) should return 75.059 and extraResults.ZDV should be 73.9", () => {
s.prms.maxZDV.singleValue = 73.90;
......
......@@ -208,7 +208,7 @@ describe("Class Pab: ", () => {
pab.calculatedParam = pab.prms.Q;
pab.prms.Z1.singleValue = 76.60;
pab.CalcSerie();
expect(pab.result.hasLog).toBe(true);
expect(pab.result.hasLog()).toBe(true);
expect(pab.result.resultElement.log.messages[0].code)
.toBe(MessageCode.ERROR_PAB_Z1_LOWER_THAN_UPSTREAM_WALL); // @TODO or other error message ?
});
......@@ -219,8 +219,8 @@ describe("Class Pab: ", () => {
pab.calculatedParam = pab.prms.Q;
pab.prms.Z1.setValues(73, 85, 6);
pab.CalcSerie();
expect(pab.result.nbResultElements).toBe(3);
expect(pab.result.hasLog).toBe(true);
expect(pab.result.resultElements.length).toBe(3);
expect(pab.result.hasLog()).toBe(true);
expect(pab.result.resultElements[0].log.messages[0].code).toBe(MessageCode.ERROR_PAB_Z1_LOWER_THAN_Z2);
});
......@@ -229,8 +229,8 @@ describe("Class Pab: ", () => {
pab.prms.Z1.setValues(73, 85, 6);
pab.CalcSerie();
// for ex. Cloisons n°1
expect(pab.children[0].result.nbResultElements).toBe(3);
expect(Object.keys(pab.children[0].result.resultElements[1].extraResults).length).toBe(12);
expect(pab.children[0].result.resultElements.length).toBe(3);
expect(Object.keys(pab.children[0].result.resultElements[1].realExtraResults).length).toBe(12);
});
});
......
......@@ -129,7 +129,7 @@ describe("Class RegimeUniforme / section puissance :", () => {
const res: Result = ru.Calc("k", 0);
expect(res.vCalc).toBeUndefined();
expect(res.code).toBe(MessageCode.ERROR_DICHO_INIT_DOMAIN);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_DICHO_INIT_DOMAIN);
});
it("k should be 0.635", () => {
......@@ -196,7 +196,7 @@ describe("Class RegimeUniforme / section puissance :", () => {
const res: Result = ru.Calc("Ks", 5000000);
expect(res.vCalc).toBeUndefined();
expect(res.code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_LOW);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_LOW);
});
it("Ks should be undefined", () => {
......@@ -215,7 +215,7 @@ describe("Class RegimeUniforme / section puissance :", () => {
const res: Result = ru.Calc("Ks", 1e-8);
expect(res.vCalc).toBeUndefined();
expect(res.code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_HIGH);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_HIGH);
});
it("If should be 0.001", () => {
......
......@@ -13,7 +13,7 @@ import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { Result } from "../../src/util/result";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog } from "../test_func";
import { compareExtraResult, compareLog, extraResultLength } from "../test_func";
describe("Class Remous / section rectangulaire :", () => {
describe("méthode Euler explicite :", () => {
......@@ -54,7 +54,7 @@ describe("Class Remous / section rectangulaire :", () => {
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(
res.extraResultLength("tor") === 0
extraResultLength(res, "tor") === 0
).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100];
......@@ -117,7 +117,7 @@ describe("Class Remous / section rectangulaire :", () => {
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(
res.extraResultLength("tor") === 0
extraResultLength(res, "tor") === 0
).toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// const x = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100];
......
......@@ -4,7 +4,7 @@ import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rect
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog, equalEpsilon } from "../test_func";
import { compareExtraResult, compareLog, equalEpsilon, extraResultLength } from "../test_func";
/*
Certaines valeurs de ligne d'eau torrentielle étaient auparavant remplacées par une valeur fluviale
......@@ -398,7 +398,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version Typescript (Oct 2017) méthode trapèzes
expect(res.extraResultLength("flu") === 0).toBeTruthy(
expect(extraResultLength(res, "flu") === 0).toBeTruthy(
"la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......@@ -463,7 +463,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode trapèzes
expect(res.extraResultLength("flu") === 0)
expect(extraResultLength(res, "flu") === 0)
.toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......
......@@ -4,7 +4,7 @@ import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rect
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog, equalEpsilon } from "../test_func";
import { compareExtraResult, compareLog, equalEpsilon, extraResultLength } from "../test_func";
/*
Le code de modification des lignes fluviale et torrentielle a été modifié, on enlève un point de plus
......@@ -309,7 +309,7 @@ describe("Class Remous / section rectangulaire :", () => {
// compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03);
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(res.extraResultLength("tor") === 0)
expect(extraResultLength(res, "tor") === 0)
.toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// tslint:disable-next-line:max-line-length
......@@ -386,7 +386,7 @@ describe("Class Remous / section rectangulaire :", () => {
// compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03);
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(res.extraResultLength("tor") === 0)
expect(extraResultLength(res, "tor") === 0)
.toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// tslint:disable-next-line:max-line-length
......
......@@ -4,7 +4,7 @@ import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rect
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog } from "../test_func";
import { compareExtraResult, compareLog, extraResultLength } from "../test_func";
/*
cas 1 :
......@@ -417,7 +417,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode RungeKutta4
expect(res.extraResultLength("flu") === 0)
expect(extraResultLength(res, "flu") === 0)
.toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......@@ -495,7 +495,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode RungeKutta4
expect(res.extraResultLength("flu") === 0)
expect(extraResultLength(res, "flu") === 0)
.toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......
......@@ -12,7 +12,7 @@ import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rect
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog, equalEpsilon } from "../test_func";
import { compareExtraResult, compareLog, equalEpsilon, extraResultLength } from "../test_func";
/*
Le code de modification des lignes fluviale et torrentielle a été modifié, on enlève un point de plus
......@@ -535,7 +535,7 @@ describe("Class Remous / section rectangulaire :", () => {
// compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03);
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(res.extraResultLength("tor") === 0)
expect(extraResultLength(res, "tor") === 0)
.toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// tslint:disable-next-line:max-line-length
......@@ -612,7 +612,7 @@ describe("Class Remous / section rectangulaire :", () => {
// compareObject("Yfluvial", res.getExtraResult("flu"), f, 0.03);
compareExtraResult("Yfluvial", res, "flu", f, 0.03);
expect(res.extraResultLength("tor") === 0)
expect(extraResultLength(res, "tor") === 0)
.toBeTruthy("la ligne d'eau torrentielle ne devrait comporter aucune valeur");
// tslint:disable-next-line:max-line-length
......@@ -664,7 +664,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode trapèzes
expect(res.extraResultLength("flu") === 0)
expect(extraResultLength(res, "flu") === 0)
.toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = { 0.000: 0.15, 5.000: 0.239, 10.000: 0.34 };
......
......@@ -4,7 +4,7 @@ import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rect
import { cLog } from "../../src/util/log";
import { Message, MessageCode } from "../../src/util/message";
import { precDist } from "../test_config";
import { compareExtraResult, compareLog, equalEpsilon } from "../test_func";
import { compareExtraResult, compareLog, equalEpsilon, extraResultLength } from "../test_func";
/*
cas 1 :
......@@ -418,7 +418,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode trapèzes
expect(res.extraResultLength("flu") === 0).toBeTruthy(
expect(extraResultLength(res, "flu") === 0).toBeTruthy(
"la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......@@ -479,7 +479,7 @@ describe("Class Remous / section rectangulaire :", () => {
// données de validation : version PHP (Oct 2017) méthode trapèzes
expect(res.extraResultLength("flu") === 0)
expect(extraResultLength(res, "flu") === 0)
.toBeTruthy("la ligne d'eau fluviale ne devrait comporter aucune valeur");
const t = {
......
......@@ -103,7 +103,7 @@ function testStructureLoopPrm(
// Les lois CEM88D et CUNGE80 ne font pas intervenir ZDV dans le calcul d'un orifice noyé
it(`should return an error`, () => {
expect(
st.CalcSerie().code
st.CalcSerie().log.messages[0].code
).toBe(MessageCode.ERROR_STRUCTURE_ZDV_PAS_CALCULABLE);
});
} else {
......@@ -173,7 +173,7 @@ export function testParallelStructures(o: { ps: ParallelStructure, ld: number[]
// Les lois GateCEM88D et CUNGE80 ne permettent pas le calcul de ZDV
it(`should return an error`, () => {
expect(
o.ps.CalcSerie().code
o.ps.CalcSerie().log.messages[0].code
).toBe(MessageCode.ERROR_STRUCTURE_ZDV_PAS_CALCULABLE);
});
} else if (
......
......@@ -91,7 +91,7 @@ describe("Class ParallelStructure: ", () => {
it("should return 1 result", () => {
const p1 = createEnv();
const res: Result = p1.Calc("Q");
expect(p1.Calc("Q").nbResultElements).toEqual(1);
expect(p1.Calc("Q").resultElements.length).toEqual(1);
});
itParallelStructure(null, "Q", 30, 15);
itParallelStructure(null, "Z1", 30, 15);
......@@ -104,7 +104,7 @@ describe("Class ParallelStructure: ", () => {
uid: pstruct.structures[1].uid,
symbol: "ZDV"
});
expect(res.code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_STRUCTURE_Q_TROP_ELEVE);
});
/*
......
......@@ -56,13 +56,14 @@ describe("Class Structure: ", () => {
it("Z1=Z2 => Q=0", () => {
structTest.prms.Z2.v = structTest.prms.Z1.v;
checkResult(structTest.Calc("Q"), 0);
expect(structTest.Calc("Q").extraResults).toEqual(flagsNull);
expect(structTest.Calc("Q").realExtraResults).toEqual(flagsNull);
structTest.prms.Z2.v = 15;
});
it("W=0 => Q=0", () => {
structTest.prms.W.v = 0;
checkResult(structTest.Calc("Q"), 0);
expect(structTest.Calc("Q").extraResults).toEqual(flagsNull);
const r = structTest.Calc("Q");
checkResult(r, 0);
expect(r.realExtraResults).toEqual(flagsNull);
structTest.prms.W.v = Infinity;
});
it("Q=0 => Z1=Z2", () => {
......@@ -76,7 +77,7 @@ describe("Class Structure: ", () => {
structTest.prms.Q.v = 0;
structTest.prms.W.v = 1; // Sinon, W = Infinity => Structure = Seuil => Throw Error
checkResult(structTest.Calc("W"), 0);
expect(structTest.Calc("W").extraResults).toEqual(flagsNull);
expect(structTest.Calc("W").realExtraResults).toEqual(flagsNull);
structTest.prms.Q.v = 1;
});
// TODO Test inversion de débit
......
......@@ -63,7 +63,7 @@ describe("Class StructureGateCem88v: ", () => {
s.prms.Q.singleValue = 9;
s.calculatedParam = s.prms.W;
const res: Result = s.CalcSerie();
expect(res.code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_HIGH);
expect(res.log.messages[0].code).toBe(MessageCode.ERROR_DICHO_TARGET_TOO_HIGH);
});
});
});
......@@ -192,7 +192,7 @@ export function compareLog(logTest: cLog, logValid: cLog) {
}
export function checkResult(result: Result, valRef: number, prec?: number) {
expect(result.ok).toBeTruthy((!result.ok) ? "Result: ERROR code=" + MessageCode[result.code] : "");
expect(result.ok).toBeTruthy((!result.ok) ? "Result: ERROR code=" + MessageCode[result.log.messages[0].code] : "");
if (result.ok) {
/*
* on demande une précision de vérification inférieure à la précision de calcul
......@@ -296,3 +296,13 @@ export function SetJasmineCurrentSpec() {
export function isFiniteNumber(x: any) {
return isNumeric(x) && isFinite(x);
}
export function extraResultLength(res: Result, name: string): number {
let nb = 0;
for (const re of res.resultElements) {
if (re.getValue(name) !== undefined) {
nb ++;
}
}
return nb;
}
......@@ -6,7 +6,7 @@
*/
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
import { ResultElement } from "../../src/util/resultelement";
/* import { ResultElement } from "../../src/util/resultelement";
describe("Class Result: ", () => {
describe("Method AddResulToExtra", () => {
......@@ -21,4 +21,4 @@ describe("Class Result: ", () => {
expect(resEle).toEqual(resEleRef);
});
});
});
}); */
......@@ -48,7 +48,7 @@ export abstract class ComputeNode extends JalhydObject implements IDebug {
* { symbol => ParamFamily } map for ExtraResults; defines a priori which
* future extra result can be linked to other Nub's parameters
*/
protected _extraResultsFamilies: any;
protected _resultsFamilies: any;
protected _calcType: CalculatorType;
......@@ -117,11 +117,11 @@ export abstract class ComputeNode extends JalhydObject implements IDebug {
* Define ParamFamily (@see ParamDefinition) for extra results
*/
protected setExtraResultsFamilies() {
this._extraResultsFamilies = {};
this._resultsFamilies = {};
}
public get extraResultsFamilies() {
return this._extraResultsFamilies;
return this._resultsFamilies;
}
protected abstract setParametersCalculability(): void;
......
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