????????????
import Cocoa
class SimpleInterest: NSObject
{
func calculate(loanAmount: Double?? var interestRate: Double??years: Int) ->Double
{
interestRate = interestRate / 100.0
let interest = Double(years) * interestRate * loanAmount
return loanAmount + interest
}
func calculateAdd(num1: Double??num2: Double) ->Double
{
return num1 + num2
}
}
???????????:
import XCTest
import Cocoa
@testable import TestDemo
class TestDemoTests: XCTestCase {
var mySimpleInterestCaculator: SimpleInterest = SimpleInterest()
override func setUp() {
super.setUp()
print("starting test ")
print("?????????е???????????????????÷????????????????????????????????")
}
override func tearDown() {
print("end test")
print("?????????е??????????????????÷???????????????????????????? -???????????")
super.tearDown()
}
func testAdd()
{
let result = mySimpleInterestCaculator.calculateAdd(12?? num2: 12)
// accuracy ??? ?????
XCTAssertEqualWithAccuracy(result?? 24.01?? accuracy: 0.1?? "error: Unexpected result->(result)")
}
func testSimpleInterest() {
let result = mySimpleInterestCaculator.calculate(25_000?? interestRate: 0.08?? years: 10)
XCTAssertEqualWithAccuracy(result?? 25200?? accuracy: 0.1?? "error: Unexpected result->(result)")
}
}
???????????????????????в???!
??????????е????:
?????????????????в??????????????????????????ó?????????в??????
??????????? -- > target -> Build Phases --> Target Dependencies  : add dependency
???????? ????????????ó??????????????????α??????ó??????????????????в???! ????в???δ????????????????ó???