# Path: num2words/currency.py
# def parse_currency_parts(value, is_int_with_cents=True):
#     if isinstance(value, int):
#         if is_int_with_cents:
#             # assume cents if value is integer
#             negative = value < 0
#             value = abs(value)
#             integer, cents = divmod(value, 100)
#         else:
#             negative = value < 0
#             integer, cents = abs(value), 0
# 
#     else:
#         value = Decimal(value)
#         value = value.quantize(
#             Decimal('.01'),
#             rounding=ROUND_HALF_UP
#         )
#         negative = value < 0
#         value = abs(value)
#         integer, fraction = divmod(value, 1)
#         integer = int(integer)
#         cents = int(fraction * 100)
# 
#     return integer, cents, negative


from decimal import Decimal
from unittest import TestCase
from num2words.currency import parse_currency_parts

class CurrencyTestCase(TestCase):
    def test_parse_currency_parts(self):
        # integer with cents
        self.assertEqual(parse_currency_parts(101), (1, 1, False))
        self.assertEqual(parse_currency_parts(-123), (1, 23, True))

        # integer without cents
        self.assertEqual(parse_currency_parts(101, is_int_with_cents=False),
                         (101, 0, False))
        self.assertEqual(parse_currency_parts(-123, is_int_with_cents=False),
                         (123, 0, True))

        # float
        self.assertEqual(parse_currency_parts(1.01), (1, 1, False))
        self.assertEqual(parse_currency_parts(-1.23), (1, 23, True))
        self.assertEqual(parse_currency_parts(-1.2), (1, 20, True))
        self.assertEqual(parse_currency_parts(0.004), (0, 0, False))
        self.assertEqual(parse_currency_parts(0.005), (0, 1, False))
        self.assertEqual(parse_currency_parts(0.006), (0, 1, False))
        self.assertEqual(parse_currency_parts(0.0005), (0, 0, False))
        self.assertEqual(parse_currency_parts(0.984), (0, 98, False))
        self.assertEqual(parse_currency_parts(0.989), (0, 99, False))
        self.assertEqual(parse_currency_parts(0.994), (0, 99, False))
        self.assertEqual(parse_currency_parts(0.999), (1, 0, False))
        # self.assertEqual(parse_currency_parts(0.985), (0, 99, False))
        # self.assertEqual(parse_currency_parts(0.995), (1, 0, False))

        # decimal
        self.assertEqual(parse_currency_parts(Decimal("1.01")), (1, 1, False))

# Path: num2words/currency.py
# def parse_currency_parts(value, is_int_with_cents=True):
#     if isinstance(value, int):
#         if is_int_with_cents:
#             # assume cents if value is integer
#             negative = value < 0
#             value = abs(value)
#             integer, cents = divmod(value, 100)
#         else:
#             negative = value < 0
#             integer, cents = abs(value), 0
# 
#     else:
#         value = Decimal(value)
#         value = value.quantize(
#             Decimal('.01'),
#             rounding=ROUND_HALF_UP
#         )
#         negative = value < 0
#         value = abs(value)
#         integer, fraction = divmod(value, 1)
#         integer = int(integer)
#         cents = int(fraction * 100)
# 
#     return integer, cents, negative


# Path: tests/test_currency.py
from decimal import Decimal
from unittest import TestCase
from num2words.currency import parse_currency_parts


class CurrencyTestCase(TestCase):
    def test_parse_currency_parts(self):
        # integer with cents
        self.assertEqual(parse_currency_parts(101), (1, 1, False))
        self.assertEqual(parse_currency_parts(-123), (1, 23, True))

        # integer without cents
        self.assertEqual(parse_currency_parts(101, is_int_with_cents=False),
                         (101, 0, False))
        self.assertEqual(parse_currency_parts(-123, is_int_with_cents=False),
                         (123, 0, True))

        # float
        self.assertEqual(parse_currency_parts(1.01), (1, 1, False))
        self.assertEqual(parse_currency_parts(-1.23), (1, 23, True))
        self.assertEqual(parse_currency_parts(-1.2), (1, 20, True))
        self.assertEqual(parse_currency_parts(0.004), (0, 0, False))
        self.assertEqual(parse_currency_parts(0.005), (0, 1, False))
        self.assertEqual(parse_currency_parts(0.006), (0, 1, False))
        self.assertEqual(parse_currency_parts(0.0005), (0, 0, False))
        self.assertEqual(parse_currency_parts(0.984), (0, 98, False))
        self.assertEqual(parse_currency_parts(0.989), (0, 99, False))
        self.assertEqual(parse_currency_parts(0.994), (0, 99, False))
        self.assertEqual(parse_currency_parts(0.999), (1, 0, False))
        # self.assertEqual(parse_currency_parts(0.985), (0, 99, False))
        # self.assertEqual(parse_currency_parts(0.995), (1, 0, False))

        # decimal
        self.assertEqual(parse_currency_parts(Decimal("1.01")), (1, 1, False))

        self.assertEqual(parse_currency_parts(Decimal("-1.23")), (1, 23, True))