so i have this piss ugly mess of ruby code for testFirst's pig latin tests (testing the translate function)
Code:
def translate(word)
(vowel_start(word)) ? word << "ay" : concat(word) << "ay"
end
def vowel_start(word)
if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u')
return true
else
return false
end
end
def concat(word)
word_end = word[0]
new_word = word[1..word.length-1]
until (vowel_start(new_word)) do
word_end << new_word[0]
new_word = new_word[1..new_word.length-1]
end
new_word << word_end
end
just got thru refactoring so it'd handle words like "school" or even longer sets of consonants, because some of the later tests do tons of consonants in a row. Felt good about that.
But then they start adding multiple words! Bastards!
I think i've been going about this all wrong, just looking at the first failure and writing for that, then rewriting / trying to work around what I have. In this case, where we get into longer phrases and ones that have "qu" to deal with, it seems like it'd be easier to start from scratch.
That seem like the case or no? Is that usually the case, or are those more experienced with tdd likely to read all the tests first?