v / examples / pendulum-simulation / modules / sim / params_test.v
126 lines · 114 sloc · 2.8 KB · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1module sim
2
3import math
4
5const params_test_mock_params = SimParams{
6 rope_length: 0.25
7 bearing_mass: 0.03
8 magnet_spacing: 0.05
9 magnet_height: 0.03
10 magnet_strength: 10
11 gravity: 4.9
12}
13const params_test_mock_state = SimState{
14 position: vector(
15 x: -0.016957230930171364
16 y: -0.02937078552673521
17 z: 0.002311063475327252
18 )
19 velocity: vector(
20 x: -7.251158929833104
21 y: -12.559375680227724
22 z: -105.91539687686381
23 )
24 accel: vector(
25 x: -8.337034766251843e-11
26 y: -2.842170943040401e-10
27 z: 1.2126596023639044e-10
28 )
29}
30const params_test_mock_tetha = 2.0 * math.pi / 3.0
31
32pub fn test_get_rope_vector() {
33 result := params_test_mock_params.get_rope_vector(params_test_mock_state)
34 expected := vector(
35 x: -0.016957230930171364
36 y: -0.02937078552673521
37 z: -0.24768893652467275
38 )
39 assert result == expected
40}
41
42pub fn test_get_forces_sum() {
43 result := params_test_mock_params.get_forces_sum(params_test_mock_state)
44 expected := vector(
45 x: 3.410605131648481e-12
46 y: 5.229594535194337e-12
47 z: 9.094947017729282e-13
48 )
49 assert result == expected
50}
51
52pub fn test_get_grav_force() {
53 result := params_test_mock_params.get_grav_force(params_test_mock_state)
54 expected := vector(
55 z: -0.147
56 )
57 assert result == expected
58}
59
60pub fn test_get_magnet_position() {
61 result := params_test_mock_params.get_magnet_position(params_test_mock_tetha)
62 expected := vector(
63 x: -0.02499999999999999
64 y: 0.04330127018922194
65 z: -0.03
66 )
67 assert result == expected
68}
69
70pub fn test_get_magnet_force() {
71 result := params_test_mock_params.get_magnet_force(params_test_mock_tetha,
72 params_test_mock_state)
73 expected := vector(
74 x: -157.4572297692556
75 y: 1422.736432604726
76 z: -632.5695169850264
77 )
78 assert result == expected
79}
80
81pub fn test_get_magnet_dist() {
82 result := params_test_mock_params.get_magnet_dist(params_test_mock_tetha,
83 params_test_mock_state)
84 expected := 0.07993696666249227
85 assert result == expected
86}
87
88pub fn test_get_magnet1_force() {
89 result := params_test_mock_params.get_magnet1_force(params_test_mock_state)
90 expected := vector(
91 x: 1310.8545084099674
92 y: 575.0062553126633
93 z: -632.5695169850262
94 )
95 assert result == expected
96}
97
98pub fn test_get_magnet2_force() {
99 result := params_test_mock_params.get_magnet2_force(params_test_mock_state)
100 expected := vector(
101 x: -157.4572297692556
102 y: 1422.736432604726
103 z: -632.5695169850264
104 )
105 assert result == expected
106}
107
108pub fn test_get_magnet3_force() {
109 result := params_test_mock_params.get_magnet3_force(params_test_mock_state)
110 expected := vector(
111 x: -1710.46541088048
112 y: -2962.612996234165
113 z: -6871.632889552589
114 )
115 assert result == expected
116}
117
118pub fn test_get_tension_force() {
119 result := params_test_mock_params.get_tension_force(params_test_mock_state, vector(
120 x: 0.0
121 y: 0.0
122 z: 0.0
123 ))
124 expected := vector(x: 0.0, y: 0.0, z: 0.0)
125 assert result == expected
126}
127