Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
152 lines
7.2 KiB
ABAP
152 lines
7.2 KiB
ABAP
CLASS {{p}}refill_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}refill_planner.
|
|
METHODS setup.
|
|
METHODS adds_and_replaces FOR TESTING.
|
|
METHODS ids_are_upper_case FOR TESTING.
|
|
METHODS rejects_zero_qty FOR TESTING.
|
|
METHODS unknown_machine FOR TESTING.
|
|
METHODS refill_accumulates FOR TESTING.
|
|
METHODS sorts_by_fill FOR TESTING.
|
|
METHODS fill_level_boundary FOR TESTING.
|
|
METHODS top_by_quantity FOR TESTING.
|
|
METHODS district_totals FOR TESTING.
|
|
METHODS total_quantity FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}refill_hidden IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}refill_planner( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD adds_and_replaces.
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 20 ).
|
|
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 5 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D2' iv_fill_level = 30 ).
|
|
DATA(lt_machines) = mo_cut->machines_below( 100 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_machines ) ).
|
|
LOOP AT lt_machines INTO DATA(ls_machine).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'D2' act = ls_machine-district ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 30 act = ls_machine-fill_level ).
|
|
ENDLOOP.
|
|
cl_abap_unit_assert=>assert_equals( exp = 5 act = mo_cut->get_refill( 'M1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD ids_are_upper_case.
|
|
mo_cut->add_machine( iv_machine_id = 'm1' iv_district = 'd1' iv_fill_level = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_true
|
|
act = mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 4 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 4 act = mo_cut->get_refill( 'm1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rejects_zero_qty.
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false
|
|
act = mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 0 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false
|
|
act = mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = -3 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = mo_cut->get_refill( 'M1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_machine.
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false
|
|
act = mo_cut->add_refill( iv_machine_id = 'M9' iv_quantity = 5 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = mo_cut->get_refill( 'M9' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD refill_accumulates.
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_true
|
|
act = mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 5 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_true
|
|
act = mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 7 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 12 act = mo_cut->get_refill( 'M1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD sorts_by_fill.
|
|
DATA lv_position TYPE i.
|
|
mo_cut->add_machine( iv_machine_id = 'M3' iv_district = 'D1' iv_fill_level = 30 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D2' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M2' iv_district = 'D1' iv_fill_level = 20 ).
|
|
DATA(lt_machines) = mo_cut->machines_below( 25 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_machines ) ).
|
|
LOOP AT lt_machines INTO DATA(ls_machine).
|
|
lv_position = lv_position + 1.
|
|
IF lv_position = 1.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'M1' act = ls_machine-machine_id ).
|
|
ELSEIF lv_position = 2.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'M2' act = ls_machine-machine_id ).
|
|
ENDIF.
|
|
ENDLOOP.
|
|
ENDMETHOD.
|
|
|
|
METHOD fill_level_boundary.
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 20 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M2' iv_district = 'D1' iv_fill_level = 19 ).
|
|
DATA(lt_below_20) = mo_cut->machines_below( 20 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_below_20 ) ).
|
|
DATA(lt_below_0) = mo_cut->machines_below( 0 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( lt_below_0 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD top_by_quantity.
|
|
DATA lv_position TYPE i.
|
|
mo_cut->add_machine( iv_machine_id = 'MA' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'MB' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'MC' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'MD' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_refill( iv_machine_id = 'MA' iv_quantity = 5 ).
|
|
mo_cut->add_refill( iv_machine_id = 'MB' iv_quantity = 9 ).
|
|
mo_cut->add_refill( iv_machine_id = 'MC' iv_quantity = 9 ).
|
|
mo_cut->add_refill( iv_machine_id = 'MD' iv_quantity = 1 ).
|
|
DATA(lt_top) = mo_cut->top_refills( 2 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_top ) ).
|
|
LOOP AT lt_top INTO DATA(ls_refill).
|
|
lv_position = lv_position + 1.
|
|
IF lv_position = 1.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'MB' act = ls_refill-machine_id ).
|
|
ELSEIF lv_position = 2.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'MC' act = ls_refill-machine_id ).
|
|
ENDIF.
|
|
ENDLOOP.
|
|
DATA(lt_all) = mo_cut->top_refills( 99 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 4 act = lines( lt_all ) ).
|
|
DATA(lt_none) = mo_cut->top_refills( 0 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( lt_none ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD district_totals.
|
|
DATA lv_position TYPE i.
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D2' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M2' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M3' iv_district = 'D2' iv_fill_level = 10 ).
|
|
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 4 ).
|
|
mo_cut->add_refill( iv_machine_id = 'M2' iv_quantity = 6 ).
|
|
DATA(lt_summary) = mo_cut->district_summary( ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_summary ) ).
|
|
LOOP AT lt_summary INTO DATA(ls_row).
|
|
lv_position = lv_position + 1.
|
|
IF lv_position = 1.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'D1' act = ls_row-district ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = ls_row-machines ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 6 act = ls_row-quantity ).
|
|
ELSEIF lv_position = 2.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'D2' act = ls_row-district ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = ls_row-machines ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 4 act = ls_row-quantity ).
|
|
ENDIF.
|
|
ENDLOOP.
|
|
ENDMETHOD.
|
|
|
|
METHOD total_quantity.
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = mo_cut->total_quantity( ) ).
|
|
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
|
mo_cut->add_machine( iv_machine_id = 'M2' iv_district = 'D2' iv_fill_level = 10 ).
|
|
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 5 ).
|
|
mo_cut->add_refill( iv_machine_id = 'M2' iv_quantity = 8 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 13 act = mo_cut->total_quantity( ) ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|