我是斯威夫特的新手,我似乎无法知道我做错了什么。
我的测试文件如下 - 类型的价值' ViewController'没有会员' averageIsAbove'
func testAverageIsAbove75(a: Double, b: Double, c: Double) {
XCTAssertFalse(testVC.averageIsAbove(a:76, b:75, c:71.9), "Average is below 75, it should return false." )
MViewController文件将此作为函数:
func averageIsAbove75(a: Double, b: Double, c: Double) -> Bool{
if (a * b * c) / 3 > 75 {
return true
}
else {
return false
}
}
答案 0 :(得分:0)
首先,您需要让每个人都能使用该方法。在关键字class
之前添加func
,以便在ViewController类中添加。{/ p>
接下来,您正在调用testAverageIsAbove
,但您的函数名为averageIsAbove75
。尝试更改以下内容:
XCTAssertFalse(testVC.averageIsAbove(a:76, b:75, c:71.9), "Average is below 75, it should return false." )
对此:
XCTAssertFalse(testVC.averageIsAbove75(a:76, b:75, c:71.9), "Average is below 75, it should return false." )
答案 1 :(得分:0)
class ViewController1 : UIViewController {
func testAverageIsAbove75(a: Double, b: Double, c: Double) {
XCTAssertFalse(ViewController2.averageIsAbove75(a:76, b:75, c:71.9), "Average is below 75, it should return false." )
}
}
class ViewController2 {
class func averageIsAbove75(a: Double, b: Double, c: Double) -> Bool{
if (a * b * c) / 3 > 75 {
return true
}
else {
return false
}
}
}