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:
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.
|
||||
Reference in New Issue
Block a user