From 84f378f654f7f90f18bbb5c580bcb6c37bbf97f8 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 22 Jan 2017 19:21:27 +0100 Subject: [PATCH] comment a test --- dist/lindenmayer.browser.js | 17 +++++++++++------ dist/lindenmayer.es.js | 17 +++++++++++------ dist/lindenmayer.js | 17 +++++++++++------ docs/examples/lindenmayer.js | 17 +++++++++++------ lindenmayer.js | 18 ++++++++++-------- test/tests.js | 9 +++++---- 6 files changed, 59 insertions(+), 36 deletions(-) diff --git a/dist/lindenmayer.browser.js b/dist/lindenmayer.browser.js index a643ddf..e13ac5a 100644 --- a/dist/lindenmayer.browser.js +++ b/dist/lindenmayer.browser.js @@ -228,16 +228,20 @@ function LSystem(_ref) { if (allowAppendingMultiSuccessors === true && this.productions.has(symbol)) { var existingProduction = this.productions.get(symbol); + console.log('EXISTING ', symbol, ': ', existingProduction); + console.log('APPEND', symbol, ':', newProduction[1]); var singleSuccessor = existingProduction.successor; var multiSuccessors = existingProduction.successors; if (singleSuccessor && !multiSuccessors) { // replace existing prod with new obj and add previous successor as first elem // to new successors field. - existingProduction = { successors: [singleSuccessor] }; + existingProduction = { successors: [existingProduction] }; } existingProduction.successors.push(newProduction[1]); + this.productions.set(symbol, existingProduction); + console.log(this.productions); } else { this.productions.set(symbol, newProduction[1]); } @@ -296,7 +300,6 @@ function LSystem(_ref) { var recursive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; - var successor = p.successor; var contextSensitive = p.leftCtx !== undefined || p.rightCtx !== undefined; var conditional = p.condition !== undefined; var stochastic = false; @@ -363,7 +366,9 @@ function LSystem(_ref) { // last true is for recursiv call // TODO: refactor getProductionResult to use an object var _result = this.getProductionResult(_p, index, part, params, true); - + // console.log(part, p.successors); + // console.log(result); + // console.log("\n"); if (_result !== undefined && _result !== false) { result = _result; break; @@ -371,11 +376,11 @@ function LSystem(_ref) { } } // if successor is a function, execute function and append return value - else if (typeof successor === 'function') { + else if (typeof p.successor === 'function') { - result = successor({ index, currentAxiom: this.axiom, part, params }); + result = p.successor({ index, currentAxiom: this.axiom, part, params }); } else { - result = successor; + result = p.successor; } if (!result) { diff --git a/dist/lindenmayer.es.js b/dist/lindenmayer.es.js index 46274d6..8dfcc91 100644 --- a/dist/lindenmayer.es.js +++ b/dist/lindenmayer.es.js @@ -225,16 +225,20 @@ function LSystem(_ref) { if (allowAppendingMultiSuccessors === true && this.productions.has(symbol)) { var existingProduction = this.productions.get(symbol); + console.log('EXISTING ', symbol, ': ', existingProduction); + console.log('APPEND', symbol, ':', newProduction[1]); var singleSuccessor = existingProduction.successor; var multiSuccessors = existingProduction.successors; if (singleSuccessor && !multiSuccessors) { // replace existing prod with new obj and add previous successor as first elem // to new successors field. - existingProduction = { successors: [singleSuccessor] }; + existingProduction = { successors: [existingProduction] }; } existingProduction.successors.push(newProduction[1]); + this.productions.set(symbol, existingProduction); + console.log(this.productions); } else { this.productions.set(symbol, newProduction[1]); } @@ -293,7 +297,6 @@ function LSystem(_ref) { var recursive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; - var successor = p.successor; var contextSensitive = p.leftCtx !== undefined || p.rightCtx !== undefined; var conditional = p.condition !== undefined; var stochastic = false; @@ -360,7 +363,9 @@ function LSystem(_ref) { // last true is for recursiv call // TODO: refactor getProductionResult to use an object var _result = this.getProductionResult(_p, index, part, params, true); - + // console.log(part, p.successors); + // console.log(result); + // console.log("\n"); if (_result !== undefined && _result !== false) { result = _result; break; @@ -368,11 +373,11 @@ function LSystem(_ref) { } } // if successor is a function, execute function and append return value - else if (typeof successor === 'function') { + else if (typeof p.successor === 'function') { - result = successor({ index, currentAxiom: this.axiom, part, params }); + result = p.successor({ index, currentAxiom: this.axiom, part, params }); } else { - result = successor; + result = p.successor; } if (!result) { diff --git a/dist/lindenmayer.js b/dist/lindenmayer.js index 23dabe5..d6f18bb 100644 --- a/dist/lindenmayer.js +++ b/dist/lindenmayer.js @@ -227,16 +227,20 @@ function LSystem(_ref) { if (allowAppendingMultiSuccessors === true && this.productions.has(symbol)) { var existingProduction = this.productions.get(symbol); + console.log('EXISTING ', symbol, ': ', existingProduction); + console.log('APPEND', symbol, ':', newProduction[1]); var singleSuccessor = existingProduction.successor; var multiSuccessors = existingProduction.successors; if (singleSuccessor && !multiSuccessors) { // replace existing prod with new obj and add previous successor as first elem // to new successors field. - existingProduction = { successors: [singleSuccessor] }; + existingProduction = { successors: [existingProduction] }; } existingProduction.successors.push(newProduction[1]); + this.productions.set(symbol, existingProduction); + console.log(this.productions); } else { this.productions.set(symbol, newProduction[1]); } @@ -295,7 +299,6 @@ function LSystem(_ref) { var recursive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; - var successor = p.successor; var contextSensitive = p.leftCtx !== undefined || p.rightCtx !== undefined; var conditional = p.condition !== undefined; var stochastic = false; @@ -362,7 +365,9 @@ function LSystem(_ref) { // last true is for recursiv call // TODO: refactor getProductionResult to use an object var _result = this.getProductionResult(_p, index, part, params, true); - + // console.log(part, p.successors); + // console.log(result); + // console.log("\n"); if (_result !== undefined && _result !== false) { result = _result; break; @@ -370,11 +375,11 @@ function LSystem(_ref) { } } // if successor is a function, execute function and append return value - else if (typeof successor === 'function') { + else if (typeof p.successor === 'function') { - result = successor({ index, currentAxiom: this.axiom, part, params }); + result = p.successor({ index, currentAxiom: this.axiom, part, params }); } else { - result = successor; + result = p.successor; } if (!result) { diff --git a/docs/examples/lindenmayer.js b/docs/examples/lindenmayer.js index a643ddf..e13ac5a 100644 --- a/docs/examples/lindenmayer.js +++ b/docs/examples/lindenmayer.js @@ -228,16 +228,20 @@ function LSystem(_ref) { if (allowAppendingMultiSuccessors === true && this.productions.has(symbol)) { var existingProduction = this.productions.get(symbol); + console.log('EXISTING ', symbol, ': ', existingProduction); + console.log('APPEND', symbol, ':', newProduction[1]); var singleSuccessor = existingProduction.successor; var multiSuccessors = existingProduction.successors; if (singleSuccessor && !multiSuccessors) { // replace existing prod with new obj and add previous successor as first elem // to new successors field. - existingProduction = { successors: [singleSuccessor] }; + existingProduction = { successors: [existingProduction] }; } existingProduction.successors.push(newProduction[1]); + this.productions.set(symbol, existingProduction); + console.log(this.productions); } else { this.productions.set(symbol, newProduction[1]); } @@ -296,7 +300,6 @@ function LSystem(_ref) { var recursive = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; - var successor = p.successor; var contextSensitive = p.leftCtx !== undefined || p.rightCtx !== undefined; var conditional = p.condition !== undefined; var stochastic = false; @@ -363,7 +366,9 @@ function LSystem(_ref) { // last true is for recursiv call // TODO: refactor getProductionResult to use an object var _result = this.getProductionResult(_p, index, part, params, true); - + // console.log(part, p.successors); + // console.log(result); + // console.log("\n"); if (_result !== undefined && _result !== false) { result = _result; break; @@ -371,11 +376,11 @@ function LSystem(_ref) { } } // if successor is a function, execute function and append return value - else if (typeof successor === 'function') { + else if (typeof p.successor === 'function') { - result = successor({ index, currentAxiom: this.axiom, part, params }); + result = p.successor({ index, currentAxiom: this.axiom, part, params }); } else { - result = successor; + result = p.successor; } if (!result) { diff --git a/lindenmayer.js b/lindenmayer.js index 459240d..f17ac4f 100644 --- a/lindenmayer.js +++ b/lindenmayer.js @@ -70,7 +70,7 @@ export default function LSystem({axiom = '', productions, finals, branchSymbols= let symbol = newProduction[0]; if(allowAppendingMultiSuccessors === true && this.productions.has(symbol)) { - + let existingProduction = this.productions.get(symbol); let singleSuccessor = existingProduction.successor; let multiSuccessors = existingProduction.successors; @@ -78,9 +78,10 @@ export default function LSystem({axiom = '', productions, finals, branchSymbols= if(singleSuccessor && !multiSuccessors) { // replace existing prod with new obj and add previous successor as first elem // to new successors field. - existingProduction = {successors: [singleSuccessor]}; + existingProduction = {successors: [existingProduction]}; + } - existingProduction.successors.push(newProduction[1]); + existingProduction.successors.push(newProduction[1]); this.productions.set(symbol, existingProduction); } else { @@ -126,7 +127,6 @@ export default function LSystem({axiom = '', productions, finals, branchSymbols= //var hasWeight = el => el.weight !== undefined; this.getProductionResult = function (p, index, part, params, recursive = false) { - let successor = p.successor; let contextSensitive = (p.leftCtx !== undefined || p.rightCtx !== undefined); let conditional = p.condition !== undefined; let stochastic = false; @@ -182,7 +182,9 @@ export default function LSystem({axiom = '', productions, finals, branchSymbols= // last true is for recursiv call // TODO: refactor getProductionResult to use an object let _result = this.getProductionResult(_p, index, part, params, true); - + // console.log(part, p.successors); + // console.log(result); + // console.log("\n"); if (_result !== undefined && _result !== false) { result = _result; break; @@ -193,12 +195,12 @@ export default function LSystem({axiom = '', productions, finals, branchSymbols= } // if successor is a function, execute function and append return value - else if (typeof successor === 'function') { + else if (typeof p.successor === 'function') { - result = successor({index, currentAxiom: this.axiom, part, params}); + result = p.successor({index, currentAxiom: this.axiom, part, params}); } else { - result = successor; + result = p.successor; } if(!result) { diff --git a/test/tests.js b/test/tests.js index ccbf4a4..ea2888c 100644 --- a/test/tests.js +++ b/test/tests.js @@ -82,16 +82,18 @@ it('Classic context sensitive syntax should work.', function() { }); it('multiple CS production on the same base symbol should work.', function () { - // TODO to FIX: push individual prods of one symbo into successors instead of single successor + // ATTENTION: Objecert order is not preserved in JS Objects + // If you want to rely on the order you define productions + // eg. one fails one not, you should define the productions iteratively via + // setProduction + let cs_LSystemMulti = new LSystem({ axiom: 'ABCDEFGHI', productions: { - 'BC': 'N', 'AC': 'Y', 'AD': 'N', 'G>HIJ': 'N', 'G>HI': 'Y', - 'AC': 'N', 'A': 'Y' } @@ -249,7 +251,6 @@ describe('Final functions', function() { - describe('L-System with multiple successors in production', function () { it('lists in successors should work', function () { let cs_LSystemMulti = new LSystem({