Exception: WithinAssay

Inherits:
CompareAssay show all
Defined in:
lib/assay/within_assay.rb

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Constants included from Assay::Assertable

Assay::Assertable::SIZE_LIMIT

Class Method Summary collapse

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.assert_message(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.

Returns:

  • (Boolean)


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