Exemple #1
0
    def test_cashflows_by_period_mixtypes(self):
        day = timedelta(days=1)

        offsets = [-5, 0, 1, 10, 10, 15]
        amounts = [-1000, 200, 300, 250, 150, 50]
        datetimes = [
            self.datetime + offsets[0] * day,
            self.datetime + offsets[1] * day,
            self.dt + offsets[2] * day,
            self.datetime + offsets[3] * day,
            self.dt + offsets[4] * day,
            self.datetime + offsets[5] * day,
        ]

        cashflows = [
            CashFlow(amount=am, datetime=dt)
            for am, dt in zip(amounts, datetimes)
        ]

        before, during, after = UserAccount.cashflows_by_period(
            self.dt, self.dt + day * 10, cashflows)
        self.assertListEqual(before, cashflows[:2])
        self.assertListEqual(during, cashflows[2:5])
        self.assertListEqual(after, cashflows[5:])

        self.assertListEqual([c.amount for c in during], [300, 250, 150])
Exemple #2
0
 def test_cashflows_by_period_one_day(self):
     cashflows = [
         CashFlow(datetime=self.datetime, amount=1),
         CashFlow(datetime=self.datetime, amount=2)
     ]
     before, during, after = UserAccount.cashflows_by_period(
         self.dt - timedelta(1), self.dt, cashflows)
     self.assertListEqual(before, [])
     self.assertListEqual(during, cashflows)
     self.assertListEqual(after, [])
Exemple #3
0
    def test_cashflows_by_period_dates(self):
        day = timedelta(days=1)

        offsets = [-5, 0, 1, 10, 10, 15]
        amounts = [-1000, 200, 300, 250, 150, 50]
        cashflows = [
            CashFlow(amount=am, datetime=self.dt + day * off)
            for am, off in zip(amounts, offsets)
        ]

        before, during, after = UserAccount.cashflows_by_period(
            self.dt, self.dt + day * 10, cashflows)
        self.assertListEqual(before, cashflows[:2])
        self.assertListEqual(during, cashflows[2:5])
        self.assertListEqual(after, cashflows[5:])

        self.assertListEqual([c.amount for c in during], [300, 250, 150])
Exemple #4
0
 def test_cashflows_by_period_empty(self):
     before, during, after = UserAccount.cashflows_by_period(
         self.dt, self.dt + timedelta(50), [])
     self.assertListEqual(before, [])
     self.assertListEqual(during, [])
     self.assertListEqual(after, [])