diff --git a/test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl b/test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl index a36adbb..477c21b 100644 --- a/test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl +++ b/test/LieGroupsTestSuite.jl/LieGroupsTestSuite.jl @@ -13,7 +13,7 @@ The following functions are expected to be available, since their defaults just """ module LieGroupsTestSuite using LieGroups -using Test +using Test, Random # # @@ -559,6 +559,60 @@ function test_lie_bracket(G::LieGroup, X, Y; expected=missing, test_mutating::Bo end end +# +# +# --- R +""" + test_rand(G::LieGroup) + +Test the random function, both the allocating and the in-place variant, +as well as the variant with an `rng`, if one is provided. + +both the random point and the random tangent vector variants are tested. + +# Keyword arguments + +* `test_mutating::Bool=true`: test the mutating functions +* `rng=:missing`: test with a specific rng +""" +function test_rand( + G::LieGroup, g; test_mutating::Bool=true, rng::Union{Missing,AbstractRNG}=missing +) + @testset "rand" begin + g1 = rand(G) + @test is_point(G, g1) + if test_mutating + g2 = copy(G, g) + rand!(G, g2) + @test is_point(G, g2) + end + X1 = rand(G; vector_at=g1) + @test is_vector(G, g1, X1) + if test_mutating + X2 = zero_vector(LieAlgebra(G), g1) + rand!(G, X2; vector_at=g1) + @test is_vector(G, g1, X2) + end + if !ismissing(rng) + g1 = rand(rng, G) + @test is_point(G, g1) + if test_mutating + g2 = copy(G, g) + rand!(rng, G, g2) + @test is_point(G, g2) + end + X1 = rand(rng, G; vector_at=g1) + @test is_vector(G, g1, X1) + if test_mutating + X2 = zero_vector(LieAlgebra(G), g1) + rand!(rng, G, X2; vector_at=g1) + @test is_vector(G, g1, X2) + end + end + end + return nothing +end + # # # --- S @@ -594,6 +648,7 @@ Possible properties are * `:Vectors` is a vector of at least 3 elements from the Lie algebra `𝔤` og `G` * `:Mutating` is a boolean (`true` by default) whether to test the mutating variants of functions or not. * `:Name` is a name of the test. If not provided, defaults to `"\$G"` +* `:Rng` is a random number generator, if provided, the random functions are tested with this generator as well Possible `expectations` are @@ -705,6 +760,14 @@ function test_lie_group(G::LieGroup, properties::Dict, expectations::Dict=Dict() test_lie_bracket(G, vectors[1], vectors[2]; expected=v, test_mutating=mutating) end + # + # + # --- R + if (rand in functions) + v = get(properties, :Rng, missing) + test_rand(G, points[1]; rng=v, test_mutating=mutating) + end + # # # --- S diff --git a/test/groups/test_general_linear_group.jl b/test/groups/test_general_linear_group.jl index 8a003df..85d1193 100644 --- a/test/groups/test_general_linear_group.jl +++ b/test/groups/test_general_linear_group.jl @@ -1,4 +1,4 @@ -using LieGroups, Test +using LieGroups, Random, Test s = joinpath(@__DIR__, "..", "LieGroupsTestSuite.jl") !(s in LOAD_PATH) && (push!(LOAD_PATH, s)) @@ -12,6 +12,7 @@ begin :Name => "The general linear group", :Points => [g1, g2, g3], :Vectors => [X1, X2, X3], + :Rng => Random.MersenneTwister(), :Functions => [ compose, conjugate, @@ -26,6 +27,7 @@ begin is_identity, lie_bracket, log, + #rand, # requires a fix in Manifolds.jl to have rand on invertive matrices show, ], ) diff --git a/test/groups/test_translation_group.jl b/test/groups/test_translation_group.jl index 028fdb3..9eeaa2f 100644 --- a/test/groups/test_translation_group.jl +++ b/test/groups/test_translation_group.jl @@ -1,4 +1,4 @@ -using LieGroups, Test +using LieGroups, Random, Test s = joinpath(@__DIR__, "..", "LieGroupsTestSuite.jl") !(s in LOAD_PATH) && (push!(LOAD_PATH, s)) @@ -12,6 +12,7 @@ begin :Name => "The Translation group", :Points => [g1, g2, g3], :Vectors => [X1, X2, X3], + :Rng => Random.MersenneTwister(), :Functions => [ adjoint, compose, @@ -27,6 +28,7 @@ begin is_identity, lie_bracket, log, + rand, show, ], )