Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Forked from trek/DoBlendingCrossover.rb
Created October 28, 2010 15:41
Show Gist options
  • Save Vaguery/651617 to your computer and use it in GitHub Desktop.
Save Vaguery/651617 to your computer and use it in GitHub Desktop.
# encoding: UTF-8
class DoBlendingCrossover < Machine
def initialize
@number_to_create = 1
end
def create (n)
@number_to_create = n
end
def process_answers
created = []
answers_keyed_by_language.each do |language, group|
group.shuffle!.each_slice(2) do |a, b|
b = a unless b
blueprint_a = a.blueprint
blueprint_b = b.blueprint
@number_to_create.times do
new_blueprint = blueprint_a.blending_crossover(blueprint_b)
created << make_answer(new_blueprint, a, b)
end
end
end
label parents: answers
label created: created
end
end
describe "DoBlendingCrossover" do
describe "initialization" do
it "should have a #number_to_create"
end
describe "processing" do
it "should process answers with different languages separately"
it "should build offspring from pairs of answers in each language group"
it "should shuffle each group before pairing them off" do
#setup
this_machine = DoBlendingCrossover.new(args)
my_split_answers = {Nudge:[NudgeAnswer.new("foo")], Speak:[SpeakAnswer.new("abcde")]}
this_machine.should_receive(:answers_keyed_by_language).and_return(my_split_answers)
#test
my_split_answers[:Nudge].should_receive.shuffle!.and_return([])
my_split_answers[:Speak].should_receive.shuffle!.and_return([])
this_machine.process_answers
end
it "should call blending_crossover for each pair"
describe "routing" do
it "should send all the original answers to route 'parents'"
it "should send all the new answers to route 'created'"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment