예제 #1
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))
예제 #2
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))
예제 #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))
예제 #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))
예제 #5
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))
예제 #6
0
 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))
예제 #7
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))
예제 #8
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))
예제 #9
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))
예제 #10
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))
예제 #11
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))
예제 #12
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))
예제 #13
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))
예제 #14
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))