Skip to content

Instantly share code, notes, and snippets.

@mowat27
Last active December 25, 2015 04:39
Show Gist options
  • Select an option

  • Save mowat27/6919390 to your computer and use it in GitHub Desktop.

Select an option

Save mowat27/6919390 to your computer and use it in GitHub Desktop.
Trigram kata for 10/10/2013
require 'rspec-given'
class StoryCreator
def initialize(story, selector_fn = nil)
@story = story
@selector_fn = selector_fn
end
def new_story
trigram = {
"I wish" => ["I"],
"wish I" => ["may"]
}
if ! @selector_fn
@story
else
start_point = @selector_fn.call(trigram)
"#{start_point} #{trigram[start_point].first}"
end
end
end
describe StoryCreator do
context "with 1 word" do
Given(:story_creator) { StoryCreator.new("I") }
Then { story_creator.new_story == "I" }
end
context "with 2 words" do
Given(:story_creator) { StoryCreator.new("I wish") }
Then { story_creator.new_story == "I wish" }
end
context "with words" do
Given(:story_creator) { StoryCreator.new("I wish I may", ->(trigram) { "wish I" } ) }
Then { story_creator.new_story == "wish I may" }
end
end
{
"I wish" => ["I"],
"wish I" => ["may"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment