about summary refs log tree commit diff
path: root/structs_test.go
blob: 5b00aa5fca78263cb82caffbe229e4728b70294d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package quadtree

import (
	"fmt"
	"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)
}

// TestBoundingBox creates a bounding box
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)
}

func ExampleNewCoord() {
	fmt.Println(NewCoord(1, 1))
	// Output: {1, 1}
}