| 1 | module datatypes |
| 2 | |
| 3 | fn 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 | |
| 10 | fn 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 | |
| 24 | fn 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 | |
| 38 | fn 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 | |
| 55 | fn 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 | |
| 63 | fn 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 | |
| 71 | fn 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 | |