class Given::Fuzzy::FuzzyNumber

Constants

DEFAULT_EPSILON

Attributes

delta_amount[R]
exact_value[R]

Public Class Methods

new(exact_value) click to toggle source
   # File lib/given/fuzzy_number.rb
10 def initialize(exact_value)
11   @exact_value = exact_value
12   @delta_amount = exact_value * DEFAULT_EPSILON
13 end

Public Instance Methods

==(other) click to toggle source

True if the other number is in range of the fuzzy number.

   # File lib/given/fuzzy_number.rb
32 def ==(other)
33   (other - exact_value).abs <= delta_amount
34 end
delta(delta) click to toggle source

Set the delta for a fuzzy number.

   # File lib/given/fuzzy_number.rb
41 def delta(delta)
42   @delta_amount = delta.abs
43   self
44 end
epsilon(neps) click to toggle source

Specifying the number of epsilons to be used in setting the delta.

   # File lib/given/fuzzy_number.rb
54 def epsilon(neps)
55   delta(exact_value * (neps * Float::EPSILON))
56 end
exactly_equals?(other) click to toggle source
   # File lib/given/fuzzy_number.rb
15 def exactly_equals?(other)
16   other.is_a?(self.class) &&
17     exact_value == other.exact_value &&
18     delta_amount == other.delta_amount
19 end
high_limit() click to toggle source

High limit of the fuzzy number.

   # File lib/given/fuzzy_number.rb
27 def high_limit
28   exact_value + delta_amount
29 end
low_limit() click to toggle source

Low limit of the fuzzy number.

   # File lib/given/fuzzy_number.rb
22 def low_limit
23   exact_value - delta_amount
24 end
percent(percentage) click to toggle source

Specifying a percentage of the exact number to be used in setting the delta.

   # File lib/given/fuzzy_number.rb
48 def percent(percentage)
49   delta(exact_value * (percentage / 100.0))
50 end
to_s() click to toggle source
   # File lib/given/fuzzy_number.rb
36 def to_s
37   "<Approximately #{exact_value} +/- #{delta_amount}>"
38 end