Suppose I’m writing a calculator engine with a class as follows…

`public class ArithmeticExpression { ArithmeticExpression Add(double operand) { /* ... */ } ArithmeticExpression Subtract(double operand) { /* ... */ } // ... other useful operations like division, multiplication, etc. double ProduceResult() { /* ... */ } } `

… and the goal is to defer evaluation of the expression until `ProduceResullt()`

is called, so that correct order of all stacked operations is maintained.

### My question is:

How should I tackle with **unit testing this class** without getting overwhelmed by the number of combinations of method calls?

It is clear to me that the order of calls should be tested somehow, but writing tests like this:

`public void Multiply_CalledAfterAdd_TakesPrecedenceOverAdd() { // ... } public void Multiply_CalledAfterDivide_EvaluatesLeftToRight() { // ... } `

can get maddening and out of control quite quickly. And it’s not even about those 16 tests for the four basic arithmetic functions. Suppose in the future I decide to extend the calculator with a modulo operation – that’s 9 **almost identical** tests more to begin with.

On the other hand – the whole puprose of the class is to keep the order of operations maintained, so it’s got to be verified somehow.

Wrapping up – I know the example is trivial, but it’s a general problem that I struggle to find an answer to. Any help is appreciated, thanks.