Skip to content

Commit

Permalink
standard
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhhai committed Jun 19, 2015
1 parent 3712db3 commit 4c56f8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ function calcPrefix (exp) {
args.push(o)
o = stack.pop()
}
var rst = Math[token.substr(postfixer.MATH_EP.length)].apply(null, args)
stack.push(rst)
stack.push(Math[token.substr(postfixer.MATH_EP.length)].apply(null, args))
} else {
stack.push(token)
}
Expand Down Expand Up @@ -75,8 +74,7 @@ function calcPostfix (exp) {
o = stack.pop()
}
args.reverse()
var rst = Math[token.substr(0, token.length - postfixer.MATH_EP.length)].apply(null, args)
stack.push(rst)
stack.push(Math[token.substr(0, token.length - postfixer.MATH_EP.length)].apply(null, args))
} else {
stack.push(token)
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"scripts": {
"start": "node cli.js",
"stop": "tape test/*.js | faucet",
"test": "standard && tape test/*.js | faucet"
},
"repository": {
Expand Down
20 changes: 20 additions & 0 deletions test/2-postfixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ test('infix to postfix test', function (t) {

t.end()
})

test('func: infix to postfix test', function (t) {
t.equal(postfixer('abs(1 - 2)'), '. 1 2 - abs.')
// t.equal(postfixer('1 + 2 * 3'), '1 2 3 * +')
// t.equal(postfixer('(1 + 2) * 3'), '1 2 + 3 *')
// t.equal(postfixer('(abs[1] + 2) * 3 + E'), 'abs[1] 2 + 3 * E +')
// t.equal(postfixer('(PI + 2) * 3 + E'), 'PI 2 + 3 * E +')
// t.equal(postfixer('(PI + 2/ 10) * 3 + (E-19 )'), 'PI 2 10 / + 3 * E 19 - +')
// t.equal(postfixer('(1 + 2 - 3*(PI + 10))'), '1 2 + 3 PI 10 + * -')
//
// t.equal(postfixer('1 + (-2)'), '1 -2 +')
// t.equal(postfixer('-1 + 2 + -3'), '-1 2 + -3 +')
// t.equal(postfixer('1 + - 2'), '1 -2 +')
// t.equal(postfixer('-1 + - 2'), '-1 -2 +')
// t.equal(postfixer('-1 - -3'), '-1 -3 -')
// t.equal(postfixer('|-1| - -3'), '|-1| -3 -')
// t.equal(postfixer('abs[-1] - -3'), 'abs[-1] -3 -')

t.end()
})

0 comments on commit 4c56f8f

Please sign in to comment.