Review fixes G0019, G0108: added hidden tests; revalidated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
This commit is contained in:
66
tasks_gen/eval/G0122/reference/bot_plan.func.abap
Normal file
66
tasks_gen/eval/G0122/reference/bot_plan.func.abap
Normal file
@@ -0,0 +1,66 @@
|
||||
FUNCTION {{p}}bot_plan
|
||||
IMPORTING
|
||||
iv_min_hl TYPE decfloat34
|
||||
EXPORTING
|
||||
ev_total_hl TYPE decfloat34
|
||||
ev_plan_count TYPE int4.
|
||||
|
||||
TYPES: BEGIN OF ty_group,
|
||||
beer_type TYPE {{p}}botord-beer_type,
|
||||
total_hl TYPE {{p}}botpln-total_hl,
|
||||
order_count TYPE {{p}}botpln-order_count,
|
||||
END OF ty_group.
|
||||
|
||||
DATA lt_groups TYPE HASHED TABLE OF ty_group WITH UNIQUE KEY beer_type.
|
||||
DATA ls_group TYPE ty_group.
|
||||
DATA ls_row TYPE {{p}}botpln.
|
||||
DATA lt_plan TYPE STANDARD TABLE OF {{p}}botpln WITH EMPTY KEY.
|
||||
|
||||
CLEAR: ev_total_hl, ev_plan_count.
|
||||
|
||||
SELECT beer_type, volume_hl
|
||||
FROM {{p}}botord
|
||||
INTO TABLE @DATA(lt_orders).
|
||||
|
||||
LOOP AT lt_orders INTO DATA(ls_order).
|
||||
IF ls_order-volume_hl <= 0.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
READ TABLE lt_groups ASSIGNING FIELD-SYMBOL(<ls_group>)
|
||||
WITH TABLE KEY beer_type = ls_order-beer_type.
|
||||
IF sy-subrc = 0.
|
||||
<ls_group>-total_hl = <ls_group>-total_hl + ls_order-volume_hl.
|
||||
<ls_group>-order_count = <ls_group>-order_count + 1.
|
||||
ELSE.
|
||||
ls_group = VALUE #( beer_type = ls_order-beer_type
|
||||
total_hl = ls_order-volume_hl
|
||||
order_count = 1 ).
|
||||
INSERT ls_group INTO TABLE lt_groups.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
LOOP AT lt_groups ASSIGNING FIELD-SYMBOL(<ls_grp>).
|
||||
IF <ls_grp>-total_hl < iv_min_hl.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
ls_row = VALUE #( client = sy-mandt
|
||||
beer_type = <ls_grp>-beer_type
|
||||
plan_pos = 0
|
||||
total_hl = <ls_grp>-total_hl
|
||||
order_count = <ls_grp>-order_count ).
|
||||
APPEND ls_row TO lt_plan.
|
||||
ev_total_hl = ev_total_hl + <ls_grp>-total_hl.
|
||||
ENDLOOP.
|
||||
|
||||
SORT lt_plan BY total_hl DESCENDING beer_type ASCENDING.
|
||||
LOOP AT lt_plan ASSIGNING FIELD-SYMBOL(<ls_row>).
|
||||
<ls_row>-plan_pos = sy-tabix.
|
||||
ENDLOOP.
|
||||
ev_plan_count = lines( lt_plan ).
|
||||
|
||||
DELETE FROM {{p}}botpln.
|
||||
IF lt_plan IS NOT INITIAL.
|
||||
INSERT {{p}}botpln FROM TABLE @lt_plan.
|
||||
ENDIF.
|
||||
|
||||
ENDFUNCTION.
|
||||
115
tasks_gen/eval/G0122/reference/t14_test.clas.abap
Normal file
115
tasks_gen/eval/G0122/reference/t14_test.clas.abap
Normal file
@@ -0,0 +1,115 @@
|
||||
CLASS {{p}}t14_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_plan TYPE STANDARD TABLE OF {{p}}botpln WITH EMPTY KEY.
|
||||
CLASS-DATA mo_env TYPE REF TO if_osql_test_environment.
|
||||
CLASS-METHODS class_setup.
|
||||
CLASS-METHODS class_teardown.
|
||||
METHODS setup.
|
||||
METHODS add_order
|
||||
IMPORTING iv_id TYPE {{p}}botord-order_id
|
||||
iv_type TYPE {{p}}botord-beer_type
|
||||
iv_volume TYPE {{p}}botord-volume_hl.
|
||||
METHODS run_plan
|
||||
IMPORTING iv_min_hl TYPE decfloat34
|
||||
EXPORTING ev_total TYPE decfloat34
|
||||
ev_count TYPE int4.
|
||||
METHODS read_plan RETURNING VALUE(rt_plan) TYPE ty_plan.
|
||||
METHODS groups_orders FOR TESTING.
|
||||
METHODS filters_by_min_volume FOR TESTING.
|
||||
METHODS sorts_plan FOR TESTING.
|
||||
METHODS replaces_plan FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}t14_test IMPLEMENTATION.
|
||||
|
||||
METHOD class_setup.
|
||||
mo_env = cl_osql_test_environment=>create(
|
||||
i_dependency_list = VALUE #( ( '{{P}}BOTORD' ) ( '{{P}}BOTPLN' ) ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD class_teardown.
|
||||
IF mo_env IS BOUND.
|
||||
mo_env->destroy( ).
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD setup.
|
||||
DELETE FROM {{p}}botord.
|
||||
DELETE FROM {{p}}botpln.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD add_order.
|
||||
DATA ls_order TYPE {{p}}botord.
|
||||
ls_order-client = sy-mandt.
|
||||
ls_order-order_id = iv_id.
|
||||
ls_order-beer_type = iv_type.
|
||||
ls_order-volume_hl = iv_volume.
|
||||
INSERT {{p}}botord FROM @ls_order.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD run_plan.
|
||||
CALL FUNCTION '{{P}}BOT_PLAN'
|
||||
EXPORTING
|
||||
iv_min_hl = iv_min_hl
|
||||
IMPORTING
|
||||
ev_total_hl = ev_total
|
||||
ev_plan_count = ev_count.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD read_plan.
|
||||
SELECT beer_type, plan_pos, total_hl, order_count
|
||||
FROM {{p}}botpln
|
||||
INTO TABLE @rt_plan.
|
||||
SORT rt_plan BY plan_pos.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD groups_orders.
|
||||
add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ).
|
||||
add_order( iv_id = '2' iv_type = 'PILS' iv_volume = 50 ).
|
||||
run_plan( EXPORTING iv_min_hl = 0
|
||||
IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ).
|
||||
DATA(lt_plan) = read_plan( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 150 act = lt_plan[ 1 ]-total_hl ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_plan[ 1 ]-order_count ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 150 ) act = lv_total ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD filters_by_min_volume.
|
||||
add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ).
|
||||
add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 50 ).
|
||||
run_plan( EXPORTING iv_min_hl = 75
|
||||
IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ).
|
||||
DATA(lt_plan) = read_plan( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 100 ) act = lv_total ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sorts_plan.
|
||||
add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ).
|
||||
add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 300 ).
|
||||
run_plan( EXPORTING iv_min_hl = 0
|
||||
IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ).
|
||||
DATA(lt_plan) = read_plan( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_plan ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'ALE' act = lt_plan[ 1 ]-beer_type ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 1 ]-plan_pos ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 2 ]-beer_type ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_plan[ 2 ]-plan_pos ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD replaces_plan.
|
||||
add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 0 ).
|
||||
run_plan( EXPORTING iv_min_hl = 0
|
||||
IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ).
|
||||
DATA(lt_plan) = read_plan( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( lt_plan ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_total ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_count ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
@@ -1,87 +0,0 @@
|
||||
FUNCTION {{p}}track_fee
|
||||
IMPORTING
|
||||
it_paths TYPE STANDARD TABLE
|
||||
EXPORTING
|
||||
et_fees TYPE STANDARD TABLE
|
||||
EXCEPTIONS
|
||||
invalid_distance
|
||||
invalid_category.
|
||||
|
||||
TYPES: BEGIN OF ty_sum,
|
||||
train_cat TYPE c LENGTH 2,
|
||||
path_count TYPE i,
|
||||
total_km TYPE p LENGTH 13 DECIMALS 2,
|
||||
total_fee TYPE p LENGTH 13 DECIMALS 2,
|
||||
END OF ty_sum.
|
||||
|
||||
DATA: lt_sums TYPE SORTED TABLE OF ty_sum WITH UNIQUE KEY train_cat,
|
||||
lv_cat TYPE c LENGTH 2,
|
||||
lv_km TYPE p LENGTH 13 DECIMALS 2,
|
||||
lv_flag TYPE c LENGTH 1,
|
||||
lv_rate TYPE p LENGTH 5 DECIMALS 2,
|
||||
lv_raw TYPE decfloat34,
|
||||
lv_fee TYPE p LENGTH 13 DECIMALS 2.
|
||||
|
||||
FIELD-SYMBOLS: <ls_in> TYPE any,
|
||||
<ls_out> TYPE any,
|
||||
<ls_sum> TYPE ty_sum,
|
||||
<lv_val> TYPE any.
|
||||
|
||||
CLEAR et_fees.
|
||||
|
||||
LOOP AT it_paths ASSIGNING <ls_in>.
|
||||
ASSIGN COMPONENT 'TRAIN_CAT' OF STRUCTURE <ls_in> TO <lv_val>.
|
||||
lv_cat = <lv_val>.
|
||||
ASSIGN COMPONENT 'DISTANCE_KM' OF STRUCTURE <ls_in> TO <lv_val>.
|
||||
lv_km = <lv_val>.
|
||||
ASSIGN COMPONENT 'NIGHT_FLAG' OF STRUCTURE <ls_in> TO <lv_val>.
|
||||
lv_flag = <lv_val>.
|
||||
|
||||
IF lv_km <= 0.
|
||||
RAISE invalid_distance.
|
||||
ENDIF.
|
||||
|
||||
CASE lv_cat.
|
||||
WHEN 'IC'.
|
||||
lv_rate = '1.20'.
|
||||
WHEN 'RG'.
|
||||
lv_rate = '0.90'.
|
||||
WHEN 'FR'.
|
||||
lv_rate = '0.60'.
|
||||
WHEN 'SP'.
|
||||
lv_rate = '1.50'.
|
||||
WHEN OTHERS.
|
||||
RAISE invalid_category.
|
||||
ENDCASE.
|
||||
|
||||
lv_raw = lv_km * lv_rate.
|
||||
IF lv_flag = 'X'.
|
||||
lv_raw = lv_raw * 12 / 10.
|
||||
ENDIF.
|
||||
lv_fee = round( val = lv_raw dec = 2 mode = cl_abap_math=>round_half_up ).
|
||||
IF lv_fee < 5.
|
||||
lv_fee = 5.
|
||||
ENDIF.
|
||||
|
||||
READ TABLE lt_sums ASSIGNING <ls_sum> WITH TABLE KEY train_cat = lv_cat.
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE ty_sum( train_cat = lv_cat ) INTO TABLE lt_sums ASSIGNING <ls_sum>.
|
||||
ENDIF.
|
||||
<ls_sum>-path_count = <ls_sum>-path_count + 1.
|
||||
<ls_sum>-total_km = <ls_sum>-total_km + lv_km.
|
||||
<ls_sum>-total_fee = <ls_sum>-total_fee + lv_fee.
|
||||
ENDLOOP.
|
||||
|
||||
LOOP AT lt_sums ASSIGNING <ls_sum>.
|
||||
APPEND INITIAL LINE TO et_fees ASSIGNING <ls_out>.
|
||||
ASSIGN COMPONENT 'TRAIN_CAT' OF STRUCTURE <ls_out> TO <lv_val>.
|
||||
<lv_val> = <ls_sum>-train_cat.
|
||||
ASSIGN COMPONENT 'PATH_COUNT' OF STRUCTURE <ls_out> TO <lv_val>.
|
||||
<lv_val> = <ls_sum>-path_count.
|
||||
ASSIGN COMPONENT 'TOTAL_KM' OF STRUCTURE <ls_out> TO <lv_val>.
|
||||
<lv_val> = <ls_sum>-total_km.
|
||||
ASSIGN COMPONENT 'TOTAL_FEE' OF STRUCTURE <ls_out> TO <lv_val>.
|
||||
<lv_val> = <ls_sum>-total_fee.
|
||||
ENDLOOP.
|
||||
|
||||
ENDFUNCTION.
|
||||
@@ -1,75 +0,0 @@
|
||||
CLASS {{p}}track_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_paths TYPE {{P}}TRACK_TYPES=>tt_path.
|
||||
TYPES ty_fees TYPE {{P}}TRACK_TYPES=>tt_fee.
|
||||
TYPES ty_money TYPE {{P}}TRACK_TYPES=>ty_money.
|
||||
|
||||
METHODS fees_for
|
||||
IMPORTING it_paths TYPE ty_paths
|
||||
RETURNING VALUE(rt_fees) TYPE ty_fees.
|
||||
|
||||
METHODS one_category FOR TESTING.
|
||||
METHODS two_categories FOR TESTING.
|
||||
METHODS night_surcharge FOR TESTING.
|
||||
METHODS invalid_distance FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}track_test IMPLEMENTATION.
|
||||
|
||||
METHOD fees_for.
|
||||
CALL FUNCTION '{{P}}TRACK_FEE'
|
||||
EXPORTING
|
||||
it_paths = it_paths
|
||||
IMPORTING
|
||||
et_fees = rt_fees
|
||||
EXCEPTIONS
|
||||
invalid_distance = 1
|
||||
invalid_category = 2
|
||||
OTHERS = 3.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD one_category.
|
||||
DATA lt_paths TYPE ty_paths.
|
||||
lt_paths = VALUE #( ( path_id = '00000001' train_cat = 'SP' distance_km = '10.00' night_flag = '' ) ).
|
||||
DATA(lt_fees) = fees_for( lt_paths ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_fees ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_money( '15.00' ) act = lt_fees[ 1 ]-total_fee ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD two_categories.
|
||||
DATA lt_paths TYPE ty_paths.
|
||||
lt_paths = VALUE #( ( path_id = '00000001' train_cat = 'RG' distance_km = '20.00' night_flag = '' )
|
||||
( path_id = '00000002' train_cat = 'FR' distance_km = '20.00' night_flag = '' ) ).
|
||||
DATA(lt_fees) = fees_for( lt_paths ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_fees ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'FR' act = lt_fees[ 1 ]-train_cat ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'RG' act = lt_fees[ 2 ]-train_cat ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD night_surcharge.
|
||||
DATA lt_paths TYPE ty_paths.
|
||||
lt_paths = VALUE #( ( path_id = '00000001' train_cat = 'FR' distance_km = '50.00' night_flag = 'X' ) ).
|
||||
DATA(lt_fees) = fees_for( lt_paths ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_money( '36.00' ) act = lt_fees[ 1 ]-total_fee ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD invalid_distance.
|
||||
DATA lt_paths TYPE ty_paths.
|
||||
lt_paths = VALUE #( ( path_id = '00000001' train_cat = 'IC' distance_km = '0.00' night_flag = '' ) ).
|
||||
DATA lt_fees TYPE ty_fees.
|
||||
CALL FUNCTION '{{P}}TRACK_FEE'
|
||||
EXPORTING
|
||||
it_paths = lt_paths
|
||||
IMPORTING
|
||||
et_fees = lt_fees
|
||||
EXCEPTIONS
|
||||
invalid_distance = 1
|
||||
OTHERS = 2.
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user