Last active
December 25, 2015 04:39
-
-
Save mowat27/6919390 to your computer and use it in GitHub Desktop.
Trigram kata for 10/10/2013
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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