def test_should_add_ok_when_nanos_have_different_signs(self):
     the_sum = money.add(self._SOME_YEN, self._SOME_YEN_DEBT)
     want_units = self._SOME_YEN_DEBT.units + self._SOME_YEN.units - 1
     expect(the_sum.units).to(equal(want_units))
     expect(the_sum.nanos).to(equal(money.MAX_NANOS))
     the_sum = money.add(self._SOME_MORE_YEN, self._SOME_YEN_DEBT)
     want_units = self._SOME_YEN_DEBT.units + self._SOME_YEN.units - 1
     expect(the_sum.units).to(equal(want_units))
     expect(the_sum.nanos).to(equal(1 - money.MAX_NANOS))
 def test_should_fail_if_non_money_is_used(self):
     testfs = [
         lambda: money.add(self._SOME_YEN, object()),
         lambda: money.add(object(), self._SOME_USD),
         lambda: money.add(None, self._SOME_USD),
         lambda: money.add(self._SOME_YEN, None),
     ]
     for testf in testfs:
         expect(testf).to(raise_error(ValueError))
Example #3
0
 def test_should_fail_if_non_money_is_used(self):
     testfs = [
         lambda: money.add(self._SOME_YEN, object()),
         lambda: money.add(object(), self._SOME_USD),
         lambda: money.add(None, self._SOME_USD),
         lambda: money.add(self._SOME_YEN, None),
     ]
     for testf in testfs:
         expect(testf).to(raise_error(ValueError))
Example #4
0
 def test_should_add_ok_when_nanos_have_different_signs(self):
     the_sum = money.add(self._SOME_YEN, self._SOME_YEN_DEBT)
     want_units = self._SOME_YEN_DEBT.units + self._SOME_YEN.units - 1
     expect(the_sum.units).to(equal(want_units))
     expect(the_sum.nanos).to(equal(money.MAX_NANOS))
     the_sum = money.add(self._SOME_MORE_YEN, self._SOME_YEN_DEBT)
     want_units = self._SOME_YEN_DEBT.units + self._SOME_YEN.units - 1
     expect(the_sum.units).to(equal(want_units))
     expect(the_sum.nanos).to(equal(1 - money.MAX_NANOS))
 def test_should_allow_positive_overflows(self):
     overflowing = money.add(self._SOME_YEN,
                             self._LARGE_YEN,
                             allow_overflow=True)
     expect(overflowing.units).to(equal(self._INT64_MAX))
     expect(overflowing.nanos).to(equal(money.MAX_NANOS))
 def test_should_fail_on_unallowed_positive_overflows(self):
     testf = lambda: money.add(self._SOME_YEN, self._LARGE_YEN)
     expect(testf).to(raise_error(OverflowError))
 def test_should_fail_on_currency_mismatch(self):
     testf = lambda: money.add(self._SOME_YEN, self._SOME_USD)
     expect(testf).to(raise_error(ValueError))
 def test_should_add_ok_when_nanos_have_same_sign(self):
     the_sum = money.add(self._SOME_YEN, self._SOME_YEN)
     expect(the_sum.units).to(equal(2 * self._SOME_YEN.units))
 def test_should_allow_negative_overflows(self):
     overflowing = money.add(self._SOME_YEN_DEBT,
                             self._LARGE_YEN_DEBT,
                             allow_overflow=True)
     expect(overflowing.units).to(equal(self._INT64_MIN))
     expect(overflowing.nanos).to(equal(-money.MAX_NANOS))
Example #10
0
 def test_should_fail_on_unallowed_negative_overflows(self):
     testf = lambda: money.add(self._SOME_YEN_DEBT, self._LARGE_YEN_DEBT)
     expect(testf).to(raise_error(OverflowError))
Example #11
0
 def test_should_allow_positive_overflows(self):
     overflowing = money.add(self._SOME_YEN, self._LARGE_YEN,
                             allow_overflow=True)
     expect(overflowing.units).to(equal(self._INT64_MAX))
     expect(overflowing.nanos).to(equal(money.MAX_NANOS))
Example #12
0
 def test_should_fail_on_currency_mismatch(self):
     testf = lambda: money.add(self._SOME_YEN, self._SOME_USD)
     expect(testf).to(raise_error(ValueError))
Example #13
0
 def test_should_add_ok_when_nanos_have_same_sign(self):
     the_sum = money.add(self._SOME_YEN, self._SOME_YEN)
     expect(the_sum.units).to(equal(2 * self._SOME_YEN.units))
Example #14
0
 def test_should_allow_negative_overflows(self):
     overflowing = money.add(self._SOME_YEN_DEBT, self._LARGE_YEN_DEBT,
                             allow_overflow=True)
     expect(overflowing.units).to(equal(self._INT64_MIN))
     expect(overflowing.nanos).to(equal(-money.MAX_NANOS))