Tests for side midpoints; move BFS test to BoxTests
This commit is contained in:
parent
48425d5cb8
commit
c62ae41fc0
1 changed files with 52 additions and 21 deletions
|
@ -13,7 +13,25 @@ public typealias Box = DiamondSquareAlgorithm.Box
|
||||||
public typealias Point = DiamondSquareAlgorithm.Box.Point
|
public typealias Point = DiamondSquareAlgorithm.Box.Point
|
||||||
public typealias Size = DiamondSquareAlgorithm.Box.Size
|
public typealias Size = DiamondSquareAlgorithm.Box.Size
|
||||||
|
|
||||||
class DiamondSquareBFSTests: XCTestCase {
|
class DiamondSquareBoxTests: XCTestCase {
|
||||||
|
|
||||||
|
func testMidpoint() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let midpoint = box.midpoint
|
||||||
|
XCTAssertEqual(midpoint.x, 6)
|
||||||
|
XCTAssertEqual(midpoint.y, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSubdivision() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let subdivs = box.subdivisions
|
||||||
|
XCTAssertEqual(subdivs.count, 4)
|
||||||
|
XCTAssertEqual(subdivs[0], Box(origin: (x: 3, y: 4), size: (w: 3, h: 3)))
|
||||||
|
XCTAssertEqual(subdivs[1], Box(origin: (x: 6, y: 4), size: (w: 3, h: 3)))
|
||||||
|
XCTAssertEqual(subdivs[2], Box(origin: (x: 3, y: 7), size: (w: 3, h: 3)))
|
||||||
|
XCTAssertEqual(subdivs[3], Box(origin: (x: 6, y: 7), size: (w: 3, h: 3)))
|
||||||
|
}
|
||||||
|
|
||||||
func testBFS() {
|
func testBFS() {
|
||||||
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
var expectedBoxes: [Box] = [
|
var expectedBoxes: [Box] = [
|
||||||
|
@ -42,7 +60,7 @@ class DiamondSquareBFSTests: XCTestCase {
|
||||||
Box(origin: (x: 8, 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: 6, y: 9), size: (w: 2, h: 2)),
|
||||||
Box(origin: (x: 8, y: 9), size: (w: 2, h: 2)),
|
Box(origin: (x: 8, y: 9), size: (w: 2, h: 2)),
|
||||||
].reversed()
|
].reversed()
|
||||||
|
|
||||||
box.breadthFirstSearch { (box: Box) -> (Void) in
|
box.breadthFirstSearch { (box: Box) -> (Void) in
|
||||||
let exBox = expectedBoxes.popLast()
|
let exBox = expectedBoxes.popLast()
|
||||||
|
@ -51,9 +69,39 @@ class DiamondSquareBFSTests: XCTestCase {
|
||||||
}
|
}
|
||||||
XCTAssertEqual(expectedBoxes.count, 0)
|
XCTAssertEqual(expectedBoxes.count, 0)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class DiamondSquareBoxTests: XCTestCase {
|
// MARK: Sides
|
||||||
|
|
||||||
|
func testNorth() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let pt = box.north
|
||||||
|
XCTAssertEqual(pt.x, 6)
|
||||||
|
XCTAssertEqual(pt.y, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testWest() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let pt = box.west
|
||||||
|
XCTAssertEqual(pt.x, 3)
|
||||||
|
XCTAssertEqual(pt.y, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSouth() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let pt = box.south
|
||||||
|
XCTAssertEqual(pt.x, 6)
|
||||||
|
XCTAssertEqual(pt.y, 9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEast() {
|
||||||
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
|
let pt = box.east
|
||||||
|
XCTAssertEqual(pt.x, 8)
|
||||||
|
XCTAssertEqual(pt.y, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Corners
|
||||||
|
|
||||||
func testNorthwest() {
|
func testNorthwest() {
|
||||||
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
||||||
let pt = box.northwest
|
let pt = box.northwest
|
||||||
|
@ -81,21 +129,4 @@ class DiamondSquareBoxTests: XCTestCase {
|
||||||
XCTAssertEqual(pt.x, 8)
|
XCTAssertEqual(pt.x, 8)
|
||||||
XCTAssertEqual(pt.y, 9)
|
XCTAssertEqual(pt.y, 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMidpoint() {
|
|
||||||
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
|
||||||
let midpoint = box.midpoint
|
|
||||||
XCTAssertEqual(midpoint.x, 6)
|
|
||||||
XCTAssertEqual(midpoint.y, 7)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSubdivision() {
|
|
||||||
let box = Box(origin: (x: 3, y: 4), size: (w: 5, h: 5))
|
|
||||||
let subdivs = box.subdivisions
|
|
||||||
XCTAssertEqual(subdivs.count, 4)
|
|
||||||
XCTAssertEqual(subdivs[0], Box(origin: (x: 3, y: 4), size: (w: 3, h: 3)))
|
|
||||||
XCTAssertEqual(subdivs[1], Box(origin: (x: 6, y: 4), size: (w: 3, h: 3)))
|
|
||||||
XCTAssertEqual(subdivs[2], Box(origin: (x: 3, y: 7), size: (w: 3, h: 3)))
|
|
||||||
XCTAssertEqual(subdivs[3], Box(origin: (x: 6, y: 7), size: (w: 3, h: 3)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue