Created
April 6, 2016 18:42
-
-
Save Reltre/949359bb7fe01aaac18cff3ac1b070ed to your computer and use it in GitHub Desktop.
To Currency Tests
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 'minitest/autorun' | |
require_relative 'currency' | |
class CurrencyTest < Minitest::Test | |
def test_invalid_currency | |
assert_raises(ArgumentError) { to_currency("453&$*#") } | |
end | |
def test_dollar_format | |
assert_equal '$', to_currency("5")[0] | |
end | |
def test_cents_formatting | |
assert_equal '.32', to_currency("10.32")[-3..-1] | |
end | |
def test_rounds_to_hundreth | |
assert_equal '$22.57', to_currency("22.5683213") | |
end | |
def test_small_number | |
assert_equal '$782.32', to_currency("782.32") | |
end | |
def test_large_number | |
assert_equal '$3,234,111.85', to_currency("3234111.85") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment