test/rantly_test.rb in rantly-1.1.0 vs test/rantly_test.rb in rantly-1.2.0
- old
+ new
@@ -55,10 +55,21 @@
it "generate Float" do
property_of { float }.check { |f| assert f.is_a?(Float)}
end
+ it "generate Float with normal distribution" do
+ property_of{
+ center = integer(100)
+ normal_points = Array.new(100){ float(:normal, { center: center }) }
+ [center, normal_points]
+ }.check{ |center, normal_points|
+ average_center = normal_points.reduce(0, :+) / 100
+ assert average_center.between?(center - 0.5, center + 0.5)
+ }
+ end
+
it "generate Boolean" do
property_of { boolean }.check { |t|
assert t == true || t == false
}
end
@@ -134,18 +145,18 @@
}.check { |o|
assert_equal true, o
}
property_of {
i0 = range(0,100)
- i1,s = call Proc.new {
+ i1 = call Proc.new {
range(i0+1,i0+100)
}
[i0,i1]
}.check { |(i0,i1)|
assert i0.is_a?(Fixnum) && i1.is_a?(Fixnum)
- assert i0 != i1
assert i1 > i0
+ assert i1 <= (i0 + 100)
}
end
it "raise if calling on any other value" do
assert_raises(RuntimeError) {
@@ -253,17 +264,10 @@
it "generate array with right types" do
property_of {
sized(10) { array { freq(:integer,:string,:float)} }
}.check { |arr|
- assert arr.all? { |o|
- case o
- when Fixnum, Float, String
- true
- else
- false
- end
- }
+ assert arr.all? { |o| [Fixnum, Float, String].include? o.class }
}
end
# it "raise if generating an array without size" do
# assert_raises(RuntimeError) {