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

Fix nghyd#325

add spec
parent a7736860
......@@ -135,6 +135,21 @@ describe("chained computation of linked Nubs : ", () => {
const r2 = res2.vCalc;
expect(r1).not.toBe(r2);
});
it("partial PAB chain, bug nghyd#325", () => {
// tslint:disable-next-line:max-line-length
const sess = `{ "header": { "source": "jalhyd", "format_version": "1.0", "created": "2019-07-30T08:24:10.711Z" }, "session": [ { "uid": "NjdmM3", "props": { "calcType": 12, "nodeType": 0 }, "meta": { "title": "PAB : chute" }, "children": [], "parameters": [ { "symbol": "Z1", "mode": "SINGLE", "value": 29.99 }, { "symbol": "Z2", "mode": "SINGLE", "value": 26.81 }, { "symbol": "DH", "mode": "CALCUL" } ] }, { "uid": "eWNjdG", "props": { "calcType": 13, "nodeType": 0 }, "meta": { "title": "PAB : nombre" }, "children": [], "parameters": [ { "symbol": "DHT", "mode": "LINK", "targetNub": "NjdmM3", "targetParam": "DH" }, { "symbol": "N", "mode": "SINGLE", "value": 14 }, { "symbol": "DH", "mode": "CALCUL" } ] }, { "uid": "dXM4em", "props": { "calcType": 6, "nodeType": 0 }, "meta": { "title": "PAB : puissance" }, "children": [], "parameters": [ { "symbol": "DH", "mode": "LINK", "targetNub": "eWNjdG", "targetParam": "DH" }, { "symbol": "Q", "mode": "SINGLE", "value": 2.8 }, { "symbol": "V", "mode": "CALCUL" }, { "symbol": "PV", "mode": "SINGLE", "value": 140 } ] }, { "uid": "bzNlaX", "props": { "calcType": 5, "nodeType": 0 }, "meta": { "title": "PAB : dimensions" }, "children": [], "parameters": [ { "symbol": "L", "mode": "SINGLE", "value": 5 }, { "symbol": "W", "mode": "SINGLE", "value": 5 }, { "symbol": "Y", "mode": "CALCUL" }, { "symbol": "V", "mode": "LINK", "targetNub": "dXM4em", "targetParam": "V" } ] }, { "uid": "eG9nM2", "props": { "calcType": 10, "nodeType": 0 }, "meta": { "title": "Cloisons" }, "children": [ { "uid": "ZjMxYT", "props": { "calcType": 7, "nodeType": 5, "structureType": 0, "loiDebit": 11 }, "children": [], "parameters": [ { "symbol": "h1", "mode": "CALCUL" }, { "symbol": "L", "mode": "SINGLE", "value": 0.9 } ] } ], "parameters": [ { "symbol": "Q", "mode": "SINGLE", "value": 2.8 }, { "symbol": "Z1", "mode": "LINK", "targetNub": "NjdmM3", "targetParam": "Z1" }, { "symbol": "LB", "mode": "LINK", "targetNub": "bzNlaX", "targetParam": "L" }, { "symbol": "BB", "mode": "LINK", "targetNub": "bzNlaX", "targetParam": "W" }, { "symbol": "PB", "mode": "LINK", "targetNub": "bzNlaX", "targetParam": "Y" }, { "symbol": "DH", "mode": "LINK", "targetNub": "eWNjdG", "targetParam": "DH" } ] } ] }`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
// calc partial chain from PAB-Dimensions
const pabDim = Session.getInstance().findNubByUid("bzNlaX");
pabDim.CalcSerie();
expect(pabDim.result.vCalc).toBeDefined();
// calc complete chain from Cloisons
const cloisons = Session.getInstance().findNubByUid("eG9nM2");
cloisons.CalcSerie();
expect(cloisons.result.vCalc).toBeDefined();
});
});
describe("failure in calc chain", () => {
......
......@@ -726,7 +726,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
* be calculated). Used to trigger chain calculation.
*/
public getRequiredNubs(visited: string[] = []): Nub[] {
const requiredNubs: Nub[] = [];
let requiredNubs: Nub[] = [];
// prevent loops
if (! visited.includes(this.uid)) {
visited.push(this.uid);
......@@ -743,7 +743,29 @@ export abstract class Nub extends ComputeNode implements IObservable {
}
}
}
return requiredNubs;
// 1. deduplicate
requiredNubs = requiredNubs.filter(
(element, index, self) => self.findIndex((e) => e.uid === element.uid) === index
);
// 2. only keep requiredNubs that are not dependencies of others
const realRequiredNubs: Nub[] = [];
for (const rn of requiredNubs) {
let keep = true;
// test all combinations
for (const rn2 of requiredNubs) {
if (rn.uid !== rn2.uid) {
keep = (
keep
&& ! rn2.dependsOnNubResult(rn, true)
);
}
}
if (keep) {
realRequiredNubs.push(rn);
}
}
return realRequiredNubs;
}
/**
......
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