def testSplitFundSufficientFunds(self): source = funds.Fund() source.amount = 40 source.unrealized_gains = 20 sink = funds.Fund() source, sink = funds.SplitFund(source, sink, 30) self.assertEqual(source.amount, 10) self.assertEqual(sink.amount, 30) self.assertEqual(source.unrealized_gains, 5) self.assertEqual(sink.unrealized_gains, 15)
def testSplitFundSourceHasZeroFunds(self): source = funds.Fund() source.amount = 0 source.unrealized_gains = 0 sink = funds.Fund() source, sink = funds.SplitFund(source, sink, 30) self.assertEqual(source.amount, 0) self.assertEqual(sink.amount, 0) self.assertEqual(source.unrealized_gains, 0) self.assertEqual(sink.unrealized_gains, 0)
def testSplitFundInsufficientFunds(self): source = funds.Fund() source.amount = 40 source.unrealized_gains = 20 sink = funds.Fund() source, sink = funds.SplitFund(source, sink, 50) self.assertEqual(source.amount, 0) self.assertEqual(sink.amount, 40) self.assertEqual(source.unrealized_gains, 0) self.assertEqual(sink.unrealized_gains, 20)
def testSplitFundSinkHasMoney(self): source = funds.Fund() source.amount = 40 source.unrealized_gains = 20 sink = funds.Fund() sink.amount = 20 sink.unrealized_gains = 10 source, sink = funds.SplitFund(source, sink, 30) self.assertEqual(source.amount, 10) self.assertEqual(sink.amount, 50) self.assertEqual(source.unrealized_gains, 5) self.assertEqual(sink.unrealized_gains, 25)
def testDepositUnlimitedRoom(self): fund = funds.Fund() deposited, year_rec = fund.Deposit(15, utils.YearRecord()) self.assertEqual(deposited, 15) self.assertEqual(fund.amount, 15) self.assertIn(funds.DepositReceipt(15, funds.FUND_TYPE_NONE), year_rec.deposits)
def testGrowthInflation(self): fund = funds.Fund() fund.amount = 20 year_rec = utils.YearRecord() year_rec.growth_rate = 0 year_rec.inflation = 1 self.assertEqual(fund.Growth(year_rec), 20)
def testWithdrawForcedInsufficient(self): fund = funds.Fund() fund.amount = 10 fund.forced_withdraw = 15 withdrawn, gains, year_rec = fund.Withdraw(5, utils.YearRecord()) self.assertEqual(withdrawn, 10) self.assertEqual(fund.amount, 0) self.assertEqual(fund.forced_withdraw, 0)
def testWithdrawForcedActive(self): fund = funds.Fund() fund.amount = 20 fund.forced_withdraw = 15 withdrawn, gains, year_rec = fund.Withdraw(10, utils.YearRecord()) self.assertEqual(withdrawn, 15) self.assertEqual(fund.amount, 5) self.assertEqual(fund.forced_withdraw, 0)
def testWithdrawInsufficientFunds(self): fund = funds.Fund() fund.amount = 5 withdrawn, gains, year_rec = fund.Withdraw(15, utils.YearRecord()) self.assertEqual(withdrawn, 5) self.assertEqual(fund.amount, 0) self.assertIn(funds.WithdrawReceipt(5, 0, funds.FUND_TYPE_NONE), year_rec.withdrawals)
def testWithdrawZero(self): fund = funds.Fund() fund.amount = 0 withdrawn, gains, year_rec = fund.Withdraw(10, utils.YearRecord()) self.assertEqual(withdrawn, 0) self.assertEqual(gains, 0) self.assertIn(funds.WithdrawReceipt(0, 0, funds.FUND_TYPE_NONE), year_rec.withdrawals)
def testWithdrawRoomReplenishment(self): fund = funds.Fund() fund.amount = 20 fund.GetRoom = unittest.mock.MagicMock(return_value=5) set_room = unittest.mock.MagicMock() fund.SetRoom = set_room fund.room_replenishes = True withdrawn, gains, year_rec = fund.Withdraw(10, utils.YearRecord()) set_room.assert_called_with(unittest.mock.ANY, 15)
def testWithdrawRealizedGains(self): fund = funds.Fund() fund.amount = 40 fund.unrealized_gains = 5 withdrawn, gains, year_rec = fund.Withdraw(10, utils.YearRecord()) self.assertEqual(withdrawn, 10) self.assertEqual(gains, 1.25) self.assertEqual(fund.unrealized_gains, 3.75) self.assertIn(funds.WithdrawReceipt(10, 1.25, funds.FUND_TYPE_NONE), year_rec.withdrawals)
def testDepositInsufficientRoom(self): fund = funds.Fund() fund.GetRoom = unittest.mock.MagicMock(return_value=10) set_room = unittest.mock.MagicMock() fund.SetRoom = set_room deposited, year_rec = fund.Deposit(15, utils.YearRecord()) self.assertEqual(deposited, 10) self.assertEqual(fund.amount, 10) self.assertIn(funds.DepositReceipt(10, funds.FUND_TYPE_NONE), year_rec.deposits) set_room.assert_called_with(unittest.mock.ANY, 0)
def testGrowthVeryNegative(self): fund = funds.Fund() fund.amount = 20 year_rec = utils.YearRecord() year_rec.growth_rate = -1.2 self.assertEqual(fund.Growth(year_rec), -20)
def testGrowthPositive(self): fund = funds.Fund() fund.amount = 20 year_rec = utils.YearRecord() year_rec.growth_rate = 0.1 self.assertEqual(fund.Growth(year_rec), 2)
def testGrowthZero(self): fund = funds.Fund() fund.amount = 20 year_rec = utils.YearRecord() year_rec.growth_rate = 0 self.assertEqual(fund.Growth(year_rec), 0)