Skip to content

Commit

Permalink
add cover tests
Browse files Browse the repository at this point in the history
  • Loading branch information
li3zhen1 committed Oct 11, 2023
1 parent b790a94 commit fea3760
Showing 1 changed file with 65 additions and 8 deletions.
73 changes: 65 additions & 8 deletions Tests/QuadTreeTests/CoverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class CoverTests: XCTestCase {
// assert.deepStrictEqual(quadtree().cover(0, 0).cover(1, 2).extent(), [[0, 0], [4, 4]]);
// });
func testCoverNonTrivialExtent() {
let q = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:1, y:2)) {EmptyQuadDelegate()}
let q = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q.add(.new(), at: .init(x:1, y:2))
assert(q.quad ~= Quad(x0: 0, x1: 4, y0: 0, y1: 4))
}
Expand Down Expand Up @@ -53,25 +53,25 @@ final class CoverTests: XCTestCase {
// assert.deepStrictEqual(quadtree().cover(0, 0).cover(2, 2).cover(-3, 3).extent(), [[-4, 0], [4, 8]]);
// });
func testCoverDoubleExistingExtent() {
let q = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:1, y:2)) {EmptyQuadDelegate()}
let q = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q.add(.new(), at: (2,2))
q.add(.new(), at: (-1,-1))
assert(q.quad ~= Quad(x0: -4, x1: 4, y0: -4, y1: 4))

let q2 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:1, y:2)) {EmptyQuadDelegate()}
let q2 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q2.add(.new(), at: (2,2))
q2.add(.new(), at: (1,-1))
// assert(q2.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))
assert(q2.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))

let q3 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:1, y:2)) {EmptyQuadDelegate()}
let q3 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q3.add(.new(), at: (2,2))
q3.add(.new(), at: (3,-1))
// assert(q3.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))
assert(q3.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))

let q4 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:1, y:2)) {EmptyQuadDelegate()}
let q4 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q4.add(.new(), at: (2,2))
q4.add(.new(), at: (3,1))
// assert(q4.quad ~= Quad(x0: 0, x1: 4, y0: 0, y1: 4))
assert(q4.quad ~= Quad(x0: 0, x1: 4, y0: 0, y1: 4))
}


Expand All @@ -89,6 +89,63 @@ final class CoverTests: XCTestCase {
// assert.deepStrictEqual(q.copy().cover(5, -3).root(), [,, [{data: [0, 0]},,, {data: [2, 2]}],, ]);
// assert.deepStrictEqual(q.copy().cover(-3, -3).root(), [,,, [{data: [0, 0]},,, {data: [2, 2]}]]);
// });
func testCoverWrapRootNode() {
let q = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q.add(.new(), at: (0,0))
q.add(.new(), at: (2,2))
assert(q.quad ~= Quad(x0: 0, x1: 4, y0: 0, y1: 4))

let q2 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q2.add(.new(), at: (0,0))
q2.add(.new(), at: (2,2))
q2.add(.new(), at: (3,3))
assert(q2.quad ~= Quad(x0: 0, x1: 4, y0: 0, y1: 4))

let q3 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q3.add(.new(), at: (0,0))
q3.add(.new(), at: (2,2))
q3.add(.new(), at: (-1,3))
assert(q3.quad ~= Quad(x0: -4, x1: 4, y0: 0, y1: 8))

let q4 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q4.add(.new(), at: (0,0))
q4.add(.new(), at: (2,2))
q4.add(.new(), at: (3,-1))
assert(q4.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))

let q5 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q5.add(.new(), at: (0,0))
q5.add(.new(), at: (2,2))
q5.add(.new(), at: (-1,-1))
assert(q5.quad ~= Quad(x0: -4, x1: 4, y0: -4, y1: 4))

let q6 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q6.add(.new(), at: (0,0))
q6.add(.new(), at: (2,2))
q6.add(.new(), at: (5,5))
assert(q6.quad ~= Quad(x0: 0, x1: 8, y0: 0, y1: 8))

let q7 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q7.add(.new(), at: (0,0))
q7.add(.new(), at: (2,2))
q7.add(.new(), at: (-3,5))
assert(q7.quad ~= Quad(x0: -4, x1: 4, y0: 0, y1: 8))


let q8 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q8.add(.new(), at: (0,0))
q8.add(.new(), at: (2,2))
q8.add(.new(), at: (5,-3))
assert(q8.quad ~= Quad(x0: 0, x1: 8, y0: -4, y1: 4))


let q9 = QuadTree2.create(startingWith: IdNode.new(), at: .init(x:0, y:0)) {EmptyQuadDelegate()}
q9.add(.new(), at: (0,0))
q9.add(.new(), at: (2,2))
q9.add(.new(), at: (-3,-3))
assert(q9.quad ~= Quad(x0: -4, x1: 4, y0: -4, y1: 4))

}


// it("quadtree.cover(x, y) does not wrap the root node if it is a leaf", () => {
Expand Down

0 comments on commit fea3760

Please sign in to comment.