def test_single_forwarding_zero_balance_cleanup(self): balances = Balances() balances.add('a', 1) balances.add('b', 2) balances.add('c', 3) balances.addFirstRef('a') balances.consumeContents_IfAny('a') self.assertDictEqual(balances.balances, {'a': 0, 'b': 2, 'c': 3}) balances.consumeAndForward(['a', 'b'], 'c') self.assertDictEqual(balances.balances, {'c': 5}) balances.consumeContents_IfAny('c') self.assertDictEqual(balances.balances, {'c': 0}) balances.removeRef('a') self.assertDictEqual(balances.balances, {})
def test_consume_contents(self): balances = Balances() returnValue = balances.consumeContents_IfAny('2') self.assertEqual(returnValue, 0) balances.add('1', 5) balances.add('2', 7) balances.add('3', 9) balances.addFirstRef('1') returnValue = balances.consumeContents_IfAny('1') self.assertEqual(returnValue, 5) self.assertDictEqual(balances.balances, {'3': 9, '2': 7, '1': 0}) returnValue = balances.consumeContents_IfAny('1') self.assertEqual(returnValue, 0) self.assertDictEqual(balances.balances, {'3': 9, '2': 7, '1': 0}) returnValue = balances.consumeContents_IfAny('2') self.assertEqual(returnValue, 7) self.assertDictEqual(balances.balances, {'3': 9, '1': 0}) balances.removeRef('1') self.assertDictEqual(balances.balances, {'3': 9})