From 6f99124cece02a11a9f6ccdec0629e9797714b29 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Thu, 15 Jun 2017 16:00:00 +0200 Subject: [PATCH] correction bugs dans les tests --- spec/nubtest.ts | 2 +- spec/regime_uniforme_circ.spec.ts | 21 ++++++++-------- spec/regime_uniforme_puissance.spec.ts | 2 +- spec/regime_uniforme_rect.spec.ts | 4 +-- spec/regime_uniforme_trapeze.spec.ts | 2 +- spec/section_param_rect_fluvial.spec.ts | 30 +++++++++++++---------- spec/section_param_trapez_fluvial.spec.ts | 30 +++++++++++++---------- src/param.ts | 10 ++++++++ src/section/section_circulaire.ts | 3 ++- src/section/section_type.ts | 15 ++++++------ 10 files changed, 69 insertions(+), 50 deletions(-) diff --git a/spec/nubtest.ts b/spec/nubtest.ts index d0f0c2f9..9b0fc3d6 100644 --- a/spec/nubtest.ts +++ b/spec/nubtest.ts @@ -55,7 +55,7 @@ export class NubTest extends Nub { protected setParametersCalculability() { this.getParameter('A').calculability = ParamCalculability.DICHO; this.getParameter('B').calculability = ParamCalculability.DICHO; - //this.getParameter('C').calculability = ParamCalculability.EQUATION; // TODO + this.getParameter('C').calculability = ParamCalculability.EQUATION; } get prms(): NubTestParams { diff --git a/spec/regime_uniforme_circ.spec.ts b/spec/regime_uniforme_circ.spec.ts index f1d01da1..57d1987b 100644 --- a/spec/regime_uniforme_circ.spec.ts +++ b/spec/regime_uniforme_circ.spec.ts @@ -25,13 +25,12 @@ describe('Class RegimeUniforme / section circulaire : ', () => { let ru = new RegimeUniforme(sect); - // expect(ru.Calc("D", 0, 0.001).vCalc).toBeCloseTo(6, 2); - expect(ru.Calc("D").vCalc).toBeCloseTo(6, 2); + expect(ru.Calc("D", 1e-8).vCalc).toBeCloseTo(6, 2); }); it('Ks should be 40', () => { - let paramCnl = new ParamsSectionCirc(6, // diamètre + let paramSection = new ParamsSectionCirc(6, // diamètre 0.6613, // tirant d'eau undefined, // Ks=Strickler 1.2, // Q=Débit @@ -41,15 +40,15 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl); + let sect = new cSnCirc(undefined, paramSection); let ru = new RegimeUniforme(sect); - expect(ru.Calc("Ks").vCalc).toBeCloseTo(40, 2); + expect(ru.Calc("Ks", 1e-8).vCalc).toBeCloseTo(40, 2); }); it('If should be 0.001', () => { - let paramCnl = new ParamsSectionCirc(6, // diamètre + let paramSection = new ParamsSectionCirc(6, // diamètre 0.6613, // tirant d'eau 40, // Ks=Strickler 1.2, // Q=Débit @@ -59,7 +58,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl); + let sect = new cSnCirc(undefined, paramSection); let ru = new RegimeUniforme(sect); @@ -67,7 +66,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { }); it('Q should be 1.2', () => { - let paramCnl = new ParamsSectionCirc(6, // diamètre + let paramSection = new ParamsSectionCirc(6, // diamètre 0.6613, // tirant d'eau 40, // Ks=Strickler undefined, // Q=Débit @@ -77,7 +76,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl); + let sect = new cSnCirc(undefined, paramSection); let ru = new RegimeUniforme(sect); @@ -85,7 +84,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { }); it('Y should be 0.6613', () => { - let paramCnl = new ParamsSectionCirc(6, // diamètre + let paramSection = new ParamsSectionCirc(6, // diamètre undefined, // tirant d'eau 40, // Ks=Strickler 1.2, // Q=Débit @@ -95,7 +94,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl); + let sect = new cSnCirc(undefined, paramSection); let ru = new RegimeUniforme(sect); diff --git a/spec/regime_uniforme_puissance.spec.ts b/spec/regime_uniforme_puissance.spec.ts index e19d0db2..a210c33d 100644 --- a/spec/regime_uniforme_puissance.spec.ts +++ b/spec/regime_uniforme_puissance.spec.ts @@ -64,7 +64,7 @@ describe('Class RegimeUniforme / section puissance: ', () => { let ru = new RegimeUniforme(sect, false); - expect(ru.Calc("Ks").vCalc).toBeCloseTo(33.774, 2); + expect(ru.Calc("Ks", 1e-8).vCalc).toBeCloseTo(33.774, 2); }); diff --git a/spec/regime_uniforme_rect.spec.ts b/spec/regime_uniforme_rect.spec.ts index 5472c9ce..36347bda 100644 --- a/spec/regime_uniforme_rect.spec.ts +++ b/spec/regime_uniforme_rect.spec.ts @@ -44,7 +44,7 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect); - expect(ru.Calc("Ks").vCalc).toBeCloseTo(30.618, precDigits); + expect(ru.Calc("Ks", 1e-8).vCalc).toBeCloseTo(30.618, precDigits); }); it('If should be 0.001', () => { @@ -101,8 +101,8 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { it('Y should be 0.663', () => { let prms = new ParamsSectionRectang(undefined, // tirant d'eau + 2.5, // largeur de fond 40, // Ks=Strickler - 2.5, // largeur de fond 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision diff --git a/spec/regime_uniforme_trapeze.spec.ts b/spec/regime_uniforme_trapeze.spec.ts index 2b3a7677..c4987891 100644 --- a/spec/regime_uniforme_trapeze.spec.ts +++ b/spec/regime_uniforme_trapeze.spec.ts @@ -62,7 +62,7 @@ describe('Class RegimeUniforme / section trapèze: ', () => { let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); - expect(ru.Calc("Ks").vCalc).toBeCloseTo(24.14, precDigits); + expect(ru.Calc("Ks", 1e-8).vCalc).toBeCloseTo(24.14, precDigits); }); it('If should be 0.001', () => { diff --git a/spec/section_param_rect_fluvial.spec.ts b/spec/section_param_rect_fluvial.spec.ts index 0371cd94..488453f0 100644 --- a/spec/section_param_rect_fluvial.spec.ts +++ b/spec/section_param_rect_fluvial.spec.ts @@ -7,19 +7,23 @@ import { ParamsSectionRectang, cSnRectang } from "../src/section/section_rectang let paramSection: ParamsSectionRectang; let sect: cSnRectang; +function createSection(prec: number): cSnRectang { + paramSection = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler + 1.2, // Q=Débit + 0.001, // If=pente du fond + prec, // précision + 1 // YB= hauteur de berge + // YCL=Condition limite en cote à l'amont ou à l'aval + ); + + return new cSnRectang(undefined, paramSection); +} + describe('Section paramétrée rectangulaire : ', () => { beforeEach(() => { - paramSection = new ParamsSectionRectang(0.8, // tirant d'eau - 2.5, // largeur de fond - 40, // Ks=Strickler - 1.2, // Q=Débit - 0.001, // If=pente du fond - precDist, // précision - 1 // YB= hauteur de berge - // YCL=Condition limite en cote à l'amont ou à l'aval - ); - - sect = new cSnRectang(undefined, paramSection); + sect = createSection(precDist); }); describe('fluvial :', () => { @@ -90,13 +94,13 @@ describe('Section paramétrée rectangulaire : ', () => { // perte de charge it('J should equal to 0.00059', () => { - paramSection.Prec.v = 0.00001; + sect = createSection(0.00001); expect(sect.Calc_J()).toBeCloseTo(0.00059, precDigits); }); // Variation linéaire de l'énergie spécifique it('I-J should equal to 0.00041', () => { - paramSection.Prec.v = 0.00001; + sect = createSection(0.00001); expect(sect.Calc("I-J")).toBeCloseTo(0.00041, precDigits); }); diff --git a/spec/section_param_trapez_fluvial.spec.ts b/spec/section_param_trapez_fluvial.spec.ts index 352641e7..896fdc87 100644 --- a/spec/section_param_trapez_fluvial.spec.ts +++ b/spec/section_param_trapez_fluvial.spec.ts @@ -7,20 +7,24 @@ import { ParamsSectionTrapez, cSnTrapez } from "../src/section/section_trapez"; let paramSection: ParamsSectionTrapez; let sect: cSnTrapez; +function createSection(prec: number): cSnTrapez { + paramSection = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.8, // tirant d'eau + 40, // Ks=Strickler + 1.2, // Q=Débit + 0.001, // If=pente du fond + precDist, // précision + 1 // YB= hauteur de berge + // YCL=Condition limite en cote à l'amont ou à l'aval + ); + + return new cSnTrapez(undefined, paramSection); +} + describe('Section paramétrée trapèze : ', () => { beforeEach(() => { - paramSection = new ParamsSectionTrapez(2.5, // largeur de fond - 0.56, // fruit - 0.8, // tirant d'eau - 1.2, // Q=Débit - 40, // Ks=Strickler - 0.001, // If=pente du fond - precDist, // précision - 1 // YB= hauteur de berge - // YCL=Condition limite en cote à l'amont ou à l'aval - ); - - sect = new cSnTrapez(undefined, paramSection); + sect = createSection(precDist); }); describe('fluvial :', () => { @@ -91,7 +95,7 @@ describe('Section paramétrée trapèze : ', () => { // perte de charge it('J should equal to 0.00036', () => { - paramSection.Prec.v = 0.00001; + let sect = createSection(0.00001); expect(sect.Calc_J()).toBeCloseTo(0.00036, precDigits); }); diff --git a/src/param.ts b/src/param.ts index 86e2d429..8d8a751a 100644 --- a/src/param.ts +++ b/src/param.ts @@ -189,6 +189,10 @@ export class ParamDefinition { this._value = val; } + get uncheckedValue() { + return this._value; + } + private checkValue(v: number) { let sDomain = ParamDomainValue[this._domain.value]; @@ -252,6 +256,12 @@ export class ParamDefinition { this._savedValue = undefined; } */ + + toString(): string { + if (this.isDefined()) + return "" + this._value; + return "undefined"; + } } diff --git a/src/section/section_circulaire.ts b/src/section/section_circulaire.ts index e32b2346..ee0ddbb8 100644 --- a/src/section/section_circulaire.ts +++ b/src/section/section_circulaire.ts @@ -77,7 +77,8 @@ export class cSnCirc extends acSection { private isDebordement(): boolean { // return this.prms.Y.v > Math.min(this.prms.YB.v, this.prms.D.v); //return this.valeurYDebordement() > 0; - return this.prms.Y.v >= this.prms.D.v || this.prms.Y.v >= this.prms.YB.v + // return this.prms.Y.v >= this.prms.D.v || this.prms.Y.v >= this.prms.YB.v + return this.prms.Y.v > this.prms.D.v || this.prms.Y.v > this.prms.YB.v } /** diff --git a/src/section/section_type.ts b/src/section/section_type.ts index 95c1b01f..e8eb8508 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -221,8 +221,8 @@ export abstract class acSection extends ComputeNode { */ private Swap(bMem) { if (bMem) { - this.debug('save Y=' + this.prms.Y.v); - this.Y_old = this.prms.Y.v; + this.debug('save Y=' + this.prms.Y.toString()); + this.Y_old = this.prms.Y.uncheckedValue; this.Calc_old = this.arCalc; } else { @@ -241,9 +241,10 @@ export abstract class acSection extends ComputeNode { */ Calc(sDonnee: string, rY: number = undefined): number { this.debug("in Calc(" + sDonnee + ", rY = " + rY + ") old " + sDonnee + "= " + this.arCalc[sDonnee]); - this.debug("this.Y=" + this.prms.Y.v); + this.debug("this.Y=" + this.prms.Y.toString()); - if (rY != undefined && rY != this.prms.Y.v) { + //if (rY != undefined && rY != this.prms.Y.v) { + if (rY != undefined && (!this.prms.Y.isDefined() || rY != this.prms.Y.v)) { this.prms.Y.v = rY; // On efface toutes les données dépendantes de Y pour forcer le calcul this.Reset(false); @@ -276,7 +277,7 @@ export abstract class acSection extends ComputeNode { else this.debug("Calc(" + sDonnee + ") cache= " + this.arCalc[sDonnee]); - this.debug('this.Y=' + this.prms.Y.v); + this.debug('this.Y=' + this.prms.Y.toString()); return this.arCalc[sDonnee]; } @@ -289,7 +290,7 @@ export abstract class acSection extends ComputeNode { */ CalcGeo(sDonnee): number { this.debug("in CalcGeo(" + sDonnee + ') old ' + sDonnee + '=' + this.arCalcGeo[sDonnee]); - this.debug('this.Y=' + this.prms.Y.v); + this.debug('this.Y=' + this.prms.Y.toString()); // if (sDonnee != 'B' && !this.arCalcGeo['B']) { if (sDonnee != 'B' && this.arCalcGeo['B'] == undefined) { @@ -329,7 +330,7 @@ export abstract class acSection extends ComputeNode { else this.debug("CalcGeo(" + sDonnee + ") cache= " + this.arCalcGeo[sDonnee]); - this.debug('this.Y=' + this.prms.Y.v); + this.debug('this.Y=' + this.prms.Y.toString()); return this.arCalcGeo[sDonnee]; } -- GitLab