Skip to content

Commit

Permalink
perform factorial, with retursion, test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlopez committed Dec 24, 2012
1 parent 4a6959e commit 7d55040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/cobolscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ var cobolscript = (function() {
function IntegerExpression(text) { this.compile = function() { return text; }; }

function BinaryExpression(left, oper, right) {
if (oper == '=')
oper = '==';
else if (oper == '<>')
oper = '!=';

this.compile = function(program, context) {
return left.compile(program, context) + ' ' + oper + ' ' + right.compile(program.context);
}
Expand Down
12 changes: 12 additions & 0 deletions test/perform.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ run('perform procedure1 using k varying k from 1 to 4. procedure1 using x. add x
assert.equal(ws.a, 10);
assert.equal(ws.k, 5);

// perform with giving and return

var ws = { result: 0 };
run('perform procedure1 using 3 giving result. procedure1 using n. add 1 to n. return n.', ws);
assert.equal(ws.result, 4);

// perform factorial with auxiliary parameters

var ws = { result: 0 };
run('perform factorial using 3 giving result. factorial using n, m. if n = 1 then return n. subtract 1 from n giving m. perform factorial using m giving m. multiply n by m. return m.', ws);
assert.equal(ws.result, 6);

0 comments on commit 7d55040

Please sign in to comment.