Class: TheoryImplementation

Inherits:
Theory show all
Defined in:
lib/theory/TheoryImplementation.rb

Overview

Instances of this class are realised theorys. The theory variables have been replaced with values that generate valid ruby code.

Instance Attribute Summary collapse

Attributes inherited from Theory

#action, #dependents, #example_runtime_method, #results, #theory_id, #theory_instance_id

Instance Method Summary collapse

Methods inherited from Theory

#all_theory_variables, #components, #describe, #find_component, #has_result_structure?, #highest_theory_variable_id, #highlight, #identify_unchanged, #irrelevant?, load_theory, #map_to, #orphan_action_variables, #rewrite_permutations, #select_result_structure, #uniq_theory_variables, #write

Constructor Details

#initialize(dependents, action, results, mapping, accessor_values = {}) ⇒ TheoryImplementation

Returns a new instance of TheoryImplementation.

Parameters:

  • mapping

    The literal mapping indicating what variable should be converted to what literal value. val=9>,…

  • values


12
13
14
15
# File 'lib/theory/TheoryImplementation.rb', line 12

def initialize(dependents,action,results,mapping,accessor_values={})
  super(dependents,action,results)
  @mapping, @accessor_values = mapping, accessor_values
end

Instance Attribute Details

#accessor_valuesObject (readonly)

Returns the value of attribute accessor_values.



5
6
7
# File 'lib/theory/TheoryImplementation.rb', line 5

def accessor_values
  @accessor_values
end

#mappingObject (readonly)

Returns the value of attribute mapping.



5
6
7
# File 'lib/theory/TheoryImplementation.rb', line 5

def mapping
  @mapping
end

Instance Method Details

#copyObject



17
18
19
20
# File 'lib/theory/TheoryImplementation.rb', line 17

def copy
  #return TheoryImplementation.new(@dependents.copy, @action.copy, @results.copy,@mapping.copy)
   return Marshal.load(Marshal.dump(self))
end

#evaluate_dependent(dependent, runtime_method, test_cases) ⇒ Object

TODO If I remove the code from this method then tc_theory_implementation.rb still

passes all the tests!


59
60
61
62
63
64
# File 'lib/theory/TheoryImplementation.rb', line 59

def evaluate_dependent(dependent,runtime_method,test_cases)
  #dependent.statement.push(Parser.run('return true'))
  last_runtime_method = runtime_method.copy
  eval dependent.statement.write 
  return false
end

#leads_to?(result_description) ⇒ Boolean

Returns true if the result descript matches any of the results for this theory.

Parameters:

  • result_description

    A OpenStatement with an if statement inside e.g. if(runtime_method.all_pass?(test_cases)) end

Returns:



29
30
31
# File 'lib/theory/TheoryImplementation.rb', line 29

def leads_to?(result_description)
  @results.any? {|x| x.statement.write == result_description.write}
end

#meets_dependencies?(runtime_method, test_cases) ⇒ Boolean

Returns true if the implemeted theories pass given the given runtime method and test cases.

TODO There might be a bit of crossover between the TheoryResult validates?

method.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/theory/TheoryImplementation.rb', line 39

def meets_dependencies?(runtime_method,test_cases)
  
  self.dependents.collect {|y| y.copy}.each do |x|
    # TODO  I'm not sure there is much benefit in the ParametersContainer class
    begin
      unless evaluate_dependent(x,runtime_method.copy,test_cases)
        return false
      end
    rescue NoMethodError => e
      return false
    rescue StandardError => e
      return false
    end      
    
  end
  return true    

end