Alpha Chen 2 years ago
parent 22ef61b805
commit fb7c012f2c
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -3,4 +3,11 @@ require "minitest/test_task"
Minitest::TestTask.create(:test) Minitest::TestTask.create(:test)
namespace :test do
desc "Run tests on Ruby file changes"
task :watch do
sh "fd .*.rb | entr -d rake test"
end
end
task :default => :test task :default => :test

@ -46,7 +46,7 @@ module Minitest
prev_failure = database[name] prev_failure = database[name]
unless prev_failure.nil? if prev_failure
choices = prev_failure.unpack("Q>*") choices = prev_failure.unpack("Q>*")
state.test_function(TestCase.for_choices(choices)) state.test_function(TestCase.for_choices(choices))
end end
@ -101,12 +101,9 @@ module Minitest
# Return True with probability `p`. # Return True with probability `p`.
def weighted(p) def weighted(p)
if p.zero? || p.negative? result = if p <= 0 then forced_choice(0)
result = forced_choice(0) elsif p >= 1 then forced_choice(1)
elsif p >= 1 else make_choice(1) { (@random.rand <= p) ? 1 : 0 }
result = forced_choice(1)
else
result = make_choice(1) { (@random.rand <= p) ? 1 : 0 }
end end
puts "weighted(#{p}): #{result}" if should_print? puts "weighted(#{p}): #{result}" if should_print?
@ -118,7 +115,6 @@ module Minitest
# choice() had returned `n`. You almost never need this, but sometimes it # choice() had returned `n`. You almost never need this, but sometimes it
# can be a useful hint to the shrinker. # can be a useful hint to the shrinker.
def forced_choice(n) def forced_choice(n)
raise RangeError.new("Invalid choice #{n}") if n.bit_length > 64 || n.negative? raise RangeError.new("Invalid choice #{n}") if n.bit_length > 64 || n.negative?
raise Frozen unless @status.nil? raise Frozen unless @status.nil?

Loading…
Cancel
Save