about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-11-03 18:46:19 +0100
committerhanemile <hanemile@protonmail.com>2018-11-03 18:46:19 +0100
commitb82c7e7e352061dccc3cb83a914092bd3677ac3f (patch)
tree62a7045cb94255c70ab418a6a9c56a1a288a11d4
parenta56d1134968de6b4867de24a1e8f15112a7e9554 (diff)
Updated the InsideOf test, now covering all possible cases!
-rw-r--r--structs_test.go30
1 files changed, 27 insertions, 3 deletions
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))