Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
greater command
  • Loading branch information
benjaminplee committed Mar 25, 2010
1 parent 3058913 commit 4d10651
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
10 changes: 10 additions & 0 deletions QuickPietJS/lib/commands.js
Expand Up @@ -117,6 +117,16 @@ Commands = {

stack.push(stack.pop() == 0 ? 1 : 0)
},

greater : function(stack) {
this._enforce_min_stack_size(stack, 2)

stack.push(stack.pop() < stack.pop() ? 1 : 0)
},

end : function() {
return '_END_'
},

_enforce_non_empty_stack : function(stack) {
this._enforce_min_stack_size(stack, 1)
Expand Down
38 changes: 36 additions & 2 deletions QuickPietJS/spec/unit/commands.spec.js
Expand Up @@ -306,7 +306,7 @@ describe 'Commands'
stack.push(33)
end
it 'should pop top 2 values and remainder of their division (second top % top)'
it 'should pop top 2 values and push the remainder of their division (second top % top)'
Commands.mod(stack)
stack.should.eql [10, 2]
Expand Down Expand Up @@ -366,11 +366,45 @@ describe 'Commands'
end
describe 'greater'
it 'should pop top 2 values and push 1 if second-top is > top'
stack = [2, 5, 3]
Commands.greater(stack)
stack.should.eql [2, 1]
end
it 'should pop top 2 values and push 0 if second-top is <= top'
stack = [2, 3, 5]
Commands.greater(stack)
stack.should.eql [2, 0]
end
it 'should error if the stack is empty'
stack = []
-{ Commands.greater(stack) }.should.throw_error EvalError, 'Stack does not have enough values'
end
it 'should error if stack has only one value'
stack = [10]
-{ Commands.greater(stack) }.should.throw_error EvalError, 'Stack does not have enough values'
end
it 'should return undefined'
stack = [1, 2]
Commands.greater(stack).should.eql undefined
end
end
describe 'end'
it 'should return internal program end label'
Commands.end().should.eql '_END_'
end
end
describe 'goto'
Expand Down

0 comments on commit 4d10651

Please sign in to comment.