Пример #1
0
    def test_when_start_is_bigger_than_end(self):

        start = util.str_to_datetime('2020-12-07')
        end = util.str_to_datetime('2020-12-04')

        with self.assertRaises(ValueError):
            logic.filter_by_date_interval(self.input_example, start, end)
Пример #2
0
    def test_when_end_is_out_of_range(self):

        start = util.str_to_datetime('2020-12-01')
        end = util.str_to_datetime('2020-12-11')

        with self.assertRaises(ValueError):
            logic.filter_by_date_interval(self.input_example, start, end)
Пример #3
0
    def test_for_full_range(self):

        expected = self.input_example

        start = util.str_to_datetime('2020-12-01')
        end = util.str_to_datetime('2020-12-10')

        result = logic.filter_by_date_interval(self.input_example, start, end)
        result = result.reset_index(drop=True)

        pd.testing.assert_frame_equal(expected, result)
Пример #4
0
    def test_for_last_days(self):

        expected = util.matrix_to_dataframe([
            ['2020-12-09', 9, 90],
        ])

        start = util.str_to_datetime('2020-12-09')
        end = util.str_to_datetime('2020-12-10')

        result = logic.filter_by_date_interval(self.input_example, start, end)
        result = result.reset_index(drop=True)

        pd.testing.assert_frame_equal(expected, result)
Пример #5
0
    def test_for_valid_interval(self):

        expected = util.matrix_to_dataframe([
            ['2020-12-04', 4, 40],
            ['2020-12-05', 5, 50],
            ['2020-12-06', 6, 60],
        ])

        start = util.str_to_datetime('2020-12-04')
        end = util.str_to_datetime('2020-12-07')

        result = logic.filter_by_date_interval(self.input_example, start, end)
        result = result.reset_index(drop=True)

        pd.testing.assert_frame_equal(expected, result)
Пример #6
0
    def test_if_values_are_correct(self):

        expected = pd.DataFrame([
            ['2020-12-01', 1000.533966],
            ['2020-12-02', 1001.068218],
            ['2020-12-03', 1001.602756],
            ['2020-12-04', 1002.137578],
            ['2020-12-05', 1002.672686],
            ['2020-12-06', 1003.208080],
            ['2020-12-07', 1003.743760],
            ['2020-12-08', 1004.279726],
            ['2020-12-09', 1004.815978],
        ],
                                columns=['date', 'unitPrice'])

        cdb = 103.5
        start = util.str_to_datetime('2020-12-01')
        end = util.str_to_datetime('2020-12-10')

        result = logic.calculate_cdb_for_period(self.input_example, cdb, start,
                                                end)

        pd.testing.assert_frame_equal(expected, result)