Stage 2 summary at 50 accepted trajectories

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Kral
2026-10-05 18:02:52 +02:00
parent 332fb4601d
commit 5bcd1bf9cd
1230 changed files with 77563 additions and 33 deletions

View File

@@ -0,0 +1,57 @@
FUNCTION {{p}}banquet_fee
IMPORTING
iv_order_id TYPE string
EXPORTING
ev_total TYPE decfloat34
ev_portions TYPE i
ev_dishes TYPE i
EXCEPTIONS
no_positions
unknown_dish
invalid_quantity.
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
DATA lt_dishes TYPE HASHED TABLE OF {{p}}dish WITH UNIQUE KEY dish_id.
DATA lt_seen TYPE HASHED TABLE OF {{p}}pos WITH UNIQUE KEY dish_id.
DATA ls_position TYPE {{p}}pos.
DATA ls_dish TYPE {{p}}dish.
CLEAR: ev_total, ev_portions, ev_dishes.
SELECT order_id, pos_no, dish_id, qty
FROM {{p}}pos
WHERE order_id = @iv_order_id
INTO TABLE @lt_positions.
IF lt_positions IS INITIAL.
RAISE no_positions.
ENDIF.
LOOP AT lt_positions INTO ls_position.
IF ls_position-qty <= 0.
RAISE invalid_quantity.
ENDIF.
ENDLOOP.
SELECT dish_id, dish_name, price
FROM {{p}}dish
INTO TABLE @lt_dishes.
LOOP AT lt_positions INTO ls_position.
READ TABLE lt_dishes INTO ls_dish WITH TABLE KEY dish_id = ls_position-dish_id.
IF sy-subrc <> 0.
RAISE unknown_dish.
ENDIF.
ev_total = ev_total + ls_dish-price * ls_position-qty.
ev_portions = ev_portions + ls_position-qty.
INSERT ls_position INTO TABLE lt_seen.
ENDLOOP.
ev_dishes = lines( lt_seen ).
IF ev_portions >= 50.
ev_total = round( val = ev_total * 95 / 100 dec = 2 mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDFUNCTION.

View File

@@ -0,0 +1,120 @@
CLASS {{p}}t41_test DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS setup.
METHODS teardown.
METHODS insert_dishes.
METHODS insert_positions
IMPORTING it_positions TYPE STANDARD TABLE OF {{p}}pos.
METHODS fee_for
IMPORTING iv_order_id TYPE string
RETURNING VALUE(rv_total) TYPE decfloat34.
METHODS total_of_order FOR TESTING.
METHODS distinct_dishes FOR TESTING.
METHODS discount_from_fifty FOR TESTING.
METHODS empty_order FOR TESTING.
ENDCLASS.
CLASS {{p}}t41_test IMPLEMENTATION.
METHOD setup.
DELETE FROM {{p}}pos WHERE client = @sy-mandt.
DELETE FROM {{p}}dish WHERE client = @sy-mandt.
insert_dishes( ).
ENDMETHOD.
METHOD teardown.
DELETE FROM {{p}}pos WHERE client = @sy-mandt.
DELETE FROM {{p}}dish WHERE client = @sy-mandt.
ENDMETHOD.
METHOD insert_dishes.
DATA lt_dishes TYPE STANDARD TABLE OF {{p}}dish.
lt_dishes = VALUE #(
( client = sy-mandt dish_id = 'D001' dish_name = 'Tomato soup' price = '4.50' )
( client = sy-mandt dish_id = 'D002' dish_name = 'Roast beef' price = '18.00' )
( client = sy-mandt dish_id = 'D003' dish_name = 'Apple pie' price = '5.25' )
( client = sy-mandt dish_id = 'D004' dish_name = 'Sparkling water' price = '2.00' )
( client = sy-mandt dish_id = 'D005' dish_name = 'Bread basket' price = '2.05' )
).
INSERT {{p}}dish FROM TABLE @lt_dishes.
ENDMETHOD.
METHOD insert_positions.
INSERT {{p}}pos FROM TABLE @it_positions.
ENDMETHOD.
METHOD fee_for.
CALL FUNCTION '{{P}}BANQUET_FEE'
EXPORTING
iv_order_id = iv_order_id
IMPORTING
ev_total = rv_total
EXCEPTIONS
OTHERS = 1.
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
ENDMETHOD.
METHOD total_of_order.
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
lt_positions = VALUE #(
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D001' qty = 2 )
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D002' qty = 1 ) ).
insert_positions( lt_positions ).
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '27.00' )
act = fee_for( 'T41A' ) ).
ENDMETHOD.
METHOD distinct_dishes.
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
lt_positions = VALUE #(
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D001' qty = 2 )
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D001' qty = 3 )
( client = sy-mandt order_id = 'T41A' pos_no = 3 dish_id = 'D003' qty = 1 ) ).
insert_positions( lt_positions ).
DATA lv_dishes TYPE i.
CALL FUNCTION '{{P}}BANQUET_FEE'
EXPORTING
iv_order_id = 'T41A'
IMPORTING
ev_dishes = lv_dishes
EXCEPTIONS
OTHERS = 1.
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_dishes ).
ENDMETHOD.
METHOD discount_from_fifty.
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
lt_positions = VALUE #(
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D004' qty = 49 )
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D005' qty = 1 ) ).
insert_positions( lt_positions ).
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '95.05' )
act = fee_for( 'T41A' ) ).
ENDMETHOD.
METHOD empty_order.
DATA lv_total TYPE decfloat34.
CALL FUNCTION '{{P}}BANQUET_FEE'
EXPORTING
iv_order_id = 'T41Z'
IMPORTING
ev_total = lv_total
EXCEPTIONS
no_positions = 1
OTHERS = 2.
cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ).
ENDMETHOD.
ENDCLASS.