Created
March 10, 2011 01:28
-
-
Save flavianmissi/863402 to your computer and use it in GitHub Desktop.
Count and Say problem: http://www.rubyquiz.com/quiz138.html
This file contains 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
class CountAndSay: | |
def say(self, word): | |
numbers = {1:"one", 2:"two", 3:"three"} | |
say = "" | |
while len(word) > 0: | |
it = iter(word) | |
letter = it.next() | |
if letter is not " ": | |
say += numbers[word.count(letter)] + " " + letter + " " | |
word = word.replace(letter, "") | |
return say |
This file contains 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
import unittest | |
from count_and_say import CountAndSay | |
from nose.tools import * | |
class CountAndSayTestCase(unittest.TestCase): | |
def test_if_look_retrieve_one_k_one_l_two_o(self): | |
word = CountAndSay() | |
assert_equals(word.say("look"), "one l two o one k ") | |
def test_if_look_and_say_does_not_count_blank_spaces(self): | |
word = CountAndSay() | |
assert_equals(word.say("look and say"), "one l two o one k two a one n one d one s one y ") | |
def test_if_an_randomic_phrase_return_the_expected(self): | |
word = CountAndSay() | |
assert_equals(word.say("an randomic phrase"), "three a two n two r one d one o one m one i one c one p one h one s one e ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment