Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Methods

Test the property ``prop``, with argument tpyes ``typs``, running ``ntests`` tests, and using the argument generators arggens. Each argument generator must be a function in a single positive integer which returns an item of the appropriate type which has "size" of the integer. This integer is used to scale the tests. This is a more efficient and flexible approach than conditional properties, but is sometimes harder to express::

julia> quantproperty((x::Int, y::Int)->(x/y)>=floor(x/y), 100, (size)->QuickCheck.generator(Int,size), (size)->randbool() ? rand(1:size) : rand(-size:1))
julia> quantproperty((x::Int, y::Int)->(x/y)>=floor(x/y), 100, (size)->QuickCheck.generator(Int,size), (size)->rand(Bool) ? rand(1:size) : rand(-size:1))
OK, passed 100 tests.

----------
Expand Down
13 changes: 9 additions & 4 deletions src/QuickCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export condproperty
export quantproperty

function lambda_arg_types(f::Function)
if !isa(f.code, LambdaStaticData)
if !isa(f, Function)
error("You must supply either an anonymous function with typed arguments or an array of argument types.")
end
[eval(var.args[2]) for var in Base.uncompressed_ast(f.code).args[1]]
# [eval(var.args[2]) for var in Base.uncompressed_ast(f.code).args[1]]
c = methods(f).ms
if length(c) != 1
error("The function must have one, and only one method.")
end
[c[1].sig.parameters[2:end]...]
end

# Simple properties
Expand Down Expand Up @@ -43,7 +48,7 @@ function check_property(prop::Function, arggens, argconds, ntests, maxtests)
totalTests = 0
for i in 1:ntests
goodargs = false
args = {}
args = []
while !goodargs
totalTests += 1
if totalTests > maxtests
Expand All @@ -63,7 +68,7 @@ end
# Default generators for primitive types
generator{T<:Unsigned}(::Type{T}, size) = convert(T, rand(1:size))
generator{T<:Signed}(::Type{T}, size) = convert(T, rand(-size:size))
generator{T<:FloatingPoint}(::Type{T}, size) = convert(T, (rand()-0.5).*size)
generator{T<:AbstractFloat}(::Type{T}, size) = convert(T, (rand()-0.5).*size)
# This won't generate interesting UTF-8, but doing that is a Hard Problem
generator{T<:String}(::Type{T}, size) = convert(T, randstring(size))

Expand Down