def test_check_outdated_guzis_correctly_remove_outdated_guzas(self): user = User("id", None) user.create_daily_guzis(date(2010, 1, 1)) self.assertEqual(len(user.guza_wallet), 1) self.assertEqual(len(user.total_accumulated), 0) user.check_outdated_guzis(date(2010, 2, 1)) self.assertEqual(len(user.guza_wallet), 0) self.assertEqual(len(user.guza_trashbin), 1)
def test_spend_to_takes_older_guzis_first(self): """ When a user pays, his oldest Guzis should be spended first to avoid constant outdate """ source = User("source", None) target = User("target", None) for i in range(31): source.create_daily_guzis(date(2010, 1, i + 1)) source.spend_to(target, 10) # After spending, user waits 9 days more (to be at 30) for i in range(10): source.create_daily_guzis(date(2010, 2, i + 1)) # Then, of oldest have been taken, there should have no outdated # Guzi which passed to the total_accumulated source.check_outdated_guzis(date(2010, 2, 9)) self.assertEqual(len(source.total_accumulated), 0)
def test_give_guzas_to_takes_older_guzas_first(self): """ When a user gives Guzas, his oldest Guzas should be spended first to avoid constant outdate """ source = User("source", None) target = Company("target", [User(None, None)]) for i in range(31): source.create_daily_guzis(date(2010, 1, i + 1)) source.give_guzas_to(target, 10) # After spending, user waits 10 days more (to be at 31) for i in range(10): source.create_daily_guzis(date(2010, 2, i + 1)) # Then, of oldest have been taken, there should have no outdated # Guza which passed to the total_accumulated source.check_outdated_guzis(date(2010, 2, 9)) self.assertEqual(len(source.guza_trashbin), 0)