Add the UITest to your project.
If you didn't create it when you created the project, you can add it by following the steps in the image below.
Write @testable import Swiswiswift
(Swiswiswift is the name of the project) so that you can refer to it in the test class.
By prefixing the function name with “test”, it can be executed as a test.
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
import UIKit | |
class FizzBuzz_20190127 { | |
class func fizzBuzz(num: Int) -> String { | |
if num % 15 == 0 { | |
return "FizzBuzz" | |
} else if num % 3 == 0 { | |
return "Fizz" | |
} else if num % 5 == 0 { | |
return "Buzz" | |
} else { | |
return "\(num)" | |
} | |
} | |
} |
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
import XCTest | |
@testable import Swiswiswift | |
class FizzBuzzTests_20190127: XCTestCase { | |
func testTreeMultiples() { | |
for treeMultiples in [3, 6, 9, 12, 18] { | |
let actual = FizzBuzz_20190127.fizzBuzz(num: treeMultiples) | |
XCTAssertEqual(actual, "Fizz") | |
} | |
} | |
func testFiveMultiples() { | |
for fiveMultiples in [5, 10, 20, 25, 50] { | |
let actual = FizzBuzz_20190127.fizzBuzz(num: fiveMultiples) | |
XCTAssertEqual(actual, "Buzz") | |
} | |
} | |
func testThreeAndFiveMultiples() { | |
for testThreeAndFiveMultiples in [15, 30, 45, 60, 75] { | |
let actual = FizzBuzz_20190127.fizzBuzz(num: testThreeAndFiveMultiples) | |
XCTAssertEqual(actual, "FizzBuzz") | |
} | |
} | |
} |