about summary refs log tree commit diff
path: root/structs_test.go
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-11-03 00:30:42 +0100
committerhanemile <hanemile@protonmail.com>2018-11-03 00:30:42 +0100
commit6bc79c4fb9a3251a6c45932576c9c131c8c6efc3 (patch)
treeea0b905209ab452212122db13659b12ddb55980b /structs_test.go
parent27dc10cef8fcd462e348bab8e499551f6634609f (diff)
moved the files to the right dir
Diffstat (limited to 'structs_test.go')
-rw-r--r--structs_test.go126
1 files changed, 126 insertions, 0 deletions
diff --git a/structs_test.go b/structs_test.go
new file mode 100644
index 0000000..66598bf
--- /dev/null
+++ b/structs_test.go
@@ -0,0 +1,126 @@
+package quadtree
+
+import (
+	"testing"
+)
+
+// Quadtree Test
+func TestQuadtree(t *testing.T) {
+	testQuadtree := quadtree{
+		nodeCapacity: 0,
+		boundary:     boundingBox{},
+		pointsSlice:  nil,
+		northWest:    nil,
+		northEast:    nil,
+		southWest:    nil,
+		southEast:    nil,
+	}
+
+	t.Log(testQuadtree)
+}
+
+// NewQuadTree test
+func TestNewQuadtree(t *testing.T) {
+	var boundary = boundingBox{
+		center:        Coord{0, 0},
+		halfDimension: 3,
+	}
+
+	var newQuadtree = *newQuadtree(boundary, 0)
+
+	t.Log(newQuadtree)
+}
+
+// Coordinate Test
+func TestCoord(t *testing.T) {
+	testCoord := Coord{
+		x: 0,
+		y: 1,
+	}
+
+	t.Log(testCoord)
+}
+
+// NewCoord test
+func TestNewCoord(t *testing.T) {
+	var newCoordinate = NewCoord(1, 2)
+
+	t.Log(newCoordinate)
+}
+
+func TestBoundingBox(t *testing.T) {
+	var newBoundingBox = boundingBox{
+		center: Coord{
+			x: 1,
+			y: 2,
+		},
+		halfDimension: 3,
+	}
+
+	t.Log(newBoundingBox)
+}
+
+func TestInsideOf(t *testing.T) {
+	var testCoordinate = Coord{0, 0}
+	var testQuadTree = newQuadtree(boundingBox{
+		center: Coord{
+			x: 0,
+			y: 0,
+		},
+		halfDimension: 1,
+	}, 0)
+
+	var isInsideOf = testCoordinate.insideOf(testQuadTree)
+	t.Log(isInsideOf)
+}
+
+// Test the newBoundingBox function
+func TestNewBoundingBox(t *testing.T) {
+
+	// Initialize some values that are needed
+	var newCenter = Coord{1, 2}
+	var newHalfDimension float64 = 3
+
+	// Initialize the bounding box using the values above
+	var newBoundingBox = newBoundingBox(newCenter, newHalfDimension)
+
+	// Print the newBoundingBox
+	t.Log(newBoundingBox)
+}
+
+func TestSubdivide(t *testing.T) {
+	var boundary = boundingBox{
+		center:        Coord{0, 0},
+		halfDimension: 3,
+	}
+
+	var newQuadtree = *newQuadtree(boundary, 0)
+
+	newQuadtree.subdivide()
+
+	t.Logf("newQuadTree: %v\n", newQuadtree)
+	t.Logf("NorthWestCell: %v\n", newQuadtree.northWest)
+	t.Logf("NorthEestCell: %v\n", newQuadtree.northEast)
+	t.Logf("SouthWestCell: %v\n", newQuadtree.southWest)
+	t.Logf("SouthEastCell: %v\n", newQuadtree.southEast)
+
+}
+
+// test the insert function
+func TestInsert(t *testing.T) {
+	// Define a new quadtree-root-boundary
+	var boundary = boundingBox{
+		center:        Coord{0, 0},
+		halfDimension: 3,
+	}
+
+	// create a new quadtree using the boundary
+	var newQuadtree = *newQuadtree(boundary, 0)
+
+	// Define a star and insert it into the quadtree
+	singleCoord := Coord{0.5, 0.5}
+	newQuadtree.insert(singleCoord)
+
+	// Print the stuff generated
+	t.Logf("Complete Tree: %v\n", newQuadtree.northEast.southWest.southWest.northEast)
+}