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:
29
tasks_gen/eval/G0122/generation.json
Normal file
29
tasks_gen/eval/G0122/generation.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"id": "G0122",
|
||||
"pool": "eval",
|
||||
"object_type": "FUNC",
|
||||
"category": "C",
|
||||
"attempts": [
|
||||
{
|
||||
"stage": "validate",
|
||||
"oracle": null,
|
||||
"null": null
|
||||
},
|
||||
{
|
||||
"stage": "validate",
|
||||
"oracle": 0,
|
||||
"null": 0
|
||||
},
|
||||
{
|
||||
"stage": "validate",
|
||||
"oracle": 0,
|
||||
"null": 0
|
||||
},
|
||||
{
|
||||
"stage": "validate",
|
||||
"oracle": 0,
|
||||
"null": 0
|
||||
}
|
||||
],
|
||||
"accepted": false
|
||||
}
|
||||
302
tasks_gen/eval/G0122/hidden/t31_hidden.clas.abap
Normal file
302
tasks_gen/eval/G0122/hidden/t31_hidden.clas.abap
Normal file
@@ -0,0 +1,302 @@
|
||||
CLASS {{p}}t31_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_stations TYPE STANDARD TABLE OF {{p}}station.
|
||||
TYPES ty_moves TYPE STANDARD TABLE OF {{p}}move.
|
||||
TYPES ty_id TYPE {{p}}station-station_id.
|
||||
TYPES ty_name TYPE {{p}}station-station_name.
|
||||
|
||||
METHODS given
|
||||
IMPORTING it_stations TYPE ty_stations
|
||||
it_moves TYPE ty_moves.
|
||||
|
||||
METHODS rebalance
|
||||
IMPORTING iv_dry_run TYPE abap_bool DEFAULT abap_false
|
||||
EXPORTING ev_applied TYPE i
|
||||
ev_rejected TYPE i.
|
||||
|
||||
METHODS bikes_of
|
||||
IMPORTING iv_id TYPE ty_id
|
||||
RETURNING VALUE(rv_bikes) TYPE i.
|
||||
|
||||
METHODS name_of
|
||||
IMPORTING iv_id TYPE ty_id
|
||||
RETURNING VALUE(rv_name) TYPE ty_name.
|
||||
|
||||
METHODS applies_one_move FOR TESTING.
|
||||
METHODS applies_in_move_order FOR TESTING.
|
||||
METHODS rejects_unknown_station FOR TESTING.
|
||||
METHODS rejects_insufficient_bikes FOR TESTING.
|
||||
METHODS rejects_full_target FOR TESTING.
|
||||
METHODS rejects_non_positive_qty FOR TESTING.
|
||||
METHODS rejects_same_station FOR TESTING.
|
||||
METHODS counts_rejections FOR TESTING.
|
||||
METHODS keeps_untouched_stations FOR TESTING.
|
||||
METHODS dry_run_keeps_state FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}t31_hidden IMPLEMENTATION.
|
||||
|
||||
METHOD given.
|
||||
DATA(lt_stations) = it_stations.
|
||||
DATA(lt_moves) = it_moves.
|
||||
|
||||
LOOP AT lt_stations ASSIGNING FIELD-SYMBOL(<ls_station>).
|
||||
<ls_station>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
LOOP AT lt_moves ASSIGNING FIELD-SYMBOL(<ls_move>).
|
||||
<ls_move>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
DELETE FROM {{p}}station.
|
||||
DELETE FROM {{p}}move.
|
||||
INSERT {{p}}station FROM TABLE @lt_stations.
|
||||
INSERT {{p}}move FROM TABLE @lt_moves.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rebalance.
|
||||
CALL FUNCTION '{{P}}BIKE_REBALANCE'
|
||||
EXPORTING
|
||||
iv_dry_run = iv_dry_run
|
||||
IMPORTING
|
||||
ev_applied = ev_applied
|
||||
ev_rejected = ev_rejected
|
||||
EXCEPTIONS
|
||||
OTHERS = 1.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD bikes_of.
|
||||
SELECT SINGLE bikes FROM {{p}}station
|
||||
INTO @rv_bikes
|
||||
WHERE station_id = @iv_id.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD name_of.
|
||||
SELECT SINGLE station_name FROM {{p}}station
|
||||
INTO @rv_name
|
||||
WHERE station_id = @iv_id.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD applies_one_move.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 6 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 1 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 4 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 2 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 5 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD applies_in_move_order.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 )
|
||||
( station_id = 'S003' station_name = 'Gamma' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 2 source_id = 'S001' target_id = 'S002' quantity = 5 )
|
||||
( move_no = 1 source_id = 'S002' target_id = 'S003' quantity = 5 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S003' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_unknown_station.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 6 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S009' target_id = 'S001' quantity = 2 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 6 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_insufficient_bikes.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 2 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 5 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 2 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_full_target.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 4 bikes = 4 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 1 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 4 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_non_positive_qty.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 0 )
|
||||
( move_no = 2 source_id = 'S001' target_id = 'S002' quantity = -3 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 2 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_same_station.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S001' quantity = 2 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 5 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD counts_rejections.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 2 )
|
||||
( move_no = 2 source_id = 'S001' target_id = 'S999' quantity = 1 )
|
||||
( move_no = 3 source_id = 'S001' target_id = 'S002' quantity = 0 )
|
||||
( move_no = 4 source_id = 'S001' target_id = 'S002' quantity = 100 )
|
||||
( move_no = 5 source_id = 'S002' target_id = 'S001' quantity = 1 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 2 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 3 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 4 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 1 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD keeps_untouched_stations.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 4 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 4 )
|
||||
( station_id = 'S003' station_name = 'Gamma' capacity = 12 bikes = 7 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 1 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 3 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S003' ) exp = 7 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = name_of( 'S003' ) exp = CONV ty_name( 'Gamma' ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD dry_run_keeps_state.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 3 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( EXPORTING iv_dry_run = abap_true
|
||||
IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
65
tasks_gen/eval/G0122/reference/bike_rebalance.func.abap
Normal file
65
tasks_gen/eval/G0122/reference/bike_rebalance.func.abap
Normal file
@@ -0,0 +1,65 @@
|
||||
FUNCTION {{p}}bike_rebalance
|
||||
IMPORTING
|
||||
iv_dry_run TYPE abap_bool
|
||||
EXPORTING
|
||||
ev_applied TYPE i
|
||||
ev_rejected TYPE i.
|
||||
|
||||
DATA lt_state TYPE STANDARD TABLE OF {{p}}station.
|
||||
DATA lt_moves TYPE STANDARD TABLE OF {{p}}move.
|
||||
|
||||
SELECT station_id, station_name, capacity, bikes
|
||||
FROM {{p}}station
|
||||
INTO TABLE @lt_state.
|
||||
|
||||
SELECT move_no, source_id, target_id, quantity
|
||||
FROM {{p}}move
|
||||
INTO TABLE @lt_moves.
|
||||
|
||||
SORT lt_state BY station_id.
|
||||
SORT lt_moves BY move_no.
|
||||
|
||||
ev_applied = 0.
|
||||
ev_rejected = 0.
|
||||
|
||||
LOOP AT lt_moves INTO DATA(ls_move).
|
||||
IF ls_move-quantity <= 0
|
||||
OR ls_move-source_id = ls_move-target_id.
|
||||
ev_rejected = ev_rejected + 1.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
|
||||
READ TABLE lt_state ASSIGNING FIELD-SYMBOL(<ls_source>)
|
||||
WITH KEY station_id = ls_move-source_id BINARY SEARCH.
|
||||
IF sy-subrc <> 0.
|
||||
ev_rejected = ev_rejected + 1.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
|
||||
READ TABLE lt_state ASSIGNING FIELD-SYMBOL(<ls_target>)
|
||||
WITH KEY station_id = ls_move-target_id BINARY SEARCH.
|
||||
IF sy-subrc <> 0.
|
||||
ev_rejected = ev_rejected + 1.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
|
||||
IF <ls_source>-bikes < ls_move-quantity
|
||||
OR <ls_target>-capacity - <ls_target>-bikes < ls_move-quantity.
|
||||
ev_rejected = ev_rejected + 1.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
|
||||
<ls_source>-bikes = <ls_source>-bikes - ls_move-quantity.
|
||||
<ls_target>-bikes = <ls_target>-bikes + ls_move-quantity.
|
||||
ev_applied = ev_applied + 1.
|
||||
ENDLOOP.
|
||||
|
||||
IF iv_dry_run = abap_false.
|
||||
LOOP AT lt_state INTO DATA(ls_state).
|
||||
UPDATE {{p}}station
|
||||
SET bikes = @ls_state-bikes
|
||||
WHERE station_id = @ls_state-station_id.
|
||||
ENDLOOP.
|
||||
ENDIF.
|
||||
|
||||
ENDFUNCTION.
|
||||
130
tasks_gen/eval/G0122/reference/t31_test.clas.abap
Normal file
130
tasks_gen/eval/G0122/reference/t31_test.clas.abap
Normal file
@@ -0,0 +1,130 @@
|
||||
CLASS {{p}}t31_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_stations TYPE STANDARD TABLE OF {{p}}station.
|
||||
TYPES ty_moves TYPE STANDARD TABLE OF {{p}}move.
|
||||
TYPES ty_id TYPE {{p}}station-station_id.
|
||||
|
||||
METHODS given
|
||||
IMPORTING it_stations TYPE ty_stations
|
||||
it_moves TYPE ty_moves.
|
||||
|
||||
METHODS rebalance
|
||||
IMPORTING iv_dry_run TYPE abap_bool DEFAULT abap_false
|
||||
EXPORTING ev_applied TYPE i
|
||||
ev_rejected TYPE i.
|
||||
|
||||
METHODS bikes_of
|
||||
IMPORTING iv_id TYPE ty_id
|
||||
RETURNING VALUE(rv_bikes) TYPE i.
|
||||
|
||||
METHODS applies_move FOR TESTING.
|
||||
METHODS rejects_move FOR TESTING.
|
||||
METHODS dry_run FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}t31_test IMPLEMENTATION.
|
||||
|
||||
METHOD given.
|
||||
DATA(lt_stations) = it_stations.
|
||||
DATA(lt_moves) = it_moves.
|
||||
|
||||
LOOP AT lt_stations ASSIGNING FIELD-SYMBOL(<ls_station>).
|
||||
<ls_station>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
LOOP AT lt_moves ASSIGNING FIELD-SYMBOL(<ls_move>).
|
||||
<ls_move>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
DELETE FROM {{p}}station.
|
||||
DELETE FROM {{p}}move.
|
||||
INSERT {{p}}station FROM TABLE @lt_stations.
|
||||
INSERT {{p}}move FROM TABLE @lt_moves.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rebalance.
|
||||
CALL FUNCTION '{{P}}BIKE_REBALANCE'
|
||||
EXPORTING
|
||||
iv_dry_run = iv_dry_run
|
||||
IMPORTING
|
||||
ev_applied = ev_applied
|
||||
ev_rejected = ev_rejected
|
||||
EXCEPTIONS
|
||||
OTHERS = 1.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD bikes_of.
|
||||
SELECT SINGLE bikes FROM {{p}}station
|
||||
INTO @rv_bikes
|
||||
WHERE station_id = @iv_id.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD applies_move.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 3 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 2 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 3 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD rejects_move.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 1 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 4 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD dry_run.
|
||||
DATA lt_stations TYPE ty_stations.
|
||||
DATA lt_moves TYPE ty_moves.
|
||||
DATA lv_applied TYPE i.
|
||||
DATA lv_rejected TYPE i.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Alpha' capacity = 10 bikes = 5 )
|
||||
( station_id = 'S002' station_name = 'Beta' capacity = 10 bikes = 0 ) ).
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 2 ) ).
|
||||
|
||||
given( it_stations = lt_stations it_moves = lt_moves ).
|
||||
rebalance( EXPORTING iv_dry_run = abap_true
|
||||
IMPORTING ev_applied = lv_applied ev_rejected = lv_rejected ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_applied exp = 1 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = lv_rejected exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S001' ) exp = 5 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = bikes_of( 'S002' ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
12
tasks_gen/eval/G0122/seed/move.tabl.abap
Normal file
12
tasks_gen/eval/G0122/seed/move.tabl.abap
Normal file
@@ -0,0 +1,12 @@
|
||||
@EndUserText.label : 'Planned bike move'
|
||||
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
|
||||
@AbapCatalog.tableCategory : #TRANSPARENT
|
||||
@AbapCatalog.deliveryClass : #A
|
||||
@AbapCatalog.dataMaintenance : #RESTRICTED
|
||||
define table {{p}}move {
|
||||
key client : abap.clnt not null;
|
||||
key move_no : abap.int4 not null;
|
||||
source_id : abap.char(6) not null;
|
||||
target_id : abap.char(6) not null;
|
||||
quantity : abap.int4 not null;
|
||||
}
|
||||
39
tasks_gen/eval/G0122/seed/seed_bike.clas.abap
Normal file
39
tasks_gen/eval/G0122/seed/seed_bike.clas.abap
Normal file
@@ -0,0 +1,39 @@
|
||||
CLASS {{p}}seed_bike DEFINITION
|
||||
PUBLIC FINAL CREATE PUBLIC.
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}seed_bike IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
DATA lt_stations TYPE STANDARD TABLE OF {{p}}station.
|
||||
DATA lt_moves TYPE STANDARD TABLE OF {{p}}move.
|
||||
|
||||
lt_stations = VALUE #(
|
||||
( station_id = 'S001' station_name = 'Central Square' capacity = 20 bikes = 12 )
|
||||
( station_id = 'S002' station_name = 'Harbour' capacity = 15 bikes = 3 )
|
||||
( station_id = 'S003' station_name = 'Main Station' capacity = 10 bikes = 10 ) ).
|
||||
|
||||
lt_moves = VALUE #(
|
||||
( move_no = 1 source_id = 'S001' target_id = 'S002' quantity = 4 )
|
||||
( move_no = 2 source_id = 'S002' target_id = 'S003' quantity = 2 ) ).
|
||||
|
||||
LOOP AT lt_stations ASSIGNING FIELD-SYMBOL(<ls_station>).
|
||||
<ls_station>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
LOOP AT lt_moves ASSIGNING FIELD-SYMBOL(<ls_move>).
|
||||
<ls_move>-client = sy-mandt.
|
||||
ENDLOOP.
|
||||
|
||||
DELETE FROM {{p}}station.
|
||||
INSERT {{p}}station FROM TABLE @lt_stations.
|
||||
|
||||
DELETE FROM {{p}}move.
|
||||
INSERT {{p}}move FROM TABLE @lt_moves.
|
||||
|
||||
out->write( 'Bike sharing sample data inserted.' ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
12
tasks_gen/eval/G0122/seed/station.tabl.abap
Normal file
12
tasks_gen/eval/G0122/seed/station.tabl.abap
Normal file
@@ -0,0 +1,12 @@
|
||||
@EndUserText.label : 'Bike station'
|
||||
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
|
||||
@AbapCatalog.tableCategory : #TRANSPARENT
|
||||
@AbapCatalog.deliveryClass : #A
|
||||
@AbapCatalog.dataMaintenance : #RESTRICTED
|
||||
define table {{p}}station {
|
||||
key client : abap.clnt not null;
|
||||
key station_id : abap.char(6) not null;
|
||||
station_name : abap.char(30) not null;
|
||||
capacity : abap.int4 not null;
|
||||
bikes : abap.int4 not null;
|
||||
}
|
||||
85
tasks_gen/eval/G0122/spec.md
Normal file
85
tasks_gen/eval/G0122/spec.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# 1. Goal
|
||||
|
||||
A bike-sharing operator moves bikes between its stations. A background job
|
||||
calls one function module to apply the planned moves of the operator. The
|
||||
function module reads the planned moves and the current state of the stations
|
||||
from the database, applies the moves, and writes the new state of the stations
|
||||
back to the database. The function module returns the number of applied moves
|
||||
and the number of rejected moves.
|
||||
|
||||
# 2. Open questions
|
||||
|
||||
None.
|
||||
|
||||
# 3. Context
|
||||
|
||||
- Function group {{P}}FG_BIKE exists in package $TMP.
|
||||
- Table {{P}}STATION exists in package $TMP. It holds the current state of the
|
||||
stations of the operator. The table is client-dependent.
|
||||
- Table {{P}}MOVE exists in package $TMP. It holds the planned moves. The table
|
||||
is client-dependent.
|
||||
- The station IDs in {{P}}STATION are unique. The move numbers in {{P}}MOVE are
|
||||
unique.
|
||||
- The function module reads and changes the two tables. It works on the data of
|
||||
the current client.
|
||||
|
||||
# 4. Contract
|
||||
|
||||
Function module {{P}}BIKE_REBALANCE in the function group {{P}}FG_BIKE:
|
||||
|
||||
IMPORTING
|
||||
iv_dry_run TYPE abap_bool
|
||||
EXPORTING
|
||||
ev_applied TYPE i
|
||||
ev_rejected TYPE i
|
||||
|
||||
Table {{P}}STATION:
|
||||
|
||||
client (key)
|
||||
station_id (key) TYPE c LENGTH 6
|
||||
station_name TYPE c LENGTH 30
|
||||
capacity TYPE i
|
||||
bikes TYPE i
|
||||
|
||||
Table {{P}}MOVE:
|
||||
|
||||
client (key)
|
||||
move_no (key) TYPE i
|
||||
source_id TYPE c LENGTH 6
|
||||
target_id TYPE c LENGTH 6
|
||||
quantity TYPE i
|
||||
|
||||
# 5. Business rules
|
||||
|
||||
1. Read all rows of {{P}}STATION and all rows of {{P}}MOVE.
|
||||
2. Apply the moves in ascending order of move_no. Do not apply them in the
|
||||
order of the table.
|
||||
3. A move is rejected if at least one of these conditions is true:
|
||||
- quantity is less than or equal to 0;
|
||||
- source_id and target_id are equal;
|
||||
- source_id is not the ID of a station in {{P}}STATION;
|
||||
- target_id is not the ID of a station in {{P}}STATION;
|
||||
- the source station has fewer bikes than quantity;
|
||||
- the target station has fewer free docks than quantity. The free docks of
|
||||
a station are capacity minus bikes.
|
||||
4. A rejected move does not change any station.
|
||||
5. An accepted move subtracts quantity from the bikes of the source station
|
||||
and adds quantity to the bikes of the target station.
|
||||
6. After the last move, the function module writes the new bikes value of the
|
||||
stations back to {{P}}STATION. station_name and capacity do not change.
|
||||
7. If iv_dry_run is true, the function module does not change {{P}}STATION.
|
||||
8. ev_applied is the number of accepted moves. ev_rejected is the number of
|
||||
rejected moves. Both numbers are also returned if iv_dry_run is true.
|
||||
|
||||
# 6. Constraints
|
||||
|
||||
- Release target: SAP_BASIS 816 (ABAP Platform 2025).
|
||||
- Package: $TMP. Do not create a transport request.
|
||||
- Clean ABAP. Keep the function module and every method below 40 statements.
|
||||
- Out of scope: do not change {{P}}STATION, {{P}}MOVE and {{P}}SEED_BIKE.
|
||||
|
||||
# 7. Acceptance
|
||||
|
||||
- The function module is active and has no syntax error.
|
||||
- The hidden tests pass.
|
||||
- Write ABAP Unit tests for the function module in a global test class.
|
||||
90
tasks_gen/eval/G0122/task.json
Normal file
90
tasks_gen/eval/G0122/task.json
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"id": "G0122",
|
||||
"category": "C",
|
||||
"object_type": "FUNC",
|
||||
"difficulty": 2,
|
||||
"release_target": "v816",
|
||||
"expected_outcome": "implement",
|
||||
"budget": {
|
||||
"max_tool_calls": 40,
|
||||
"max_activations": 10
|
||||
},
|
||||
"seed": [
|
||||
{
|
||||
"type": "TABL",
|
||||
"name": "{{P}}STATION",
|
||||
"file": "seed/station.tabl.abap",
|
||||
"description": "Bike stations of the operator"
|
||||
},
|
||||
{
|
||||
"type": "TABL",
|
||||
"name": "{{P}}MOVE",
|
||||
"file": "seed/move.tabl.abap",
|
||||
"description": "Planned bike moves"
|
||||
},
|
||||
{
|
||||
"type": "FUGR",
|
||||
"name": "{{P}}FG_BIKE",
|
||||
"description": "Bike sharing function group"
|
||||
},
|
||||
{
|
||||
"type": "CLAS",
|
||||
"name": "{{P}}SEED_BIKE",
|
||||
"file": "seed/seed_bike.clas.abap",
|
||||
"description": "Sample data for the two tables",
|
||||
"run": true
|
||||
}
|
||||
],
|
||||
"contract": [
|
||||
{
|
||||
"type": "FUNC",
|
||||
"name": "{{P}}BIKE_REBALANCE",
|
||||
"functionGroup": "{{P}}FG_BIKE",
|
||||
"params": [
|
||||
{
|
||||
"name": "iv_dry_run",
|
||||
"type": "abap_bool"
|
||||
},
|
||||
{
|
||||
"name": "ev_applied",
|
||||
"type": "i"
|
||||
},
|
||||
{
|
||||
"name": "ev_rejected",
|
||||
"type": "i"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"out_of_scope": [
|
||||
"{{P}}STATION",
|
||||
"{{P}}MOVE",
|
||||
"{{P}}SEED_BIKE"
|
||||
],
|
||||
"hidden_tests": [
|
||||
{
|
||||
"type": "CLAS",
|
||||
"name": "{{P}}T31_HIDDEN",
|
||||
"file": "hidden/t31_hidden.clas.abap",
|
||||
"description": "Hidden tests for the bike rebalancing"
|
||||
}
|
||||
],
|
||||
"reference": [
|
||||
{
|
||||
"type": "FUNC",
|
||||
"name": "{{P}}BIKE_REBALANCE",
|
||||
"functionGroup": "{{P}}FG_BIKE",
|
||||
"file": "reference/bike_rebalance.func.abap",
|
||||
"description": "Reference implementation of the rebalancing"
|
||||
},
|
||||
{
|
||||
"type": "CLAS",
|
||||
"name": "{{P}}T31_TEST",
|
||||
"file": "reference/t31_test.clas.abap",
|
||||
"description": "Own ABAP Unit tests for the function module"
|
||||
}
|
||||
],
|
||||
"craft_checks": [
|
||||
"method_length"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user