From 6bc79c4fb9a3251a6c45932576c9c131c8c6efc3 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 3 Nov 2018 00:30:42 +0100 Subject: moved the files to the right dir --- structs_test.go | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 structs_test.go (limited to 'structs_test.go') 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) +} -- cgit 1.4.1