v2 / vlib / datatypes / quadtree_test.v
83 lines · 76 sloc · 1.48 KB · c51d30bf5309653c6b573ec815268e69a78ea8cc
Raw
1module datatypes
2
3fn test_create() {
4 mut qt := Quadtree{}
5 test := qt.create(0, 0, 1340, 640, 8, 4, 0)
6 test_clone := qt.create(0, 0, 1340, 640, 8, 4, 0)
7 assert test == test_clone
8}
9
10fn test_insert() {
11 mut qt := Quadtree{}
12 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
13 mut pt := AABB{
14 x: 100
15 y: 50
16 width: 60
17 height: 100
18 }
19 assert test.particles == []
20 test.insert(pt)
21 assert test.particles[0] == pt
22}
23
24fn test_retrieve() {
25 mut qt := Quadtree{}
26 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
27 mut pt := AABB{
28 x: 100
29 y: 50
30 width: 60
31 height: 100
32 }
33 test.insert(pt)
34 t := test.retrieve(pt)
35 assert t[0] == pt
36}
37
38fn test_clear() {
39 mut qt := Quadtree{}
40 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
41 mut test_clone := qt.create(0, 0, 1340, 640, 8, 4, 0)
42 mut pt := AABB{
43 x: 100
44 y: 50
45 width: 60
46 height: 100
47 }
48 test.split()
49 test.insert(pt)
50 assert test != test_clone
51 test.clear()
52 assert test == test_clone
53}
54
55fn test_get_nodes() {
56 mut qt := Quadtree{}
57 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
58 test.split()
59 t := test.get_nodes()
60 assert t.len == 4
61}
62
63fn test_split() {
64 mut qt := Quadtree{}
65 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
66 test.split()
67 t := test.get_nodes()
68 assert t.len == 4
69}
70
71fn test_get_index() {
72 mut qt := Quadtree{}
73 mut test := qt.create(0, 0, 1340, 640, 8, 4, 0)
74 mut pt := AABB{
75 x: 100
76 y: 50
77 width: 60
78 height: 100
79 }
80 test.particles << pt
81 t := test.get_index(pt)
82 assert t == [1]
83}
84