133 lines
4.6 KiB
ABAP
133 lines
4.6 KiB
ABAP
CLASS {{p}}t02_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
|
|
PRIVATE SECTION.
|
|
CONSTANTS:
|
|
c_fri_05 TYPE d VALUE '20240105',
|
|
c_sat_06 TYPE d VALUE '20240106',
|
|
c_sun_07 TYPE d VALUE '20240107',
|
|
c_mon_08 TYPE d VALUE '20240108',
|
|
c_tue_09 TYPE d VALUE '20240109',
|
|
c_wed_10 TYPE d VALUE '20240110',
|
|
c_thu_11 TYPE d VALUE '20240111',
|
|
c_fri_12 TYPE d VALUE '20240112'.
|
|
|
|
DATA mo_cut TYPE REF TO {{p}}delivery_schedule.
|
|
DATA mt_holidays TYPE {{p}}delivery_schedule=>ty_holidays.
|
|
DATA mt_no_holidays TYPE {{p}}delivery_schedule=>ty_holidays.
|
|
|
|
METHODS setup.
|
|
METHODS weekend_is_not_working FOR TESTING.
|
|
METHODS working_day_is_true FOR TESTING.
|
|
METHODS holiday_is_not_working FOR TESTING.
|
|
METHODS next_day_same_for_workday FOR TESTING.
|
|
METHODS next_day_from_weekend FOR TESTING.
|
|
METHODS next_day_skips_holidays FOR TESTING.
|
|
METHODS add_zero_days FOR TESTING.
|
|
METHODS add_days_forward FOR TESTING.
|
|
METHODS add_forward_skips_holiday FOR TESTING.
|
|
METHODS add_days_backward FOR TESTING.
|
|
METHODS count_working_days_inclusive FOR TESTING.
|
|
METHODS count_reversed_range_is_zero FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t02_hidden IMPLEMENTATION.
|
|
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}delivery_schedule( ).
|
|
mt_holidays = VALUE #( ( c_tue_09 ) ( c_wed_10 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD weekend_is_not_working.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = abap_false
|
|
act = mo_cut->is_working_day( iv_date = c_sat_06 it_holidays = mt_no_holidays )
|
|
msg = 'Saturday is not a working day' ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = abap_false
|
|
act = mo_cut->is_working_day( iv_date = c_sun_07 it_holidays = mt_no_holidays )
|
|
msg = 'Sunday is not a working day' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD working_day_is_true.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = abap_true
|
|
act = mo_cut->is_working_day( iv_date = c_mon_08 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD holiday_is_not_working.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = abap_false
|
|
act = mo_cut->is_working_day( iv_date = c_tue_09 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD next_day_same_for_workday.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_mon_08
|
|
act = mo_cut->next_working_day( iv_date = c_mon_08 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD next_day_from_weekend.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_mon_08
|
|
act = mo_cut->next_working_day( iv_date = c_sat_06 it_holidays = mt_no_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD next_day_skips_holidays.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_thu_11
|
|
act = mo_cut->next_working_day( iv_date = c_tue_09 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD add_zero_days.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_sat_06
|
|
act = mo_cut->add_working_days( iv_start = c_sat_06 iv_days = 0 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD add_days_forward.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_tue_09
|
|
act = mo_cut->add_working_days( iv_start = c_fri_05 iv_days = 2 it_holidays = mt_no_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD add_forward_skips_holiday.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_thu_11
|
|
act = mo_cut->add_working_days( iv_start = c_fri_05 iv_days = 2 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD add_days_backward.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = c_fri_05
|
|
act = mo_cut->add_working_days( iv_start = c_mon_08 iv_days = -1 it_holidays = mt_no_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD count_working_days_inclusive.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 5
|
|
act = mo_cut->count_working_days( iv_from = c_mon_08 iv_to = c_fri_12 it_holidays = mt_no_holidays )
|
|
msg = 'Monday to Friday without holidays' ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 3
|
|
act = mo_cut->count_working_days( iv_from = c_mon_08 iv_to = c_fri_12 it_holidays = mt_holidays )
|
|
msg = 'Two holidays in the interval' ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 1
|
|
act = mo_cut->count_working_days( iv_from = c_mon_08 iv_to = c_mon_08 it_holidays = mt_no_holidays )
|
|
msg = 'One working day' ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 0
|
|
act = mo_cut->count_working_days( iv_from = c_tue_09 iv_to = c_tue_09 it_holidays = mt_holidays )
|
|
msg = 'One holiday' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD count_reversed_range_is_zero.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 0
|
|
act = mo_cut->count_working_days( iv_from = c_fri_12 iv_to = c_mon_08 it_holidays = mt_holidays ) ).
|
|
ENDMETHOD.
|
|
|
|
ENDCLASS.
|