コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
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)
コード例 #4
0
 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)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
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)
コード例 #15
0
 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)
コード例 #16
0
 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)