O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Requirement – single operations

So, the plan is to support add, subtract, multiply and divide operations. As explained in the kata presentation, in RPN the operator is located at the end of the expression.

That means a - b is represented as a b -, and the same applies to the other operators: addition +,  multiplication *,  and division /.

Let's add one of each of the supported operations to our tests:

@Testpublic void addOperationReturnsCorrectValue() {  assertThat(reversePolishNotation.compute("1 2 +")).isEqualTo(3);}@Testpublic void subtractOperationReturnsCorrectValue() {  assertThat(reversePolishNotation.compute("2 1 -")).isEqualTo(1);}@Testpublic void multiplyOperationReturnsCorrectValue() { assertThat(reversePolishNotation.compute("2 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required