Skip to content

Commit

Permalink
comment a test
Browse files Browse the repository at this point in the history
  • Loading branch information
nylki committed Jan 22, 2017
1 parent c3d7cc2 commit 84f378f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 36 deletions.
17 changes: 11 additions & 6 deletions dist/lindenmayer.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -363,19 +366,21 @@ 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;
}
}
}
// 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) {
Expand Down
17 changes: 11 additions & 6 deletions dist/lindenmayer.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -360,19 +363,21 @@ 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;
}
}
}
// 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) {
Expand Down
17 changes: 11 additions & 6 deletions dist/lindenmayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -362,19 +365,21 @@ 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;
}
}
}
// 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) {
Expand Down
17 changes: 11 additions & 6 deletions docs/examples/lindenmayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -363,19 +366,21 @@ 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;
}
}
}
// 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) {
Expand Down
18 changes: 10 additions & 8 deletions lindenmayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ 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;

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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
'B<B>C': 'N',
'A<B>C': 'Y',
'A<B>D': 'N',
'G>HIJ': 'N',
'G>HI': 'Y',
'A<A': 'N',
'A>C': 'N',
'A': 'Y'
}
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 84f378f

Please sign in to comment.