infix-to-postfix-notation
Version:
A wonderful tool which converts expressions in infix notation to postfix notation using recursion.
17 lines (15 loc) • 1.2 kB
JavaScript
var assert = require("assert"),
PostfixNotationConverter = require("../src/PostfixNotationConverter.js");
describe("convertToPostfixNotation()", function () {
it("should convert the infix notation to the postfix notation", function () {
assert.equal("1", PostfixNotationConverter.convertToPostfixNotation("1"));
assert.equal("1991", PostfixNotationConverter.convertToPostfixNotation("1991"));
assert.equal("", PostfixNotationConverter.convertToPostfixNotation("(((()()(()))()((()))))"));
assert.equal("12*34/+", PostfixNotationConverter.convertToPostfixNotation("((1*2)+(3/4))"));
assert.equal("123+*4/", PostfixNotationConverter.convertToPostfixNotation("((1*(2+3))/4)"));
assert.equal("1234/+*", PostfixNotationConverter.convertToPostfixNotation("(1*(2+(3/4)))"));
assert.equal("512+4*+3-", PostfixNotationConverter.convertToPostfixNotation("5+((1+2)*4)-3"));
assert.equal("534*12*12*34+++", PostfixNotationConverter.convertToPostfixNotation("5+(3*4*12*12+(3+4))"));
assert.equal("5112*56*12*45*84*124*++24*-*3-", PostfixNotationConverter.convertToPostfixNotation("5*(1+(1*2*56*12*45*84+(12*4))-(2*4))-3"));
});
});