From 000f1ca521b91029f2118f4896aa724af50475ff Mon Sep 17 00:00:00 2001 From: hanemile Date: Fri, 16 Nov 2018 14:05:33 +0100 Subject: Added some comments explaining what is being done --- quadtree_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/quadtree_test.go b/quadtree_test.go index e736515..12b76f7 100644 --- a/quadtree_test.go +++ b/quadtree_test.go @@ -5,20 +5,28 @@ import ( "testing" ) +// Test the NewCoord function func TestNewCoord(t *testing.T) { + + // create a struct storing the arguments that should be passed to the function type args struct { x float64 y float64 } + + // create a struct storing the test cases tests := []struct { name string args args want Coord }{ + // define the tests {"NewCoord both positive", args{1.0, 1.0}, Coord{1, 1}}, {"NewCoord both negative", args{-1.0, -1.0}, Coord{-1, -1}}, {"NewCoord both zero", args{0, 0}, Coord{0, 0}}, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := NewCoord(tt.args.x, tt.args.y); !reflect.DeepEqual(got, tt.want) { @@ -35,20 +43,27 @@ func BenchmarkNewCoord(b *testing.B) { } func TestNewBoundingBox(t *testing.T) { + + // create a struct storing the arguments that should be passed to the function type args struct { inCenter Coord inHalfDimension float64 } + + // create a struct storing the test cases tests := []struct { name string args args want BoundingBox }{ + // define the tests {"bounding positive", args{Coord{0, 0}, 5.0}, BoundingBox{Coord{0, 0}, 5.0}}, {"bounding negative", args{Coord{0, 0}, -5.0}, BoundingBox{Coord{0, 0}, -5.0}}, {"positive", args{Coord{3, 3}, 5.0}, BoundingBox{Coord{3, 3}, 5.0}}, {"negative", args{Coord{-3, -3}, 5.0}, BoundingBox{Coord{-3, -3}, 5.0}}, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := NewBoundingBox(tt.args.inCenter, tt.args.inHalfDimension); !reflect.DeepEqual(got, tt.want) { @@ -65,6 +80,8 @@ func BenchmarkNewBoundingBox(b *testing.B) { } func TestCoord_InsideOf(t *testing.T) { + + // create a struct storing the arguments that should be passed to the function type args struct { quadtreeCell *Quadtree } @@ -94,7 +111,7 @@ func TestCoord_InsideOf(t *testing.T) { args args want bool }{ - // Define the testcases + // define the tests {"point inside of the quadtree", &Coord{0, 0}, args{&quadtreeCell}, true}, {"point outside of the quadtree", &Coord{4, 4}, args{&quadtreeCell}, false}, } @@ -110,15 +127,20 @@ func TestCoord_InsideOf(t *testing.T) { } func TestNewQuadtree(t *testing.T) { + + // create a struct storing the arguments that should be passed to the function type args struct { boundary BoundingBox depth int } + + // create a struct storing the test cases tests := []struct { name string args args want *Quadtree }{ + // define the tests { name: "", args: args{ @@ -149,6 +171,8 @@ func TestNewQuadtree(t *testing.T) { }, }, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := NewQuadtree(tt.args.boundary, tt.args.depth); !reflect.DeepEqual(got, tt.want) { @@ -159,10 +183,13 @@ func TestNewQuadtree(t *testing.T) { } func TestQuadtree_subdivide(t *testing.T) { + + // create a struct storing the test cases tests := []struct { name string quadtree *Quadtree }{ + // define the tests { name: "Subdivide", quadtree: &Quadtree{ @@ -183,6 +210,8 @@ func TestQuadtree_subdivide(t *testing.T) { }, }, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.quadtree.subdivide() @@ -191,14 +220,19 @@ func TestQuadtree_subdivide(t *testing.T) { } func TestQuadtree_Insert(t *testing.T) { + + // create a struct storing the arguments that should be passed to the function type args struct { point Coord } + + // create a struct storing the test cases tests := []struct { name string quadtree *Quadtree args args }{ + // define the tests { name: "", quadtree: &Quadtree{ @@ -300,6 +334,8 @@ func TestQuadtree_Insert(t *testing.T) { }, }, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.quadtree.Insert(tt.args.point) @@ -309,10 +345,13 @@ func TestQuadtree_Insert(t *testing.T) { } func TestQuadtree_Print(t *testing.T) { + + // create a struct storing the test cases tests := []struct { name string quadtree *Quadtree }{ + // define the tests { name: "", quadtree: &Quadtree{ @@ -333,6 +372,8 @@ func TestQuadtree_Print(t *testing.T) { }, }, } + + // run the tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.quadtree.Print() -- cgit 1.4.1