Skip to content

Commit

Permalink
Add test for using Integer seed in clugen()
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed Jun 2, 2024
1 parent ab565d0 commit 5307ffc
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions test/clugen.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023 Nuno Fachada and contributors
# Copyright (c) 2020-2024 Nuno Fachada and contributors
# Distributed under the MIT License (See accompanying file LICENSE or copy
# at http://opensource.org/licenses/MIT)

Expand Down Expand Up @@ -224,16 +224,15 @@
end

@testset """Reproducibility:
seed=$(Int(rng.seed[1]))
""" for rng in rngs[1:(end - 1)]
# Get a seed
seed = Int(rng.seed[1])
# Reseed PRNG, run clugen and get results
Random.seed!(seed)
r1 = @test_nowarn clugen(2, 4, 100, [1, 1], 0.01, [10, 10], 5, 1, 0.1)
seed=$(seed)
""" for seed in seeds[1:2], use_rng in (true, false)
local seed_or_rng::Union{Integer,AbstractRNG}
# Create a PRNG with the specified seed, run clugen and get results
seed_or_rng = use_rng ? MersenneTwister(seed) : seed
r1 = @test_nowarn clugen(2, 4, 100, [1, 1], 0.01, [10, 10], 5, 1, 0.1, rng=seed_or_rng)
# Do it again
Random.seed!(seed)
r2 = @test_nowarn clugen(2, 4, 100, [1, 1], 0.01, [10, 10], 5, 1, 0.1)
seed_or_rng = use_rng ? MersenneTwister(seed) : seed
r2 = @test_nowarn clugen(2, 4, 100, [1, 1], 0.01, [10, 10], 5, 1, 0.1, rng=seed_or_rng)
# Check that results are exactly the same
@test all(r1.points .== r2.points)
@test all(r1.clusters .== r2.clusters)
Expand Down

0 comments on commit 5307ffc

Please sign in to comment.