From b82c7e7e352061dccc3cb83a914092bd3677ac3f Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 3 Nov 2018 18:46:19 +0100 Subject: Updated the InsideOf test, now covering all possible cases! --- structs_test.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'structs_test.go') diff --git a/structs_test.go b/structs_test.go index d165364..5c8d59c 100644 --- a/structs_test.go +++ b/structs_test.go @@ -62,8 +62,16 @@ func TestBoundingBox(t *testing.T) { t.Log(newBoundingBox) } +// TestInsideOf runs multiple tests testing if a point is inside a bounding box +// All possible scenarios are simulated: +// 1. The Point is outside of the x-range +// 2. The Point is inside of the x-range, but outside of the y-range +// 3. The Point if inside the the x- and y-range +// The case where the point is inside of the y-range, but outsid eof the x-range +// does not need to be considered func TestInsideOf(t *testing.T) { - var testCoordinate = Coord{0, 0} + + // Define a QuadTree that will be used for all tests var testQuadTree = NewQuadtree(BoundingBox{ center: Coord{ x: 0, @@ -72,8 +80,20 @@ func TestInsideOf(t *testing.T) { halfDimension: 1, }, 0) - var isInsideOf = testCoordinate.InsideOf(testQuadTree) - t.Log(isInsideOf) + // Case 1: The point is outside of the x-range + var testCoordinateInX = Coord{10, 0} + var isInsideOfX = testCoordinateInX.InsideOf(testQuadTree) + t.Logf("%v is inside of %v: %t", testCoordinateInX, testQuadTree.boundary, isInsideOfX) + + // Case 2: The point is inside of the x-range, but outside of the y-range + var testCoordinateInXNotY = Coord{0.5, 10} + var isInsideOfXNotY = testCoordinateInXNotY.InsideOf(testQuadTree) + t.Logf("%v is inside of %v: %t", testCoordinateInXNotY, testQuadTree.boundary, isInsideOfXNotY) + + // Case 3: The point is inside of the x- and y-range + var testCoordinateInside = Coord{0, 0} + var isInsideOfInside = testCoordinateInside.InsideOf(testQuadTree) + t.Logf("%v is inside of %v: %t", testCoordinateInside, testQuadTree.boundary, isInsideOfInside) } // Test the NewBoundingBox function @@ -127,6 +147,10 @@ func TestInsert(t *testing.T) { t.Logf("Complete Tree: %v\n", newQuadtree.northEast.southWest.southWest.northEast) } +/*############################################################ + BEYOND THIS POINT: EXAMPLES +############################################################*/ + // The NewCoord function can be used to create a new Coordinate in the following way: func ExampleNewCoord() { fmt.Println(NewCoord(1, 1)) -- cgit 1.4.1