Tests for breadth first search
This commit is contained in:
parent
8d6c48466b
commit
48425d5cb8
2 changed files with 47 additions and 11 deletions
|
@ -14,7 +14,43 @@ public typealias Point = DiamondSquareAlgorithm.Box.Point
|
|||
public typealias Size = DiamondSquareAlgorithm.Box.Size
|
||||
|
||||
class DiamondSquareBFSTests: XCTestCase {
|
||||
func testBFS() {
|
||||
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||
var expectedBoxes: [Box] = [
|
||||
box,
|
||||
Box(origin: (x: 3, y: 4), size: (w: 3, h: 3)),
|
||||
Box(origin: (x: 6, y: 4), size: (w: 3, h: 3)),
|
||||
Box(origin: (x: 3, y: 7), size: (w: 3, h: 3)),
|
||||
Box(origin: (x: 6, y: 7), size: (w: 3, h: 3)),
|
||||
|
||||
Box(origin: (x: 3, y: 4), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 5, y: 4), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 3, y: 6), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 5, y: 6), size: (w: 2, h: 2)),
|
||||
|
||||
Box(origin: (x: 6, y: 4), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 8, y: 4), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 6, y: 6), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 8, y: 6), size: (w: 2, h: 2)),
|
||||
|
||||
Box(origin: (x: 3, y: 7), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 5, y: 7), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 3, y: 9), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 5, y: 9), size: (w: 2, h: 2)),
|
||||
|
||||
Box(origin: (x: 6, y: 7), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 8, y: 7), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 6, y: 9), size: (w: 2, h: 2)),
|
||||
Box(origin: (x: 8, y: 9), size: (w: 2, h: 2)),
|
||||
].reversed()
|
||||
|
||||
box.breadthFirstSearch { (box: Box) -> (Void) in
|
||||
let exBox = expectedBoxes.popLast()
|
||||
XCTAssertNotNil(exBox)
|
||||
XCTAssertEqual(box, exBox!)
|
||||
}
|
||||
XCTAssertEqual(expectedBoxes.count, 0)
|
||||
}
|
||||
}
|
||||
|
||||
class DiamondSquareBoxTests: XCTestCase {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue