Beispiel #1
0
    def test_input_pipe(self):
        t = 0
        amount = Amount(10, USD)
        flow = PeriodicFlow(name="testFlow", period=10, stime=5, etime=45, amount=amount)
        account = BankAccount('Bank', 100, 0, t)
        pipe = InputPipe(name="testPipe", flow=flow, account=account)
        assert_equals(account.balance(t), 0)

        pipe.start_flow(t)

        # Test that nothing gets tranfered for for T + 1 --> t + 5
        for i in range(1, 6):
            pipe.flush(t+i)
            assert_equals(account.balance(t+i), 0)
            assert_equals(account.balance(t+i+1), 0)

        # Flush until T+6, and verify that a transfer happens!
        pipe.flush(t+6)
        assert_equals(account.balance(t+6), 10)
        assert_equals(account.balance(t+7), 10)

        # Flush until T+16, and verify that a transfer happens!
        pipe.flush(t+16)
        assert_equals(account.balance(t+16), 20)
        assert_equals(account.balance(t+17), 20)
Beispiel #2
0
    def test_costbasis_fetcher(self):
        t = 0
        amount = Amount(10, INR)
        flow = PeriodicFlow(name="testFlow", period=10, stime=5, etime=45, amount=amount)
        account = BankAccount('Bank', 100, 0, t)
        pipe = InputPipe(name="testPipe", flow=flow, account=account, costbasis_fetcher=lambda tt: Amount(tt*2, USD))
        pipe.start_flow(t)

        expected_peek = [
                (5, Amount(10, INR), Amount(5*2, USD)),
                (15, Amount(10, INR), Amount(15*2, USD)),
                (25, Amount(10, INR), Amount(25*2, USD)),
                (35, Amount(10, INR), Amount(35*2, USD)),
            ]
        assert_equals(pipe.peek(100), expected_peek)