def test_usd_to_cents_valid_non_strings(self): """Return an int given a valid non-string type.""" assert USDollar.usd_to_cents(1) == 100 assert USDollar.usd_to_cents(2.99) == 299 assert USDollar.usd_to_cents(3.999) == 399 assert USDollar.usd_to_cents(Decimal('1.99')) == 199 assert USDollar.usd_to_cents(3.14159265) == 314
def test_usd_to_cents_valid_string(self): """Return an int given a valid string containing a dollar amount.""" assert USDollar.usd_to_cents('$2.99') == 299 assert USDollar.usd_to_cents('3.00') == 300 assert USDollar.usd_to_cents('2.50$') == 250 assert USDollar.usd_to_cents('$ 1.99') == 199 assert USDollar.usd_to_cents('4.99 $') == 499 assert USDollar.usd_to_cents(' 3.50 ') == 350 assert USDollar.usd_to_cents('4') == 400 assert USDollar.usd_to_cents('5.3') == 530 assert USDollar.usd_to_cents('3.9999') == 399
def test_cents_to_usd_two_decimal_places(self): """Always return a Decimal with 2 decimal places.""" assert str(USDollar.cents_to_usd(100)) == '1.00' assert str(USDollar.cents_to_usd(350)) == '3.50' assert str(USDollar.cents_to_usd(1000)) == '10.00'
def test_cents_to_usd(self): """Return a Decimal USD value given an integer.""" assert USDollar.cents_to_usd(100) == Decimal('1.00') assert USDollar.cents_to_usd(299) == Decimal('2.99') assert USDollar.cents_to_usd(350) == Decimal('3.50')