Class: QueenCheck::Testable
- Inherits:
-
Object
- Object
- QueenCheck::Testable
- Defined in:
- lib/queencheck/core.rb
Overview
QueenCheck Testable Object
Constant Summary collapse
- DEFAULT_TEST_COUNT =
100
- DEFAULT_RETRY_COUNT =
100
Instance Method Summary collapse
-
#assert(progress) ⇒ QueenCheck::Result
run assert.
-
#check(count = DEFAULT_TEST_COUNT) ⇒ QueenCheck::ResultReport
check assert.
-
#check_with_label(labels, count = DEFAULT_TEST_COUNT) ⇒ QueenCheck::ResultReport
check assert with label for report.
-
#initialize(*arbitraries, &assertion) ⇒ QueenCheck::Testable
constructor
New Testable instance.
-
#properties(progress, retry_count = DEFAULT_RETRY_COUNT) ⇒ Array<Object, Object ...>
Generated values.
Constructor Details
#initialize(*arbitraries, &assertion) ⇒ QueenCheck::Testable
Returns new Testable instance.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/queencheck/core.rb', line 18 def initialize(*arbitraries, &assertion) @arbitraries = arbitraries.map { | arbitrary | arb = ( if arbitrary.instance_of?(QueenCheck::Arbitrary) arbitrary.gen elsif arbitrary.instance_of?(QueenCheck::Gen) arbitrary else QueenCheck::Arbitrary(arbitrary) end ) raise TypeError, "Not Implemented Arbitrary or Gen: #{arbitrary}" if arb.nil? arb.instance_of?(QueenCheck::Arbitrary) ? arb.gen : arb } @assertion = assertion end |
Instance Method Details
#assert(progress) ⇒ QueenCheck::Result
run assert
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/queencheck/core.rb', line 89 def assert(progress) begin props = properties(progress) is_success = @assertion.call(*props) rescue => ex is_success = false exception = ex end QueenCheck::Result.new(props, is_success, exception) end |
#check(count = DEFAULT_TEST_COUNT) ⇒ QueenCheck::ResultReport
check assert
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/queencheck/core.rb', line 40 def check(count = DEFAULT_TEST_COUNT) results = QueenCheck::ResultReport.new count.times do | n | begin results << self.assert(n.to_f / count) rescue QueenCheck::CanNotRetryMore next end end return results end |
#check_with_label(labels, count = DEFAULT_TEST_COUNT) ⇒ QueenCheck::ResultReport
check assert with label for report
61 62 63 64 65 66 67 |
# File 'lib/queencheck/core.rb', line 61 def check_with_label(labels, count = DEFAULT_TEST_COUNT) sets = check(count) labels.each_pair do | label, proc | sets.labeling(label, &proc) end return sets end |
#properties(progress, retry_count = DEFAULT_RETRY_COUNT) ⇒ Array<Object, Object ...>
Returns generated values.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/queencheck/core.rb', line 75 def properties(progress, retry_count = DEFAULT_RETRY_COUNT) @arbitraries.map { | gen | c = 0 until (v = gen.value(progress))[1] c += 1 raise QueenCheck::CanNotRetryMore, "can not retry generate: #{gen.inspect}" if c >= retry_count end v[0] } end |