diff --git a/spec/fuzzing.spec.ts b/spec/fuzzing.spec.ts index 193358345a04c7da424794e581fbb5afda3f0ae3..230d6a0afbf135f8432b2927fafa3280ff147ab9 100644 --- a/spec/fuzzing.spec.ts +++ b/spec/fuzzing.spec.ts @@ -181,10 +181,10 @@ describe("Fuzz testing", () => { describe(`Test ${i}`, () => { beforeAll(() => { // tslint:disable-next-line:no-console - console.debug( - // tslint:disable-next-line:max-line-length - `iNub=${iNub} Class=${nubs[iNub].constructor.name} Type=${CalculatorType[nubs[iNub].calcType]} uid=${nubs[iNub].uid}` - ); + /* console.debug( + `iNub=${iNub} Class=${nubs[iNub].constructor.name}` + + ` Type=${CalculatorType[nubs[iNub].calcType]} uid=${nubs[iNub].uid}` + ); */ }); afterAll(() => { iNub++; diff --git a/spec/value_ref/value_ref_variable.spec.ts b/spec/value_ref/value_ref_variable.spec.ts index 73a5e9cf349e9deba0fea443729b6a9008c22860..9a1bb55926ed7e0d63c5d4c7941ca66dfd4ad9ab 100644 --- a/spec/value_ref/value_ref_variable.spec.ts +++ b/spec/value_ref/value_ref_variable.spec.ts @@ -1,11 +1,12 @@ import { ConduiteDistrib } from "../../src/cond_distri"; import { ConduiteDistribParams } from "../../src/cond_distri_params"; -import { Session } from "../../src/index"; +import { CourbeRemous, CourbeRemousParams, cSnRectang, ParamsSectionRectang, Session, ParamValueMode } from "../../src/index"; import { SessionSettings } from "../../src/session_settings"; import { Result } from "../../src/util/result"; let nub1: ConduiteDistrib; let nub2: ConduiteDistrib; +let nub3: CourbeRemous; let prm1: ConduiteDistribParams; let prm2: ConduiteDistribParams; @@ -22,9 +23,18 @@ function createEnv() { nub2 = new ConduiteDistrib(new ConduiteDistribParams(3, 1.2, 0.6, 100, 0.000001)); prm2 = nub2.prms as ConduiteDistribParams; + // Nub avec paramètres non variables + nub3 = new CourbeRemous( + new cSnRectang( + new ParamsSectionRectang(0.8, 2.5, 40, 1.2, 0.01, 1.2) + ), + new CourbeRemousParams(101, 100.05, 100.9, 100, 50, 2) + ); + Session.getInstance().clear(); Session.getInstance().registerNub(nub1); Session.getInstance().registerNub(nub2); + Session.getInstance().registerNub(nub3); } describe("Référence d'un paramètre à un paramètre varié : ", () => { @@ -50,4 +60,68 @@ describe("Référence d'un paramètre à un paramètre varié : ", () => { } }); + + it("un paramètre non variable ne doit pas être liable à un paramètre varié", () => { + // cas de figure : + // nub3.Q est lié à nub2.Q, fixé + // nub2.Q passe en mode varié + // nub3.Q ne doit plus être liable à nub2.Q + + createEnv(); + + nub2.calculatedParam = prm2.Lg; + prm2.Q.singleValue = 1.25; + + let linkables = Session.getInstance().getLinkableValues(nub3.section.prms.Q); + let found = false; + for (const l of linkables) { + found = (l.nub === nub2) && (l.symbol === "Q"); + } + expect(found).toBe(true); + + nub3.section.prms.Q.defineReference(nub2, "Q"); + expect(nub3.section.prms.Q.valueMode).toBe(ParamValueMode.LINK); + expect(nub3.section.prms.Q.hasMultipleValues).toBe(false); + + prm2.Q.setValues(1, 1.5, 0.1); + + linkables = Session.getInstance().getLinkableValues(nub3.section.prms.Q); + found = false; + for (const l of linkables) { + found = (l.nub === nub2) && (l.symbol === "Q"); + } + expect(found).toBe(false); + }); + + it("un paramètre non variable ne doit pas être liable à un résultat varié", () => { + // cas de figure : + // nub3.Q est lié à nub2.Q, résultat de calcul + // nub2.Lg passe en mode varié + // nub3.Q ne doit plus être liable à nub2.Q + + createEnv(); + + nub2.calculatedParam = prm2.Q; + prm2.Lg.singleValue = 90; + + let linkables = Session.getInstance().getLinkableValues(nub3.section.prms.Q); + let found = false; + for (const l of linkables) { + found = (l.nub === nub2) && (l.symbol === "Q"); + } + expect(found).toBe(true); + + nub3.section.prms.Q.defineReference(nub2, "Q"); + expect(nub3.section.prms.Q.valueMode).toBe(ParamValueMode.LINK); + expect(nub3.section.prms.Q.hasMultipleValues).toBe(false); + + prm2.Lg.setValues(80, 120, 1.5); + + linkables = Session.getInstance().getLinkableValues(nub3.section.prms.Q); + found = false; + for (const l of linkables) { + found = (l.nub === nub2) && (l.symbol === "Q"); + } + expect(found).toBe(false); + }); }); diff --git a/src/nub.ts b/src/nub.ts index a5a9f70d2c96705222a82f24c03e07ccfdbc2e70..a193598e5e7732122cc3cd05a153f85cb2d9b765 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -560,26 +560,30 @@ export abstract class Nub extends ComputeNode implements IObservable { (p.symbol === symbol && this.calcType === src.nubCalcType) || (p.family !== undefined && (p.family === src.family)) ) { - // if it is safe to link p's value to src - if (p.isLinkableTo(src)) { - // if p is a CALC param of a Structure other than "Q" - // (structures always have Q as CALC param and cannot have another) - // or a CALC param of a Section, that is not sibling of the target - // (to prevent circular dependencies among ParallelStructures), - // expose its parent - if ( - ( - (this instanceof Structure && p.symbol !== "Q" && ! this.isSiblingOf(src.nubUid)) - || this instanceof acSection - ) - && (p.valueMode === ParamValueMode.CALCUL) - ) { - // trick to expose p as a result of the parent Nub - res.push(new LinkedValue(this.parent, p, p.symbol)); - } else { - // do not suggest parameters that are already linked to another one - if (p.valueMode !== ParamValueMode.LINK) { - res.push(new LinkedValue(this, p, p.symbol)); + // if variability doesn't cause any problem (a non-variable + // parameter cannot be linked to a variating one) + if (src.calculability !== ParamCalculability.FIXED || ! p.hasMultipleValues) { + // if it is safe to link p's value to src + if (p.isLinkableTo(src)) { + // if p is a CALC param of a Structure other than "Q" + // (structures always have Q as CALC param and cannot have another) + // or a CALC param of a Section, that is not sibling of the target + // (to prevent circular dependencies among ParallelStructures), + // expose its parent + if ( + ( + (this instanceof Structure && p.symbol !== "Q" && ! this.isSiblingOf(src.nubUid)) + || this instanceof acSection + ) + && (p.valueMode === ParamValueMode.CALCUL) + ) { + // trick to expose p as a result of the parent Nub + res.push(new LinkedValue(this.parent, p, p.symbol)); + } else { + // do not suggest parameters that are already linked to another one + if (p.valueMode !== ParamValueMode.LINK) { + res.push(new LinkedValue(this, p, p.symbol)); + } } } } @@ -594,8 +598,14 @@ export abstract class Nub extends ComputeNode implements IObservable { // browse extra results for (const erSymbol of erk) { const erFamily = this._resultsFamilies[erSymbol]; - // if family is identical - if (erFamily === src.family) { + // if family is identical and variability doesn't cause any problem + if ( + erFamily === src.family + && ( + src.calculability !== ParamCalculability.FIXED + || ! this.resultHasMultipleValues + ) + ) { res.push(new LinkedValue(this, undefined, erSymbol)); } }