Skip to content

Commit

Permalink
add shuffle test (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored Apr 1, 2021
1 parent 6154971 commit b5a5d93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The stable (guaranteed) API is
the mutating methods `rand!`, `randn!` and `randexp!`
* `rand(rng, ::AbstractArray)` (e.g. `rand(rng, 1:9)`); the streams are the same
on 32-bits and 64-bits architectures
* `shuffle(rng, ::AbstractArray)` and `shuffle!(rng, ::AbstractArray)`

Note that the generated streams of numbers for scalars and arrays are the same,
i.e. `rand(rng, X, n)` is equal to `[rand(rng, X) for _=1:n]` for a given `rng`
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,17 @@ end
end
end
end

@testset "`shuffle` stability" begin
a = 1:10
a_shuffled = [4, 5, 6, 1, 3, 7, 10, 2, 8, 9]

# If these tests fail due to changes in the algorithm used in `Random.shuffle`,
# we should vendor the old implementation here to keep it stable.
# See <https://github.com/JuliaRandom/StableRNGs.jl/issues/10>.
@test shuffle(StableRNG(10), a) == a_shuffled

b = collect(a)
shuffle!(StableRNG(10), b)
@test b == a_shuffled
end

0 comments on commit b5a5d93

Please sign in to comment.