249 lines
9.1 KiB
ABAP
249 lines
9.1 KiB
ABAP
CLASS {{P}}T14_HIDDEN DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS line_for
|
|
IMPORTING iv_donor TYPE string
|
|
iv_group TYPE string
|
|
iv_units TYPE i
|
|
RETURNING VALUE(rv_line) TYPE string.
|
|
|
|
METHODS sum_for
|
|
IMPORTING iv_donations TYPE string
|
|
iv_start TYPE string OPTIONAL
|
|
EXPORTING ev_totals TYPE string
|
|
ev_count TYPE i
|
|
ev_subrc TYPE sysubrc.
|
|
|
|
METHODS sums_per_group FOR TESTING.
|
|
METHODS counts_donors FOR TESTING.
|
|
METHODS sorted_result FOR TESTING.
|
|
METHODS upper_case_group FOR TESTING.
|
|
METHODS replaces_content FOR TESTING.
|
|
METHODS empty_input FOR TESTING.
|
|
METHODS invalid_units_raises FOR TESTING.
|
|
METHODS invalid_keeps_totals FOR TESTING.
|
|
METHODS donor_two_groups FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{P}}T14_HIDDEN IMPLEMENTATION.
|
|
|
|
METHOD line_for.
|
|
rv_line = iv_donor && ';' && iv_group && ';' && |{ iv_units }|.
|
|
ENDMETHOD.
|
|
|
|
METHOD sum_for.
|
|
DATA lv_totals TYPE string.
|
|
lv_totals = iv_start.
|
|
|
|
CALL FUNCTION '{{P}}DON_SUM'
|
|
EXPORTING
|
|
iv_donations = iv_donations
|
|
IMPORTING
|
|
ev_donor_count = ev_count
|
|
CHANGING
|
|
cv_totals = lv_totals
|
|
EXCEPTIONS
|
|
invalid_units = 1
|
|
OTHERS = 2.
|
|
|
|
ev_subrc = sy-subrc.
|
|
ev_totals = lv_totals.
|
|
ENDMETHOD.
|
|
|
|
METHOD sums_per_group.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 3 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'O-' iv_units = 1 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 5 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'O-' iv_units = 1 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD counts_donors.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D3' iv_group = 'B' iv_units = 1 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D3' iv_group = 'B' iv_units = 1 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD sorted_result.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D2' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 1 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 1 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'A+' iv_units = 1 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD upper_case_group.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'a+' iv_units = 2 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 3 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 5 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD replaces_content.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
iv_start = 'OLD TOTALS'
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_input.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
sum_for( EXPORTING iv_donations = ''
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = '' act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD invalid_units_raises.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 0 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_subrc ).
|
|
ENDMETHOD.
|
|
|
|
METHOD invalid_keeps_totals.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D2' iv_group = 'A+' iv_units = 0 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
iv_start = 'KEEP'
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'KEEP' act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD donor_two_groups.
|
|
DATA lv_actual TYPE string.
|
|
DATA lv_count TYPE i.
|
|
DATA lv_subrc TYPE sysubrc.
|
|
|
|
DATA(lv_input) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 3 ).
|
|
|
|
sum_for( EXPORTING iv_donations = lv_input
|
|
IMPORTING ev_totals = lv_actual
|
|
ev_count = lv_count
|
|
ev_subrc = lv_subrc ).
|
|
|
|
DATA(lv_expected) = line_for( iv_donor = 'D1' iv_group = 'A+' iv_units = 2 )
|
|
&& cl_abap_char_utilities=>newline
|
|
&& line_for( iv_donor = 'D1' iv_group = 'O-' iv_units = 3 ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = lv_actual ).
|
|
ENDMETHOD.
|
|
|
|
ENDCLASS.
|