Created
March 28, 2018 18:12
-
-
Save rtking1993/69f36da3602cc0bd95ade76ebabdbfa7 to your computer and use it in GitHub Desktop.
An XCTestCase class that tests the logic of calculator operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Frameworks | |
import XCTest | |
// MARK: CalculatorInteractorTests | |
class CalculatorInteractorTests: XCTestCase { | |
// MARK: Variables | |
var calculatorInteractor: CalculatorInteractor! | |
// MARK: Setup Methods | |
override func setUp() { | |
super.setUp() | |
calculatorInteractor = CalculatorInteractor() | |
} | |
// MARK: Addition Tests | |
func testAddition() { | |
let numberOne: Float = 4 | |
let numberTwo: Float = 9 | |
let result = calculatorInteractor.add(numberOne: numberOne, to: numberTwo) | |
XCTAssertEqual(result, 13) | |
} | |
func testAdditionNegative() { | |
let numberOne: Float = -3 | |
let numberTwo: Float = -6 | |
let result = calculatorInteractor.add(numberOne: numberOne, to: numberTwo) | |
XCTAssertEqual(result, -9) | |
} | |
// MARK: Subtraction Tests | |
func testSubtraction() { | |
let numberOne: Float = 9 | |
let numberTwo: Float = 4 | |
let result = calculatorInteractor.subtract(numberOne: numberOne, from: numberTwo) | |
XCTAssertEqual(result, -5) | |
} | |
func testSubtractionNegative() { | |
let numberOne: Float = -6 | |
let numberTwo: Float = -12 | |
let result = calculatorInteractor.subtract(numberOne: numberOne, from: numberTwo) | |
XCTAssertEqual(result, -6) | |
} | |
// MARK: Multiplication Tests | |
func testMultiplication() { | |
let numberOne: Float = 9 | |
let numberTwo: Float = 4 | |
let result = calculatorInteractor.multiply(numberOne: numberOne, by: numberTwo) | |
XCTAssertEqual(result, 36) | |
} | |
func testMultiplicationNegative() { | |
let numberOne: Float = -2 | |
let numberTwo: Float = -12 | |
let result = calculatorInteractor.multiply(numberOne: numberOne, by: numberTwo) | |
XCTAssertEqual(result, 24) | |
} | |
// MARK: Division Tests | |
func testDivision() { | |
let numberOne: Float = 28 | |
let numberTwo: Float = 2 | |
let result = calculatorInteractor.divide(numberOne: numberOne, by: numberTwo) | |
XCTAssertEqual(result, 14) | |
} | |
func testDivisionNegative() { | |
let numberOne: Float = -9 | |
let numberTwo: Float = -3 | |
let result = calculatorInteractor.divide(numberOne: numberOne, by: numberTwo) | |
XCTAssertEqual(result, 3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment