Fix coverage with several contract classes; table annotation and file path checks; clean task dir on write
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
This commit is contained in:
164
tasks_gen/eval/G0115/reference/refill_planner.clas.abap
Normal file
164
tasks_gen/eval/G0115/reference/refill_planner.clas.abap
Normal file
@@ -0,0 +1,164 @@
|
||||
CLASS {{p}}refill_planner DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
PUBLIC SECTION.
|
||||
TYPES:
|
||||
ty_machine_id TYPE c LENGTH 8,
|
||||
ty_district TYPE c LENGTH 4,
|
||||
ty_quantity TYPE i,
|
||||
ty_fill_level TYPE i,
|
||||
BEGIN OF ty_machine,
|
||||
machine_id TYPE ty_machine_id,
|
||||
district TYPE ty_district,
|
||||
fill_level TYPE ty_fill_level,
|
||||
END OF ty_machine,
|
||||
tt_machines TYPE STANDARD TABLE OF ty_machine WITH EMPTY KEY,
|
||||
BEGIN OF ty_refill,
|
||||
machine_id TYPE ty_machine_id,
|
||||
quantity TYPE ty_quantity,
|
||||
END OF ty_refill,
|
||||
tt_refills TYPE STANDARD TABLE OF ty_refill WITH EMPTY KEY,
|
||||
BEGIN OF ty_district_summary,
|
||||
district TYPE ty_district,
|
||||
machines TYPE i,
|
||||
quantity TYPE ty_quantity,
|
||||
END OF ty_district_summary,
|
||||
tt_district_summary TYPE STANDARD TABLE OF ty_district_summary WITH EMPTY KEY.
|
||||
|
||||
METHODS add_machine
|
||||
IMPORTING iv_machine_id TYPE ty_machine_id
|
||||
iv_district TYPE ty_district
|
||||
iv_fill_level TYPE ty_fill_level.
|
||||
METHODS add_refill
|
||||
IMPORTING iv_machine_id TYPE ty_machine_id
|
||||
iv_quantity TYPE ty_quantity
|
||||
RETURNING VALUE(rv_accepted) TYPE abap_bool.
|
||||
METHODS get_refill
|
||||
IMPORTING iv_machine_id TYPE ty_machine_id
|
||||
RETURNING VALUE(rv_quantity) TYPE ty_quantity.
|
||||
METHODS machines_below
|
||||
IMPORTING iv_fill_level TYPE ty_fill_level
|
||||
RETURNING VALUE(rt_machines) TYPE tt_machines.
|
||||
METHODS top_refills
|
||||
IMPORTING iv_count TYPE i
|
||||
RETURNING VALUE(rt_refills) TYPE tt_refills.
|
||||
METHODS district_summary
|
||||
RETURNING VALUE(rt_summary) TYPE tt_district_summary.
|
||||
METHODS total_quantity
|
||||
RETURNING VALUE(rv_total) TYPE ty_quantity.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES:
|
||||
BEGIN OF ty_machine_state,
|
||||
machine_id TYPE ty_machine_id,
|
||||
district TYPE ty_district,
|
||||
fill_level TYPE ty_fill_level,
|
||||
quantity TYPE ty_quantity,
|
||||
END OF ty_machine_state,
|
||||
tt_machine_state TYPE HASHED TABLE OF ty_machine_state WITH UNIQUE KEY machine_id.
|
||||
|
||||
DATA mt_machines TYPE tt_machine_state.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}refill_planner IMPLEMENTATION.
|
||||
METHOD add_machine.
|
||||
DATA(lv_machine_id) = to_upper( iv_machine_id ).
|
||||
ASSIGN mt_machines[ machine_id = lv_machine_id ] TO FIELD-SYMBOL(<ls_machine>).
|
||||
IF sy-subrc = 0.
|
||||
<ls_machine>-district = to_upper( iv_district ).
|
||||
<ls_machine>-fill_level = iv_fill_level.
|
||||
ELSE.
|
||||
INSERT VALUE #( machine_id = lv_machine_id
|
||||
district = to_upper( iv_district )
|
||||
fill_level = iv_fill_level
|
||||
quantity = 0 ) INTO TABLE mt_machines.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD add_refill.
|
||||
IF iv_quantity <= 0.
|
||||
rv_accepted = abap_false.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
DATA(lv_machine_id) = to_upper( iv_machine_id ).
|
||||
ASSIGN mt_machines[ machine_id = lv_machine_id ] TO FIELD-SYMBOL(<ls_machine>).
|
||||
IF sy-subrc <> 0.
|
||||
rv_accepted = abap_false.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
<ls_machine>-quantity = <ls_machine>-quantity + iv_quantity.
|
||||
rv_accepted = abap_true.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD get_refill.
|
||||
DATA(lv_machine_id) = to_upper( iv_machine_id ).
|
||||
ASSIGN mt_machines[ machine_id = lv_machine_id ] TO FIELD-SYMBOL(<ls_machine>).
|
||||
IF sy-subrc = 0.
|
||||
rv_quantity = <ls_machine>-quantity.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD machines_below.
|
||||
LOOP AT mt_machines INTO DATA(ls_machine).
|
||||
IF ls_machine-fill_level < iv_fill_level.
|
||||
INSERT VALUE #( machine_id = ls_machine-machine_id
|
||||
district = ls_machine-district
|
||||
fill_level = ls_machine-fill_level ) INTO TABLE rt_machines.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
SORT rt_machines BY fill_level machine_id.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD top_refills.
|
||||
DATA lv_index TYPE i.
|
||||
DATA lt_refills TYPE tt_refills.
|
||||
IF iv_count <= 0.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
LOOP AT mt_machines INTO DATA(ls_machine).
|
||||
IF ls_machine-quantity > 0.
|
||||
INSERT VALUE #( machine_id = ls_machine-machine_id
|
||||
quantity = ls_machine-quantity ) INTO TABLE lt_refills.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
SORT lt_refills BY quantity DESCENDING machine_id ASCENDING.
|
||||
LOOP AT lt_refills INTO DATA(ls_refill).
|
||||
lv_index = lv_index + 1.
|
||||
IF lv_index > iv_count.
|
||||
EXIT.
|
||||
ENDIF.
|
||||
INSERT ls_refill INTO TABLE rt_refills.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD district_summary.
|
||||
TYPES:
|
||||
BEGIN OF ty_district_state,
|
||||
district TYPE ty_district,
|
||||
machines TYPE i,
|
||||
quantity TYPE ty_quantity,
|
||||
END OF ty_district_state,
|
||||
tt_district_state TYPE HASHED TABLE OF ty_district_state WITH UNIQUE KEY district.
|
||||
DATA lt_districts TYPE tt_district_state.
|
||||
LOOP AT mt_machines INTO DATA(ls_machine).
|
||||
ASSIGN lt_districts[ district = ls_machine-district ] TO FIELD-SYMBOL(<ls_district>).
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE #( district = ls_machine-district )
|
||||
INTO TABLE lt_districts ASSIGNING <ls_district>.
|
||||
ENDIF.
|
||||
<ls_district>-machines = <ls_district>-machines + 1.
|
||||
<ls_district>-quantity = <ls_district>-quantity + ls_machine-quantity.
|
||||
ENDLOOP.
|
||||
LOOP AT lt_districts INTO DATA(ls_district).
|
||||
INSERT VALUE #( district = ls_district-district
|
||||
machines = ls_district-machines
|
||||
quantity = ls_district-quantity ) INTO TABLE rt_summary.
|
||||
ENDLOOP.
|
||||
SORT rt_summary BY district.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD total_quantity.
|
||||
LOOP AT mt_machines INTO DATA(ls_machine).
|
||||
rv_total = rv_total + ls_machine-quantity.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,93 @@
|
||||
CLASS ltc_refill_planner DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
DATA mo_cut TYPE REF TO {{p}}refill_planner.
|
||||
METHODS setup.
|
||||
METHODS adds_machine FOR TESTING.
|
||||
METHODS replaces_machine FOR TESTING.
|
||||
METHODS accumulates_refill FOR TESTING.
|
||||
METHODS rejects_bad_quantity FOR TESTING.
|
||||
METHODS ignores_unknown_machine FOR TESTING.
|
||||
METHODS sorts_low_fill_level FOR TESTING.
|
||||
METHODS ranks_largest_refills FOR TESTING.
|
||||
METHODS sums_per_district FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltc_refill_planner IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}refill_planner( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD adds_machine.
|
||||
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
||||
DATA(lt_machines) = mo_cut->machines_below( 50 ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_machines ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD replaces_machine.
|
||||
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
||||
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D2' iv_fill_level = 20 ).
|
||||
DATA(lt_machines) = mo_cut->machines_below( 50 ).
|
||||
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 ).
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD accumulates_refill.
|
||||
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
||||
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 5 ).
|
||||
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 rejects_bad_quantity.
|
||||
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 ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD ignores_unknown_machine.
|
||||
cl_abap_unit_assert=>assert_equals( exp = abap_false
|
||||
act = mo_cut->add_refill( iv_machine_id = 'M9' iv_quantity = 5 ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sorts_low_fill_level.
|
||||
DATA lv_position TYPE i.
|
||||
mo_cut->add_machine( iv_machine_id = 'M2' iv_district = 'D1' iv_fill_level = 20 ).
|
||||
mo_cut->add_machine( iv_machine_id = 'M1' iv_district = 'D1' iv_fill_level = 10 ).
|
||||
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 ).
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD ranks_largest_refills.
|
||||
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 = 'D1' iv_fill_level = 10 ).
|
||||
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 3 ).
|
||||
mo_cut->add_refill( iv_machine_id = 'M2' iv_quantity = 8 ).
|
||||
DATA(lt_refills) = mo_cut->top_refills( 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_refills ) ).
|
||||
LOOP AT lt_refills INTO DATA(ls_refill).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'M2' act = ls_refill-machine_id ).
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sums_per_district.
|
||||
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 = 'D1' iv_fill_level = 10 ).
|
||||
mo_cut->add_refill( iv_machine_id = 'M1' iv_quantity = 3 ).
|
||||
mo_cut->add_refill( iv_machine_id = 'M2' iv_quantity = 8 ).
|
||||
DATA(lt_summary) = mo_cut->district_summary( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_summary ) ).
|
||||
LOOP AT lt_summary INTO DATA(ls_row).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = ls_row-machines ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 11 act = ls_row-quantity ).
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user