Class: Scientist::Result
- Inherits:
-
Object
- Object
- Scientist::Result
- Defined in:
- lib/scientist/result.rb
Overview
The immutable result of running an experiment.
Instance Attribute Summary collapse
-
#candidates ⇒ Object
readonly
An Array of candidate Observations.
-
#control ⇒ Object
readonly
The control Observation to which the rest are compared.
-
#experiment ⇒ Object
readonly
An Experiment.
-
#ignored ⇒ Object
readonly
An Array of observations which didn’t match the control, but were ignored.
-
#mismatched ⇒ Object
readonly
An Array of observations which didn’t match the control.
-
#observations ⇒ Object
readonly
An Array of Observations in execution order.
Instance Method Summary collapse
-
#context ⇒ Object
Public: the experiment’s context.
-
#evaluate_candidates ⇒ Object
Internal: evaluate the candidates to find mismatched and ignored results.
-
#experiment_name ⇒ Object
Public: the name of the experiment.
-
#ignored? ⇒ Boolean
Public: were there any ignored mismatches?.
-
#initialize(experiment, observations = [], control = nil) ⇒ Result
constructor
Internal: Create a new result.
-
#matched? ⇒ Boolean
Public: was the result a match between all behaviors?.
-
#mismatched? ⇒ Boolean
Public: were there mismatches in the behaviors?.
Constructor Details
#initialize(experiment, observations = [], control = nil) ⇒ Result
Internal: Create a new result.
experiment - the Experiment this result is for observations: - an Array of Observations, in execution order control: - the control Observation
28 29 30 31 32 33 34 35 36 |
# File 'lib/scientist/result.rb', line 28 def initialize(experiment, observations = [], control = nil) @experiment = experiment @observations = observations @control = control @candidates = observations - [control] evaluate_candidates freeze end |
Instance Attribute Details
#candidates ⇒ Object (readonly)
An Array of candidate Observations.
5 6 7 |
# File 'lib/scientist/result.rb', line 5 def candidates @candidates end |
#control ⇒ Object (readonly)
The control Observation to which the rest are compared.
8 9 10 |
# File 'lib/scientist/result.rb', line 8 def control @control end |
#experiment ⇒ Object (readonly)
An Experiment.
11 12 13 |
# File 'lib/scientist/result.rb', line 11 def experiment @experiment end |
#ignored ⇒ Object (readonly)
An Array of observations which didn’t match the control, but were ignored.
14 15 16 |
# File 'lib/scientist/result.rb', line 14 def ignored @ignored end |
#mismatched ⇒ Object (readonly)
An Array of observations which didn’t match the control.
17 18 19 |
# File 'lib/scientist/result.rb', line 17 def mismatched @mismatched end |
#observations ⇒ Object (readonly)
An Array of Observations in execution order.
20 21 22 |
# File 'lib/scientist/result.rb', line 20 def observations @observations end |
Instance Method Details
#context ⇒ Object
Public: the experiment’s context
39 40 41 |
# File 'lib/scientist/result.rb', line 39 def context experiment.context end |
#evaluate_candidates ⇒ Object
Internal: evaluate the candidates to find mismatched and ignored results
Sets @ignored and @mismatched with the ignored and mismatched candidates.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scientist/result.rb', line 66 def evaluate_candidates mismatched = candidates.reject do |candidate| experiment.observations_are_equivalent?(control, candidate) end @ignored = mismatched.select do |candidate| experiment.ignore_mismatched_observation? control, candidate end @mismatched = mismatched - @ignored end |
#experiment_name ⇒ Object
Public: the name of the experiment
44 45 46 |
# File 'lib/scientist/result.rb', line 44 def experiment_name experiment.name end |
#ignored? ⇒ Boolean
Public: were there any ignored mismatches?
59 60 61 |
# File 'lib/scientist/result.rb', line 59 def ignored? ignored.any? end |
#matched? ⇒ Boolean
Public: was the result a match between all behaviors?
49 50 51 |
# File 'lib/scientist/result.rb', line 49 def matched? mismatched.empty? && !ignored? end |
#mismatched? ⇒ Boolean
Public: were there mismatches in the behaviors?
54 55 56 |
# File 'lib/scientist/result.rb', line 54 def mismatched? mismatched.any? end |