Skip to content

Commit

Permalink
use only non-overflowing length in test/random.jl
Browse files Browse the repository at this point in the history
After rebasing, the changes introduced by commit ea2bd4b are
incompatible with tests added in commit 4d1c138. The problem is that
now any array-like r can be passed to rand (not only ranges), and for
a random element to be picked out of r, a random integer in the range
1:length(r) is generated, and hence `length(r)` has to be a valid
integer (e.g. length(typemin(Int):typemax(Int)) yields OverflowError()).
  • Loading branch information
rfourquet committed Sep 30, 2014
1 parent d9814ff commit 38bef62
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ for T in (Int8, Uint8, Int16, Uint16, Int32, Uint32, Int64, Uint64, Int128, Uint
@test mod(r,2)==1

if T<:Integer && T!==Char
x = rand(typemin(T):typemax(T))
@test isa(x,T)
@test typemin(T) <= x <= typemax(T)
if T.size < Int.size
x = rand(typemin(T):typemax(T))
@test isa(x,T)
@test typemin(T) <= x <= typemax(T)
else # we bound the length of the range to typemax(T) so that there is no overflow
for (a, b) in ((typemin(T),typemin(T)+typemax(T)-one(T)),
(one(T),typemax(T)))
x = rand(a:b)
@test isa(x,T)
@test a <= x <= b
end
end
end
end

Expand Down

0 comments on commit 38bef62

Please sign in to comment.