Class: Scientist::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/scientist/result.rb

Overview

The immutable result of running an experiment.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#candidatesObject (readonly)

An Array of candidate Observations.



5
6
7
# File 'lib/scientist/result.rb', line 5

def candidates
  @candidates
end

#controlObject (readonly)

The control Observation to which the rest are compared.



8
9
10
# File 'lib/scientist/result.rb', line 8

def control
  @control
end

#experimentObject (readonly)

An Experiment.



11
12
13
# File 'lib/scientist/result.rb', line 11

def experiment
  @experiment
end

#ignoredObject (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

#mismatchedObject (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

#observationsObject (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

#contextObject

Public: the experiment’s context



39
40
41
# File 'lib/scientist/result.rb', line 39

def context
  experiment.context
end

#evaluate_candidatesObject

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_nameObject

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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


54
55
56
# File 'lib/scientist/result.rb', line 54

def mismatched?
  mismatched.any?
end