Class: AnswerFactory::Machines::MutateCodeblock
- Defined in:
- lib/machines/mutate_codeblock.rb
Instance Attribute Summary
Attributes inherited from Machine
Instance Method Summary collapse
- #build(batch, overridden_options = {}) ⇒ Object (also: #generate)
Methods inherited from Machine
Constructor Details
This class inherits a constructor from AnswerFactory::Machines::Machine
Instance Method Details
#build(batch, overridden_options = {}) ⇒ Object Also known as: generate
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/machines/mutate_codeblock.rb', line 10 def build(batch, ={}) raise ArgumentError, "MutateCodeblock#build cannot process a #{batch.class}" unless batch.kind_of?(Batch) = @options.merge() replicates = [:replicates] || 1 result = Batch.new batch.each do |answer| replicates.times do which_point = rand(answer.points) + 1 size = [:size_preserving?] ? answer.program[which_point].points : Kernel.rand(2 * answer.program[which_point].points) + 1 new_code = NudgeType::CodeType.any_value(.merge({target_size_in_points:size})) mutated_code = answer.replace_point_or_clone(which_point, new_code) variant = Answer.new(mutated_code, progress:answer.progress + 1) result << variant end end return result end |