Ejemplo n.º 1
0
    def test_quick_alternate_square(self):
        entries = [
            Transaction(0, 100, 'USD', price=10),
            Transaction(0, -100, 'USD', price=10)
        ]

        fifo = FIFO(entries)

        self.assertTrue(len(fifo.inventory) == 0)
        self.assertTrue(fifo.is_empty)
        self.assertTrue(len(fifo.trace) == 1)
        self.assertEqual(fifo.stock, 0)
        self.assertIsNone(fifo.avgcost)
Ejemplo n.º 2
0
    def test_two_buys(self):
        entries = [
            Transaction(0, -100, 'USD', price=10),
            Transaction(0, -100, 'USD', price=20)
        ]

        fifo = FIFO(entries)

        self.assertTrue(len(fifo.inventory) == 2)
        self.assertFalse(fifo.is_empty)
        self.assertTrue(len(fifo.trace) == 0)
        self.assertTrue(fifo.stock, -200)
        self.assertIsNotNone(fifo.avgcost)
        self.assertEqual(fifo.avgcost, 15)
Ejemplo n.º 3
0
    def test_multiple_Transaction_stock_out_alt(self):
        entries = [
            Transaction(0, -100, 'USD', price=10),
            Transaction(0, 50, 'USD', price=10),
            Transaction(0, 50, 'USD', price=15)
        ]

        fifo = FIFO(entries)

        self.assertTrue(len(fifo.inventory) == 0)
        self.assertTrue(fifo.is_empty)
        self.assertTrue(len(fifo.trace) == 2)
        self.assertEqual(fifo.stock, 0)
        self.assertIsNone(fifo.avgcost)
Ejemplo n.º 4
0
    def test_alternate_sell_buy(self):
        entries = [
            Transaction(0, -100, 'USD', price=10),
            Transaction(0, 200, 'USD', price=10)
        ]

        fifo = FIFO(entries)

        self.assertTrue(len(fifo.inventory) == 1)
        self.assertFalse(fifo.is_empty)
        self.assertTrue(len(fifo.trace) == 1)
        self.assertEqual(fifo.stock, 100)
        self.assertIsNotNone(fifo.avgcost)
        self.assertEqual(fifo.avgcost, 10)
Ejemplo n.º 5
0
    def test_complex_trades(self):
        fifo = FIFO([
            Transaction(0, 60, 'USD', price=10),
            Transaction(0, 10, 'USD', price=12),
            Transaction(0, -50, 'USD', price=10)
        ])
        self.assertEqual(fifo.stock, 20)
        self.assertEqual(fifo.avgcost, 11)

        fifo = FIFO([
            Transaction(0, 60, 'USD', price=10),
            Transaction(0, 10, 'USD', price=12),
            Transaction(0, -80, 'USD', price=10)
        ])
        self.assertEqual(fifo.stock, -10)
        self.assertEqual(fifo.avgcost, 10)

        fifo = FIFO([
            Transaction(0, 60, 'USD', price=10),
            Transaction(0, -10, 'USD', price=12),
            Transaction(0, -20, 'USD', price=10),
            Transaction(0, 50, 'USD', price=12),
            Transaction(0, -60, 'USD', price=14),
            Transaction(0, 10, 'USD', price=21)
        ])

        self.assertEqual(fifo.stock, 30)
        self.assertEqual(fifo.avgcost, 15)

        fifo = FIFO([
            Transaction(0, 20, 'USD', price=10),
            Transaction(0, 32, 'USD', price=7),
            Transaction(0, 97, 'USD', price=6),
            Transaction(0, 17, 'USD', price=2),
            Transaction(0, 14, 'USD', price=0),
            Transaction(0, -50, 'USD', price=9),
            Transaction(0, -59, 'USD', price=6),
            Transaction(0, -50, 'USD', price=8),
            Transaction(0, 63, 'USD', price=10),
            Transaction(0, -31, 'USD', price=6),
            Transaction(0, -21, 'USD', price=1),
            Transaction(0, -36, 'USD', price=10),
            Transaction(0, -18, 'USD', price=2),
            Transaction(0, 91, 'USD', price=2),
            Transaction(0, 85, 'USD', price=4),
            Transaction(0, -81, 'USD', price=1),
            Transaction(0, 33, 'USD', price=2),
            Transaction(0, 45, 'USD', price=4),
            Transaction(0, -18, 'USD', price=4),
            Transaction(0, -33, 'USD', price=7),
            Transaction(0, -47, 'USD', price=3),
            Transaction(0, -49, 'USD', price=7),
            Transaction(0, 73, 'USD', price=3),
            Transaction(0, 79, 'USD', price=10),
            Transaction(0, 3, 'USD', price=5),
            Transaction(0, 50, 'USD', price=7),
            Transaction(0, -82, 'USD', price=10),
            Transaction(0, 47, 'USD', price=9),
            Transaction(0, 72, 'USD', price=10),
            Transaction(0, 40, 'USD', price=1)
        ])
        self.assertEqual(fifo.stock, 286)
        self.assertEqual(fifo.avgcost, 8)

        fifo = FIFO([
            Transaction(0, 20, 'USD', price=10),
            Transaction(0, 32, 'USD', price=7),
            Transaction(0, 97, 'USD', price=6),
            Transaction(0, 17, 'USD', price=2),
            Transaction(0, 14, 'USD', price=0),
            Transaction(0, -50, 'USD', price=9),
            Transaction(0, -59, 'USD', price=6),
            Transaction(0, -50, 'USD', price=8),
            Transaction(0, 63, 'USD', price=10),
            Transaction(0, -31, 'USD', price=6),
            Transaction(0, -21, 'USD', price=1),
            Transaction(0, -36, 'USD', price=10),
            Transaction(0, -18, 'USD', price=2),
            Transaction(0, 91, 'USD', price=2),
            Transaction(0, 85, 'USD', price=4),
            Transaction(0, -81, 'USD', price=1),
            Transaction(0, 33, 'USD', price=2),
            Transaction(0, 45, 'USD', price=4),
            Transaction(0, -18, 'USD', price=4),
            Transaction(0, -33, 'USD', price=7),
            Transaction(0, -47, 'USD', price=3),
            Transaction(0, -49, 'USD', price=7),
            Transaction(0, 73, 'USD', price=3),
            Transaction(0, 79, 'USD', price=10),
            Transaction(0, 3, 'USD', price=5),
            Transaction(0, 50, 'USD', price=7),
            Transaction(0, -82, 'USD', price=10),
            Transaction(0, 47, 'USD', price=9),
            Transaction(0, 72, 'USD', price=10),
            Transaction(0, 40, 'USD', price=1),
            Transaction(0, -286, 'USD', price=8)
        ])

        self.assertEqual(fifo.stock, 0)
        self.assertIsNone(fifo.avgcost)