parent
164a0528f0
commit
9a2495c874
@ -1,2 +0,0 @@
|
|||||||
// The Swift Programming Language
|
|
||||||
// https://docs.swift.org/swift-book
|
|
@ -0,0 +1,35 @@
|
|||||||
|
import Model
|
||||||
|
|
||||||
|
extension Piece: CustomStringConvertible {
|
||||||
|
public var description: String {
|
||||||
|
switch self {
|
||||||
|
case .PlayerA:
|
||||||
|
"🔴"
|
||||||
|
case .PlayerB:
|
||||||
|
"🟡"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Board: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
|
public var description: String {
|
||||||
|
var str = String()
|
||||||
|
|
||||||
|
for row in 0..<self.rows {
|
||||||
|
for col in 0..<self.columns {
|
||||||
|
str += self[col, row]?.description ?? " "
|
||||||
|
}
|
||||||
|
|
||||||
|
str += "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
public var debugDescription: String {
|
||||||
|
let (a, b) = self.countPieces()
|
||||||
|
return "Board[\(self.columns)x\(self.rows), \(a) A and \(b) B pieces]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
import XCTest
|
|
||||||
@testable import CustomTypes
|
|
||||||
|
|
||||||
final class CustomTypesTests: XCTestCase {
|
|
||||||
func testExample() throws {
|
|
||||||
// XCTest Documentation
|
|
||||||
// https://developer.apple.com/documentation/xctest
|
|
||||||
|
|
||||||
// Defining Test Cases and Test Methods
|
|
||||||
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
import XCTest
|
||||||
|
import Model
|
||||||
|
@testable import CustomTypes
|
||||||
|
|
||||||
|
final class CustomTypesTests: XCTestCase {
|
||||||
|
func testExample() throws {
|
||||||
|
guard var board = Board(columns: 4, rows: 4) else {
|
||||||
|
XCTFail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
board[1, 1] = .PlayerA
|
||||||
|
board[2, 1] = .PlayerA
|
||||||
|
board[2, 2] = .PlayerA
|
||||||
|
board[1, 2] = .PlayerB
|
||||||
|
|
||||||
|
let text: String = board.description
|
||||||
|
|
||||||
|
XCTAssertEqual(text, " \n 🔴🔴 \n 🟡🔴 \n \n")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue