def test_get_next_date_with_year_difference(self): # Given date_1 = datetime(year=1960, month=2, day=2, hour=10, minute=5, second=0) date_2 = datetime(year=1961, month=2, day=2, hour=10, minute=5, second=0) # When actual_next_dates = date.get_next_dates(date_1, date_2, 2) # Then expected_next_date1 = datetime(year=1962, month=2, day=2, hour=10, minute=5, second=0) expected_next_date2 = datetime(year=1963, month=2, day=2, hour=10, minute=5, second=0) assert [expected_next_date1, expected_next_date2] == actual_next_dates
def test_get_next_date_with_hours_difference(self): # Given date_1 = datetime(year=1960, month=10, day=2, hour=10, minute=5, second=0) date_2 = datetime(year=1960, month=10, day=2, hour=11, minute=5, second=0) # When actual_next_dates = date.get_next_dates(date_1, date_2, 1) # Then expected_next_date = datetime(year=1960, month=10, day=2, hour=12, minute=5, second=0) assert [expected_next_date] == actual_next_dates
def test_get_next_date_with_months_difference_with_february_as_second_date( self): # Given date_1 = datetime(year=1960, month=2, day=2, hour=10, minute=5, second=0) date_2 = datetime(year=1960, month=3, day=2, hour=10, minute=5, second=0) # When actual_next_dates = date.get_next_dates(date_1, date_2, 4) # Then expected_next_date1 = datetime(year=1960, month=4, day=2, hour=10, minute=5, second=0) expected_next_date2 = datetime(year=1960, month=5, day=2, hour=10, minute=5, second=0) expected_next_date3 = datetime(year=1960, month=6, day=2, hour=10, minute=5, second=0) expected_next_date4 = datetime(year=1960, month=7, day=2, hour=10, minute=5, second=0) assert [expected_next_date1, expected_next_date2, expected_next_date3, expected_next_date4] \ == actual_next_dates
def __get_next_dates(self) -> [datetime]: """ Computes and returns the next {count} date of a given data_frame by querying the date_column_name. This method compares 2 dates of the column date and computes the last one. Arguments - data_frame (pandas.DataFrame) : data frame containing the date column - count (int): number of dates to generate Returns list[datetime] -> next {count} date of the date column """ date_column = self.data[self.date_column_name] date_1 = date_column.array[-2] date_2 = date_column.array[-1] return date.get_next_dates(date_1, date_2, self.number_of_values)
def test_return_empty_list_if_count_is_zero(self): # Given date_1 = datetime(year=1960, month=10, day=2, hour=10, minute=5, second=0) date_2 = datetime(year=1960, month=10, day=2, hour=10, minute=5, second=1) # When actual_next_dates = date.get_next_dates(date_1, date_2, 0) # Then assert [] == actual_next_dates
def test_get_next_date_with_minutes_difference(self): # Given date_1 = datetime(year=1960, month=10, day=2, hour=10, minute=5, second=0) date_2 = datetime(year=1960, month=10, day=2, hour=10, minute=6, second=0) # When actual_next_dates = date.get_next_dates(date_1, date_2, 3) # Then expected_next_date1 = datetime(year=1960, month=10, day=2, hour=10, minute=7, second=0) expected_next_date2 = datetime(year=1960, month=10, day=2, hour=10, minute=8, second=0) expected_next_date3 = datetime(year=1960, month=10, day=2, hour=10, minute=9, second=0) assert [expected_next_date1, expected_next_date2, expected_next_date3] == actual_next_dates
def test_get_next_date_with_months_difference_and_month_is_december(self): # Given date_1 = datetime(year=1960, month=11, day=1, hour=0, minute=0, second=0) date_2 = datetime(year=1960, month=12, day=1, hour=0, minute=0, second=0) # When actual_next_dates = date.get_next_dates(date_1, date_2, 3) # Then expected_next_date1 = datetime(year=1961, month=1, day=1, hour=0, minute=0, second=0) expected_next_date2 = datetime(year=1961, month=2, day=1, hour=0, minute=0, second=0) expected_next_date3 = datetime(year=1961, month=3, day=1, hour=0, minute=0, second=0) assert [expected_next_date1, expected_next_date2, expected_next_date3] == actual_next_dates