flowrate / flowrate / testing / test_defaultlist.py

import datetime
import decimal

from flowrate.testing import FlowrateTest
from flowrate.ledger import defaultlist


class TestDefaultList(FlowrateTest):

    def test_initial_zero(self):
        d = defaultlist()
        d[0:10] = range(10)
        self.assertEqual(d._data, range(10))
        self.assertEqual(d._initial, 0)

        self.assertEqual(d[3:7], [3, 4, 5, 6])

    def test_initial_positive(self):
        d = defaultlist()
        d[100:110] = range(10)
        self.assertEqual(d._data, range(10))
        self.assertEqual(d._initial, 100)

        self.assertEqual(d[103:107], [3, 4, 5, 6])

    def test_initial_negative(self):
        d = defaultlist()
        d[-110:-100] = range(10)
        self.assertEqual(d._data, range(10))
        self.assertEqual(d._initial, -110)

        self.assertEqual(d[-107:-103], [3, 4, 5, 6])

    def test_grow_high(self):
        d = defaultlist()
        d[100:110] = range(10)
        d[112] = 12
        self.assertEqual(d._data, range(10) + [0, 0, 12])
        self.assertEqual(d._initial, 100)

        self.assertEqual(d[109:114], [9, 0, 0, 12, 0])

        d[111:115] = [11, 72, 13, 14]
        self.assertEqual(d._data, range(10) + [0, 11, 72, 13, 14])
        self.assertEqual(d._initial, 100)

        self.assertEqual(d[109:117], [9, 0, 11, 72, 13, 14, 0, 0])

    def test_grow_low(self):
        d = defaultlist()
        d[100:110] = range(10)
        d[98] = 98
        self.assertEqual(d._data, [98, 0] + range(10))
        self.assertEqual(d._initial, 98)

        self.assertEqual(d[94:102], [0, 0, 0, 0, 98, 0, 0, 1])

        d[95:99] = [95, 96, 97, 888]
        self.assertEqual(d._data, [0, 95, 96, 97, 888, 0] + range(10))
        self.assertEqual(d._initial, 94)

        self.assertEqual(d[94:102], [0, 95, 96, 97, 888, 0, 0, 1])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.