18 lines
598 B
Python
18 lines
598 B
Python
import unittest
|
|
from money import to_cents
|
|
|
|
class MoneyTests(unittest.TestCase):
|
|
def test_decimal_text_uses_exact_cents(self):
|
|
self.assertEqual(to_cents("0.29"), 29)
|
|
|
|
def test_half_cent_rounds_up(self):
|
|
self.assertEqual(to_cents("1.005"), 101)
|
|
|
|
def test_negative_half_cent_rounds_away_from_zero(self):
|
|
self.assertEqual(to_cents("-1.005"), -101)
|
|
|
|
def test_invalid_or_nonfinite_amount_is_rejected(self):
|
|
for value in ("bad", "Infinity", "NaN"):
|
|
with self.subTest(value=value), self.assertRaises(ValueError):
|
|
to_cents(value)
|