v2 / vlib / v / tests / interfaces / append_struct_to_interface_array_test.v
43 lines · 36 sloc · 622 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Vec {
2mut:
3 x f64
4 y f64
5 z f64
6}
7
8struct Plane {
9 position Vec
10 normal Vec
11}
12
13struct Sphere {
14 position Vec
15 radius f64
16}
17
18interface Object {
19 position Vec
20}
21
22fn test_append_struct_to_interface_array() {
23 mut scene := []Object{}
24
25 scene << Plane{
26 position: Vec{0, -10, 0}
27 normal: Vec{0, -1, 0}
28 }
29 scene << Sphere{
30 position: Vec{0, 0, -20}
31 radius: 7
32 }
33
34 println(scene)
35
36 assert scene.len == 2
37 assert scene[0].position.x == 0
38 assert scene[0].position.y == -10
39 assert scene[0].position.z == 0
40 assert scene[1].position.x == 0
41 assert scene[1].position.y == 0
42 assert scene[1].position.z == -20
43}
44