Skip to content

Commit f751bdb

Browse files
committed
🚨 Fix tests related to random
1 parent 2da51d6 commit f751bdb

File tree

2 files changed

+65
-55
lines changed

2 files changed

+65
-55
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LinearAlgebra = "1.6"
2828
Mooncake = "0.4"
2929
Printf = "1.6"
3030
Random = "1.6"
31+
StableRNGs = "1"
3132
StaticArrays = "1"
3233
Test = "1.6"
3334
Zygote = "0.6"
@@ -37,7 +38,8 @@ julia = "1.10, 1.11"
3738
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
3839
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
3940
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
41+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
4042
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4143

4244
[targets]
43-
test = ["Test", "DifferentiationInterface", "FiniteDiff", "Mooncake", "Zygote"]
45+
test = ["Test", "DifferentiationInterface", "FiniteDiff", "Mooncake", "StableRNGs", "Zygote"]

test/random.jl

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,127 +4,135 @@
44
#
55
############################################################################################
66

7+
using StableRNGs
8+
9+
# Julia random number generator can change its output with the same seed accross minor
10+
# versions. Hence, we need to use StableRNGs.jl to ensure that the tests are consistent. For
11+
# more information, see:
12+
#
13+
# https://docs.julialang.org/en/v1/stdlib/Random/#Reproducibility
14+
715
# == File: ./src/random.jl =================================================================
816

917
@testset "DCM (Float64)" begin
1018
D_exp = DCM(
11-
0.1770772447942165,
12-
-0.24937398754945297,
13-
0.9520799670772275,
14-
-0.16371156336807055,
15-
-0.9613536278168439,
16-
-0.22135430039413143,
17-
0.9704855348719379,
18-
-0.11666969022448989,
19-
-0.21105925705178208
19+
-0.9855423399595813,
20+
0.1610947375575752,
21+
-0.05248601412042554,
22+
0.13225259369505987,
23+
0.9250801678356908,
24+
0.35599990805900494,
25+
0.10590348251083596,
26+
0.3439115709137256,
27+
-0.9330108701316029,
2028
)
2129

22-
D = rand(MersenneTwister(1986), DCM)
30+
D = rand(StableRNG(1986), DCM)
2331
@test D D_exp atol = 1e-15
2432

25-
D = rand(MersenneTwister(1986), DCM{Float64})
33+
D = rand(StableRNG(1986), DCM{Float64})
2634
@test D D_exp atol = 1e-15
2735
end
2836

2937
@testset "DCM (Float32)" begin
3038
D_exp = DCM(
31-
0.9071183f0,
32-
-0.38511035f0,
33-
0.1697833f0,
34-
-0.18077055f0,
35-
0.0077917147f0,
36-
0.98349446f0,
37-
-0.38007677f0,
38-
-0.9228377f0,
39-
-0.06254859f0
39+
0.13128565f0,
40+
0.6157909f0,
41+
0.77689487f0,
42+
-0.5353275f0,
43+
0.7036309f0,
44+
-0.4672559f0,
45+
-0.83437914f0,
46+
-0.35454917f0,
47+
0.4220264f0,
4048
)
4149

42-
D = rand(MersenneTwister(1986), DCM{Float32})
50+
D = rand(StableRNG(1986), DCM{Float32})
4351

4452
@test D D_exp atol = 1e-15
4553
end
4654

4755
@testset "Euler Angle and Axis (Float64)" begin
4856
aa_exp = EulerAngleAxis(
49-
3.0732832539795845,
57+
3.0607810768487105,
5058
@SVector [
51-
0.7668495688612252,
52-
-0.13482690249452656,
53-
0.6275057331220841
59+
-0.0748748188948659,
60+
-0.9810600691052008,
61+
-0.17864742456234697,
5462
]
5563
)
5664

57-
aa = rand(MersenneTwister(1986), EulerAngleAxis)
65+
aa = rand(StableRNG(1986), EulerAngleAxis)
5866
@test aa aa_exp atol = 1e-15
5967

60-
aa = rand(MersenneTwister(1986), EulerAngleAxis{Float64})
68+
aa = rand(StableRNG(1986), EulerAngleAxis{Float64})
6169
@test aa aa_exp atol = 1e-15
6270
end
6371

6472
@testset "Euler Angle and Axis (Float32)" begin
6573
aa_exp = EulerAngleAxis(
66-
1.6446829f0,
74+
1.4419688f0,
6775
@SVector [
68-
-0.9557738f0,
69-
0.2756822f0,
70-
0.102449425f0
76+
0.056824237f0,
77+
0.812369f0,
78+
-0.5803686f0,
7179
]
7280
)
7381

74-
aa = rand(MersenneTwister(1986), EulerAngleAxis{Float32})
82+
aa = rand(StableRNG(1986), EulerAngleAxis{Float32})
7583
@test aa aa_exp atol = 1e-15
7684
end
7785

7886
@testset "Euler Angles (Float64)" begin
7987
ea_exp = EulerAngles(
80-
2.5852880822263606,
81-
3.1861195131389626,
82-
2.9299487570635576,
83-
:YXY
88+
6.237765228608508,
89+
2.646507063149075,
90+
4.53226625968865,
91+
:YZY
8492
)
8593

86-
ea = rand(MersenneTwister(1986), EulerAngles)
94+
ea = rand(StableRNG(1986), EulerAngles)
8795
@test ea ea_exp atol = 1e-15
8896

89-
ea = rand(MersenneTwister(1986), EulerAngles{Float64})
97+
ea = rand(StableRNG(1986), EulerAngles{Float64})
9098
@test ea ea_exp atol = 1e-15
9199
end
92100

93101
@testset "Euler Angles (Float32)" begin
94102
ea_exp = EulerAngles(
95-
0.29179642f0,
96-
5.512145f0,
97-
4.3565836f0,
98-
:YXY
103+
2.7291467f0,
104+
1.5209f0,
105+
2.1911314f0,
106+
:YZY
99107
)
100108

101-
ea = rand(MersenneTwister(1986), EulerAngles{Float32})
109+
ea = rand(StableRNG(1986), EulerAngles{Float32})
102110
@test ea ea_exp atol = 1e-15
103111
end
104112

105113
@testset "Quaternion (Float64)" begin
106114
q_exp = Quaternion(
107-
-0.03414805970179898,
108-
-0.7664023306434491,
109-
0.1347482694144174,
110-
-0.6271397623279131
115+
0.04039479466622753,
116+
-0.07481370585716751,
117+
-0.9802593251184702,
118+
-0.17850161203213802,
111119
)
112120

113-
q = rand(MersenneTwister(1986), Quaternion)
121+
q = rand(StableRNG(1986), Quaternion)
114122
@test q q_exp atol = 1e-15
115123

116-
q = rand(MersenneTwister(1986), Quaternion{Float64})
124+
q = rand(StableRNG(1986), Quaternion{Float64})
117125
@test q q_exp atol = 1e-15
118126
end
119127

120128
@testset "Quaternion (Float32)" begin
121129
q_exp = Quaternion(
122-
-0.6805074f0,
123-
0.7003348f0,
124-
-0.2020037f0,
125-
-0.07506891f0
130+
0.7511563f0,
131+
0.037511066f0,
132+
0.5362646f0,
133+
-0.38311547f0,
126134
)
127135

128-
q = rand(MersenneTwister(1986), Quaternion{Float32})
136+
q = rand(StableRNG(1986), Quaternion{Float32})
129137
@test q q_exp atol = 1e-15
130138
end

0 commit comments

Comments
 (0)