Skip to content

Commit

Permalink
Make rand use in tests reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
lcw committed Jun 13, 2024
1 parent 8cb1636 commit 2173618
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
P4est = "7d669430-f675-4ae7-b43e-fab78ec5a902"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

Expand All @@ -15,5 +16,6 @@ MPIPreferences = "0.1"
P4est = "0.4.4"
Pkg = "1"
Preferences = "1"
StableRNGs = "1"
Test = "1"
UUIDs = "1"
9 changes: 6 additions & 3 deletions test/test_pxest.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MPI
using MPIPreferences
using P4estTypes
using StableRNGs
using Test

if haskey(ENV, "P4ESTTYPES_TEST_BINARY")
Expand All @@ -11,6 +12,8 @@ MPI.Init()

const comm = MPI.COMM_WORLD

const rng = StableRNG(37)

let
forest = pxest(brick(3, 4); comm)
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 12
Expand Down Expand Up @@ -40,7 +43,7 @@ let
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 24
partition!(forest)
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 24
partition!(forest; weight = (_...) -> rand((1, 2)))
partition!(forest; weight = (_...) -> rand(rng, (1, 2)))
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 24

@test_nowarn P4estTypes.savevtk("basicbrick", forest)
Expand Down Expand Up @@ -76,7 +79,7 @@ let
end

function foo_init(_, treeid, quadrant)
data = Foo(treeid, rand(Float64), rand(Float32))
data = Foo(treeid, rand(rng, Float64), rand(rng, Float32))
unsafe_storeuserdata!(quadrant, data)
@test unsafe_loaduserdata(quadrant, Foo) == data
end
Expand Down Expand Up @@ -106,7 +109,7 @@ let
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 64
partition!(forest)
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 64
partition!(forest; weight = (_...) -> rand((1, 2)))
partition!(forest; weight = (_...) -> rand(rng, (1, 2)))
@test MPI.Allreduce(sum(length.(forest)), +, comm) == 64

function replace(_, _, outgoing, incoming)
Expand Down

0 comments on commit 2173618

Please sign in to comment.