Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created May 8, 2010 19:18
Show Gist options
  • Save al-the-x/394721 to your computer and use it in GitHub Desktop.
Save al-the-x/394721 to your computer and use it in GitHub Desktop.
require 'test/unit'
require 'money_parser'
class MoneyParserTest < Test::Unit::TestCase
def assert_string_parses ( string, expected )
money_result = MoneyParser.parse(string)
assert_equal expected, money_result,
"Expected '#{string}' to return #{expected}!"
end
def provide_string_and_expected
{
"one dollar" => 1,
"two dollars" => 2,
"three dollars" => 3,
"four dollars" => 4,
"five dollars" => 5,
"six dollars" => 6,
"seven dollars" => 7,
"eight dollars" => 8,
"nine dollars" => 9,
"ten dollars" => 10,
"eleven dollars" => 11,
"twelve dollars" => 12,
"thirteen dollars" => 13,
"fourteen dollars" => 14,
"fifteen dollars" => 15,
"sixteen dollars" => 16,
"seventeen dollars" => 17,
"eighteen dollars" => 18,
"nineteen dollars" => 19,
"twenty dollars" => 20,
"twenty-one dollars" => 21,
"twenty one dollars" => 21,
"twenty-five dollars" => 25,
"twenty six dollars" => 26,
"twenty-six dollars" => 26,
"thirty seven dollars" => 37,
"ninety one dollars" => 91,
##"one hundred dollars" => 100,
##"seventy eleven dollars" => nil,
'one hundred and eleven dollars' => 111,
}
end #provide_string_and_expected
def test_all
provide_string_and_expected.each do
|string, expected|
assert_string_parses string, expected
end
end
end #MoneyParserTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment