Skip to content

celioyutaka/rpn-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPN-GO

Reverse Polish Notation or postfix notation, application to convert math expression to RPN with debugstep-by-step and solver using Golang

What it can do

Turn a math expression like

( 2 + 3 ) * 2 - 2 * 2 * 3

Into Reverse Polish Notation or postfix notation

2 3 + 2 * 2 2 * 3 * -

And solve it

-2

Debug, step-by-step how this app is converting

image image

How to use

Using go run

go run rpngo.go MATH_EXPRESSION [-d]

-d is for debug

Example 1

go run rpngo.go "10+9+9*(9+6)"

It will return 154

Example 2

go run rpngo.go "10+9+9*(9+6)" -d

It will return all debug info and entire stacking process

Testing

In the rpngo_test.go file there are some test cases, but it is still in progress

Add some test case

Example of test function TestSomeExpression() on file rpngo_test.go

{expression: "7+8", rpn_expression: "7 8 +", result: 15, isResultCorrect: true},

expression is the math expression

rpn_expression is the rpn (expected)

result is the result of this expression

isResultCorrect is a boolean to test a wrong result (use true when rpn_expression and result are OK)

Then, just run

go test -v

Releases

No releases published

Packages

No packages published

Languages