I have a function that I want to test in Swift. It has been generated using Coco/R. I have an input statement which I want to test if it provides the desired output using the generated code (Parser.swift).
I haven't tried anything out yet since I don't know where to start.
func Addition {
var x = input.a
var y = input.b
let z: Int?
z = x + y
return z
}
Expected Result: Input File: a = 10 b = 5 Output: 15
Open XCode , creat new PlayGround:
Then Try this:
import Foundation
struct InputFormat {
var a : Int
var b : Int
}
func addition(input: InputFormat) -> Int {
let x = input.a
let y = input.b
let z = x + y
return z
}
let input = InputFormat(a: 10, b: 5)
print(addition(input: input))
It was the nearest way to get your code into test. Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.