Exception: WithinAssay
- Inherits:
-
CompareAssay
- Object
- Exception
- Assertion
- CompareAssay
- WithinAssay
- Defined in:
- lib/assay/within_assay.rb
Constant Summary
Constants inherited from Assertion
Constants included from Assay::Assertable
Class Method Summary collapse
-
.assert_message(subject, criterion, delta) ⇒ Object
Failed assertion message.
-
.pass?(subject, criterion, delta) ⇒ Boolean
Check assertion.
Methods inherited from Assertion
by_name, by_operator, inherited, register, subclasses
Methods included from Assay::Assertable
#[], #assert!, #assert_message, #assertive_name, #assertor, #fail?, #operator, #pass?, #refute!, #refute_message
Class Method Details
.assert_message(subject, criterion, delta) ⇒ Object
Failed assertion message.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/assay/within_assay.rb', line 26 def self.(subject, criterion, delta) a = subject.inspect b = criterion.inspect d = delta.inspect if [a, b, d].any?{ |e| e.size > SIZE_LIMIT } "b - d <= a <= b + d\na) #{a}\nb) #{b}\nd) #{d}" else "#{b} - #{d} <= #{a} <= #{b} + #{d}" end end |
.pass?(subject, criterion, delta) ⇒ Boolean
Check assertion.
13 14 15 16 17 18 19 20 21 |
# File 'lib/assay/within_assay.rb', line 13 def self.pass?(subject, criterion, delta) if [subject, criterion, delta].all?{ |v| Numeric === v } a, b, d = subject.to_f, criterion.to_f, delta.to_f else a, b, d = subject, criterion, delta end (b - d) <= a && (b + d) >= a end |