Adding operations

We can now safely add the test for the operations, starting from the addition. Using the same trick, we create a TestCase called RpnCalculator_Operations, where we are going to assert that adding 1 and 2 gives us 3.00. Since the calculator is a Float calculator, the result must be 3.00:

class RpnCalculator_Operations: XCTestCase {    var rpnCalculator: RpnCalculator = FloatRpnCalculator()    func test__OneEnterTwoAdd__ThreeOnFirstPlace() {        rpnCalculator.new(element: "1")        rpnCalculator.new(element: "e")        rpnCalculator.new(element: "2")        rpnCalculator.new(element: "+")        XCTAssertEqual(rpnCalculator.line0, "3.00")    }}

The code used to make it pass is as follows:

func new(element: String) {    if element == "e" {        stack.push("") } else if ...

Get Hands-On Design Patterns with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.