Skip to content

Commit

Permalink
test/random.jl: segregate deterministic tests at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Sep 13, 2014
1 parent 753cd39 commit 2291a7e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/ccall
/ccalltest
/RANDOM_SEED.txt
37 changes: 26 additions & 11 deletions test/random.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Issue #6573
srand(0); rand(); x = rand(384);
@test find(x .== rand()) == []
## Non-deterministic tests
# deterministic tests (using srand) should go at the end of the file

using Base.Random.RANDOM_SEED

srand()
# bugs (failed tests) are still reproducible, provided that each test calls
# `rand` a deterministic (once global RNG state is known) number of times
# (e.g. not based on `time()`)
open("RANDOM_SEED.txt", "w") do f
println(f, RANDOM_SEED)
end

@test rand() != rand()
@test 0.0 <= rand() < 1.0
Expand Down Expand Up @@ -141,25 +150,25 @@ randmtzig_fill_ziggurat_tables()
@test all(we == Base.Random.we)
@test all(fe == Base.Random.fe)

#same random numbers on for small ranges on all systems

seed = rand(Uint) #leave state nondeterministic as above
srand(seed)
# same random numbers for small ranges on all systems

srand(RANDOM_SEED)
r = int64(rand(int32(97:122)))
srand(seed)
srand(RANDOM_SEED)
@test r == rand(int64(97:122))

srand(seed)
srand(RANDOM_SEED)
r = uint64(rand(uint32(97:122)))
srand(seed)
srand(RANDOM_SEED)
@test r == rand(uint64(97:122))

@test all([div(0x000100000000,k)*k - 1 == Base.Random.RandIntGen(uint64(1:k)).u for k in 13 .+ int64(2).^(1:30)])
@test all([div(0x000100000000,k)*k - 1 == Base.Random.RandIntGen(int64(1:k)).u for k in 13 .+ int64(2).^(1:30)])

import Base.Random: uuid4, UUID

# UUID
using Base.Random: uuid4, UUID

a = uuid4()
@test a == UUID(string(a)) == UUID(utf16(string(a))) == UUID(utf32(string(a)))
@test_throws ArgumentError UUID("550e8400e29b-41d4-a716-446655440000")
Expand All @@ -171,3 +180,9 @@ i8257 = 1:1/3:100
for i = 1:100
@test rand(i8257) in i8257
end

## Deterministic tests

# Issue #6573
srand(0); rand(); x = rand(384);
@test find(x .== rand()) == []

0 comments on commit 2291a7e

Please sign in to comment.