Ejemplo n.º 1
0
    def test_condense02a(self):
        """
        Test condense with 2 distinct intervals and 2 rows (X takes place before Y).
        """
        rows = [{
            'year': '2010',
            'period': '1',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }, {
            'year': '2010',
            'period': '2',
            'start': '2010-02-01',
            'end': '2010-02-28'
        }]

        expected = [{
            'year': '2010',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }, {
            'year': '2010',
            'start': '2010-02-01',
            'end': '2010-02-28'
        }]

        helper = Type2CondenseHelper('start', 'end', ['year'])
        helper.prepare_data(rows)
        helper.condense()
        actual = helper.get_rows()

        self.assertEqual(expected, actual)
Ejemplo n.º 2
0
    def test_condense07b(self):
        """
        Test condense with 2 equal intervals and 3 rows.
        """
        rows = [{
            'year': '2010',
            'period': '1',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }, {
            'year': '2010',
            'period': '2',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }, {
            'year': '2010',
            'period': '2',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }]

        expected = [{
            'year': '2010',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }]

        helper = Type2CondenseHelper('start', 'end', ['year'])
        helper.prepare_data(rows)
        helper.condense()
        actual = helper.get_rows()

        self.assertEqual(expected, actual)
Ejemplo n.º 3
0
    def test_condense06c(self):
        """
        Test condense with 2 overlapping intervals and 2 rows (X finishes Y).
        """
        rows = [{
            'year': '2010',
            'period': '2',
            'start': '2010-01-01',
            'end': '2010-03-31'
        }, {
            'year': '2010',
            'period': '1',
            'start': '2010-03-01',
            'end': '2010-03-31'
        }]

        expected = [{
            'year': '2010',
            'start': '2010-01-01',
            'end': '2010-02-28'
        }, {
            'year': '2010',
            'start': '2010-03-01',
            'end': '2010-03-31'
        }]

        helper = Type2CondenseHelper('start', 'end', ['year'])
        helper.prepare_data(rows)
        helper.condense()
        actual = helper.get_rows()

        self.assertEqual(expected, actual)
Ejemplo n.º 4
0
    def test_condense8a(self):
        """
        Test with 3 intervals.
        """
        rows = [{
            'year': '2010',
            'period': '1',
            'start': '2010-01-01',
            'end': '2010-12-31'
        }, {
            'year': '2010',
            'period': '2',
            'start': '2010-02-01',
            'end': '2010-02-28'
        }, {
            'year': '2010',
            'period': '3',
            'start': '2010-05-01',
            'end': '2010-05-31'
        }]

        expected = [{
            'year': '2010',
            'start': '2010-01-01',
            'end': '2010-01-31'
        }, {
            'year': '2010',
            'start': '2010-02-01',
            'end': '2010-02-28'
        }, {
            'year': '2010',
            'start': '2010-03-01',
            'end': '2010-04-30'
        }, {
            'year': '2010',
            'start': '2010-05-01',
            'end': '2010-05-31'
        }, {
            'year': '2010',
            'start': '2010-06-01',
            'end': '2010-12-31'
        }]

        helper = Type2CondenseHelper('start', 'end', ['year'])
        helper.prepare_data(rows)
        helper.condense()
        actual = helper.get_rows()

        self.assertEqual(expected, actual)