Swift?е???????
???????????? ???????[ 2015/12/31 11:02:46 ] ????????Swift ???????
????????????
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
???????? ????????????ó??????????????????α??????ó??????????????????в???! ????в???δ????????????????ó???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11