Test Human, add validation to class
continuous-integration/drone/push Build is passing Details

main
Alexis Drai 2 years ago
parent 9559978dfe
commit 27c49e34a2

@ -7,6 +7,10 @@ public class Player {
init?(withId id: Int,
withName name: String){
guard(id >= 0
&& !(name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty))
else { return nil }
self.id = id
self.name = name
}

@ -0,0 +1,6 @@
import XCTest
import connect4_lib
final class BotTest: XCTestCase {
}

@ -0,0 +1,21 @@
import XCTest
import connect4_lib
final class GameTest: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
}

@ -0,0 +1,32 @@
import XCTest
import connect4_lib
final class HumanTest: XCTestCase {
func scan() -> Int {
return 0
}
func testInit() throws {
func expect(initHumanWithId id: Int,
andName name: String,
andScanner scanner: @escaping () -> Int,
shouldNotBeNil: Bool) {
let human = Human(withId: id, withName: name, usingScanner: scanner)
if !shouldNotBeNil {
XCTAssertNil(human)
return
}
XCTAssertNotNil(human)
XCTAssertEqual(id, human?.id)
XCTAssertEqual(name, human?.name)
}
expect(initHumanWithId: 0, andName: "Bob", andScanner: scan, shouldNotBeNil: true)
expect(initHumanWithId: -1, andName: "Bob", andScanner: scan, shouldNotBeNil: false)
expect(initHumanWithId: 0, andName: "", andScanner: scan, shouldNotBeNil: false)
expect(initHumanWithId: 0, andName: " ", andScanner: scan, shouldNotBeNil: false)
}
//not testing for pebcak
}
Loading…
Cancel
Save