def testSimpleAddition(self): #sum = Money.dollar(5).plus(Money.dollar(5)) five = Money.dollar(5) sum = five.plus(five) bank = Bank() reduced = bank.reduce(sum, "USD") self.assertEqual(Money.dollar(10), reduced)
def test_sign(): pos = Money(1000) neg = Money(-1000) assert -pos == neg assert neg == +neg assert abs(pos) == pos assert abs(neg) == pos
def test_subtract(): m = Money(1000) assert m - 10 == Money(990) assert 1500 - m == Money(500) with pytest.raises(ValueError): m - 10.0 with pytest.raises(ValueError): 10.0 - m
def test_add(): m = Money(1000) assert m + 10 == Money(1010) assert 500 + m == Money(1500) with pytest.raises(ValueError): m + 10.0 with pytest.raises(ValueError): 10.0 + m
def test_divide(): m = Money(1000) assert m / 10 == Money(100) assert m / 3 == Money(333) assert m / Money(10) == Money(100) assert m / 10.0 == Money(100) assert m // 3 == Money(333) assert m // Money(3) == Money(333) with pytest.raises(ZeroDivisionError): m / 0 m / Money(0)
def test_init_non_int(): with pytest.raises(ValueError): Money(1000.0) with pytest.raises(ValueError): Money(Decimal(1000.0)) with pytest.raises(ValueError): Money("$10.00") with pytest.raises(ValueError): m = Money(1000) Money(m)
def __init__(self): self.player = None # How far this world has been scrolled left/right self.world_shift = 0 self.level_limit = -1000 self.world_offset_y = 0 # self.sprite_list = pygame.sprite.LayeredUpdates() self.sprite_list = pygame.sprite.LayeredUpdates() self.background_list = pygame.sprite.Group() # Solid objects self.solid_list = pygame.sprite.Group() self.enemy_list = pygame.sprite.Group() self.bullet_list = pygame.sprite.Group() self.blood_list = pygame.sprite.Group() self.exit_list = pygame.sprite.Group() self.collectible_list = pygame.sprite.Group() self.blood_num = 0 self.health_bar = HealthBar(20, 20, 100) self.sprite_list.add(self.health_bar) self.money = Money(0, 0) self.sprite_list.add(self.money) super(Level, self).__init__()
def test_multiply(): m = Money(1000) assert m * 10 == Money(10000) assert 50 * m == Money(50000) assert m * 10.0 == Money(10000) assert 50.0 * m == Money(50000) assert m * 1.5 == Money(1500) assert m * 1.0009 == Money(1001)
def test_comparison(): m = Money(1000) assert m == Money(1000) assert m >= Money(1000) assert m >= Money(999) assert m > Money(999) assert m <= Money(1000) assert m < Money(1001) assert m == 1000 assert m >= 1000 assert m >= 999 assert m > 999 assert m <= 1000 assert m < 1001 with pytest.raises(ValueError): assert m == 1000.0 assert m >= 1000.0 assert m >= 999.0 assert m > 999.0 assert m <= 1000.0 assert m < 1001.0
def test_init_from_float(): m = Money.from_float(1000.0) assert m.amount == 100000
def testMultiplication(self): five = Money.dollar(5) self.assertEqual(Money.dollar(10), five.times(2)) self.assertEqual(Money.dollar(15), five.times(3))
def testPlusReturnsSum(self): five = Money.dollar(5) result = five.plus(five)
def test_cast(): m = Money(1000) assert int(m) == 1000 assert float(m) == 10.0
def testCurrency(self): self.assertEqual(Money.dollar(1).currency, "USD") self.assertEqual(Money.franc(1).currency, "CHF")
def testEquality(self): self.assertNotEqual(Money.franc(5), Money.dollar(5))
def testFrancEquality(self): self.assertEqual(Money.franc(5), Money.franc(5))
def testDollarEquality(self): self.assertEqual(Money.dollar(5), Money.dollar(5)) self.assertNotEqual(Money.dollar(5), Money.dollar(6))
def test_exercise(): a = Money(10, 0) b = Money(5, 0) assert str(a.plus(b)) == "15.00p" a = Money(10, 0) b = Money(3, 0) c = Money(5, 0) assert not a.less_than(b) assert b.less_than(c) a = Money(10, 0) b = Money(3, 50) assert str(a.minus(b)) == "6.50p"
def test_round(): assert round(Money(1001)) == 1000 assert round(Money(1051)) == 1100
def test_init_from_string(): m = Money.from_string("$6,150,593.22") assert m.amount == 615059322
def test_init_with_int(): m = Money(1000) assert m.amount == 1000
def test_to_str(): m = Money(1000) assert str(m) == "$10.00" m = Money(100000) assert str(m) == "$1,000.00"