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,38 @@
{
"id": "G1129",
"pool": "train",
"object_type": "FUNC",
"category": "C",
"attempts": [
{
"stage": "validate",
"oracle": 0,
"null": 0
},
{
"stage": "bundle",
"errors": [
"seed/mealbk.tabl.abap: a table needs the annotation @AbapCatalog.tableCategory (for example #TRANSPARENT, #A)",
"seed/mealbk.tabl.abap: a table needs the annotation @AbapCatalog.deliveryClass (for example #TRANSPARENT, #A)"
],
"by_check": {
"static": 2
}
},
{
"stage": "validate",
"oracle": 0,
"null": 0
},
{
"stage": "bundle",
"errors": [
"hidden/t14_hidden.clas.abap line 141: syntax error for release v758 (abaplint): Statement does not exist in the configured ABAP version(or a parser error), \"cl_abap_unit_assert\""
],
"by_check": {
"abaplint": 1
}
}
],
"accepted": false
}

View File

@@ -0,0 +1,325 @@
CLASS {{p}}t14_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS prepare
IMPORTING iv_week TYPE string
it_book TYPE STANDARD TABLE OF {{P}}MEALBK.
METHODS cleanup
IMPORTING iv_week TYPE string.
METHODS bill
IMPORTING iv_week TYPE string
EXPORTING ev_meals TYPE decfloat34
ev_pupils TYPE decfloat34
ev_amount TYPE decfloat34
ev_discount TYPE decfloat34
ev_subrc TYPE sysubrc.
METHODS empty_week_zero FOR TESTING.
METHODS sums_two_pupils FOR TESTING.
METHODS skips_cancelled FOR TESTING.
METHODS skips_free_meal FOR TESTING.
METHODS discount_from_five FOR TESTING.
METHODS no_discount_for_four FOR TESTING.
METHODS discount_is_per_pupil FOR TESTING.
METHODS rejects_negative_price FOR TESTING.
METHODS counts_pupils FOR TESTING.
METHODS rounds_half_up FOR TESTING.
METHODS ignores_other_weeks FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_hidden IMPLEMENTATION.
METHOD prepare.
cleanup( iv_week ).
INSERT {{P}}MEALBK FROM TABLE @it_book.
ENDMETHOD.
METHOD cleanup.
DELETE FROM {{P}}MEALBK WHERE week_key = @iv_week.
ENDMETHOD.
METHOD bill.
CALL FUNCTION '{{P}}MEAL_BILL'
EXPORTING
iv_week = iv_week
IMPORTING
ev_meals = ev_meals
ev_pupils = ev_pupils
ev_amount = ev_amount
ev_discount = ev_discount
EXCEPTIONS
invalid_price = 1
OTHERS = 2.
ev_subrc = sy-subrc.
ENDMETHOD.
METHOD empty_week_zero.
DATA lv_week TYPE string VALUE 'H-EMPTY'.
cleanup( lv_week ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_discount ).
ENDMETHOD.
METHOD sums_two_pupils.
DATA lv_week TYPE string VALUE 'H-SUM1'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-SUM1' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.50' )
( week_key = 'H-SUM1' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '3.00' )
( week_key = 'H-SUM1' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '4.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 3 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 2 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '9.50' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD skips_cancelled.
DATA lv_week TYPE string VALUE 'H-CANC'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-CANC' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.00' )
( week_key = 'H-CANC' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '5.00' cancelled = 'X' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '2.00' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD skips_free_meal.
DATA lv_week TYPE string VALUE 'H-FREE'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-FREE' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '0.00' )
( week_key = 'H-FREE' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '3.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '3.00' ) act = lv_amount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD discount_from_five.
DATA lv_week TYPE string VALUE 'H-DISC'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-DISC' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-DISC' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-DISC' pupil = 'A' meal_no = 3 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-DISC' pupil = 'A' meal_no = 4 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-DISC' pupil = 'A' meal_no = 5 meal = 'LUNCH' price = '9.99' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 5 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '44.96' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '4.99' ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD no_discount_for_four.
DATA lv_week TYPE string VALUE 'H-NODS'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-NODS' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-NODS' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-NODS' pupil = 'A' meal_no = 3 meal = 'LUNCH' price = '9.99' )
( week_key = 'H-NODS' pupil = 'A' meal_no = 4 meal = 'LUNCH' price = '9.99' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 4 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '39.96' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD discount_is_per_pupil.
DATA lv_week TYPE string VALUE 'H-PERP'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-PERP' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'A' meal_no = 3 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'A' meal_no = 4 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'A' meal_no = 5 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'B' meal_no = 2 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'B' meal_no = 3 meal = 'LUNCH' price = '10.00' )
( week_key = 'H-PERP' pupil = 'B' meal_no = 4 meal = 'LUNCH' price = '10.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 9 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 2 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '85.00' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '5.00' ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD rejects_negative_price.
DATA lv_week TYPE string VALUE 'H-NEG'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-NEG' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.00' )
( week_key = 'H-NEG' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '-1.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
cleanup( lv_week ).
ENDMETHOD.
METHOD counts_pupils.
DATA lv_week TYPE string VALUE 'H-PUPL'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-PUPL' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.00' )
( week_key = 'H-PUPL' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '3.00' cancelled = 'X' )
( week_key = 'H-PUPL' pupil = 'C' meal_no = 1 meal = 'LUNCH' price = '0.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '2.00' ) act = lv_amount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD rounds_half_up.
DATA lv_week TYPE string VALUE 'H-RND'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-RND' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '1.01' )
( week_key = 'H-RND' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '1.01' )
( week_key = 'H-RND' pupil = 'A' meal_no = 3 meal = 'LUNCH' price = '1.01' )
( week_key = 'H-RND' pupil = 'A' meal_no = 4 meal = 'LUNCH' price = '1.01' )
( week_key = 'H-RND' pupil = 'A' meal_no = 5 meal = 'LUNCH' price = '1.01' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 5 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '4.55' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '0.50' ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD ignores_other_weeks.
DATA lv_week TYPE string VALUE 'H-OTHR'.
DATA lv_other TYPE string VALUE 'H-OTHR2'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'H-OTHR' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.00' ) ) ).
prepare( iv_week = lv_other
it_book = VALUE #(
( week_key = 'H-OTHR2' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '9.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount)
ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '2.00' ) act = lv_amount ).
cleanup( lv_week ).
cleanup( lv_other ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,56 @@
FUNCTION {{p}}meal_bill
IMPORTING
iv_week TYPE string
EXPORTING
ev_meals TYPE decfloat34
ev_pupils TYPE decfloat34
ev_amount TYPE decfloat34
ev_discount TYPE decfloat34
EXCEPTIONS
invalid_price.
TYPES:
BEGIN OF ty_pupil_sum,
pupil TYPE string,
meals TYPE i,
gross TYPE decfloat34,
amount TYPE decfloat34,
END OF ty_pupil_sum.
DATA lt_pupil TYPE SORTED TABLE OF ty_pupil_sum WITH UNIQUE KEY pupil.
SELECT pupil, price, cancelled
FROM {{P}}MEALBK
WHERE week_key = @iv_week
INTO TABLE @DATA(lt_book).
LOOP AT lt_book INTO DATA(ls_book).
IF ls_book-price < 0.
RAISE invalid_price.
ENDIF.
IF ls_book-cancelled = 'X' OR ls_book-price = 0.
CONTINUE.
ENDIF.
READ TABLE lt_pupil ASSIGNING FIELD-SYMBOL(<ls_pupil>) WITH TABLE KEY pupil = ls_book-pupil.
IF sy-subrc <> 0.
INSERT VALUE #( pupil = ls_book-pupil ) INTO TABLE lt_pupil ASSIGNING <ls_pupil>.
ENDIF.
<ls_pupil>-meals = <ls_pupil>-meals + 1.
<ls_pupil>-gross = <ls_pupil>-gross + ls_book-price.
ENDLOOP.
LOOP AT lt_pupil ASSIGNING <ls_pupil>.
<ls_pupil>-amount = <ls_pupil>-gross.
IF <ls_pupil>-meals >= 5.
<ls_pupil>-amount = round( val = <ls_pupil>-gross * 9 / 10
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ev_meals = ev_meals + <ls_pupil>-meals.
ev_amount = ev_amount + <ls_pupil>-amount.
ev_discount = ev_discount + <ls_pupil>-gross - <ls_pupil>-amount.
ENDLOOP.
ev_pupils = lines( lt_pupil ).
ENDFUNCTION.

View File

@@ -0,0 +1,135 @@
CLASS {{p}}t14_test DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS prepare
IMPORTING iv_week TYPE string
it_book TYPE STANDARD TABLE OF {{P}}MEALBK.
METHODS cleanup
IMPORTING iv_week TYPE string.
METHODS bill
IMPORTING iv_week TYPE string
EXPORTING ev_meals TYPE decfloat34
ev_pupils TYPE decfloat34
ev_amount TYPE decfloat34
ev_discount TYPE decfloat34.
METHODS sums_two_pupils FOR TESTING.
METHODS skips_cancelled FOR TESTING.
METHODS discount_from_five FOR TESTING.
METHODS rejects_negative_price FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_test IMPLEMENTATION.
METHOD prepare.
cleanup( iv_week ).
INSERT {{P}}MEALBK FROM TABLE @it_book.
ENDMETHOD.
METHOD cleanup.
DELETE FROM {{P}}MEALBK WHERE week_key = @iv_week.
ENDMETHOD.
METHOD bill.
CALL FUNCTION '{{P}}MEAL_BILL'
EXPORTING
iv_week = iv_week
IMPORTING
ev_meals = ev_meals
ev_pupils = ev_pupils
ev_amount = ev_amount
ev_discount = ev_discount
EXCEPTIONS
invalid_price = 1
OTHERS = 2.
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
ENDMETHOD.
METHOD sums_two_pupils.
DATA lv_week TYPE string VALUE 'R-SUM1'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'R-SUM1' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.50' )
( week_key = 'R-SUM1' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '3.00' )
( week_key = 'R-SUM1' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '4.00' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount) ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 3 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 2 ) act = lv_pupils ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '9.50' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD skips_cancelled.
DATA lv_week TYPE string VALUE 'R-CANC'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'R-CANC' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.00' )
( week_key = 'R-CANC' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '5.00' cancelled = 'X' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount) ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 1 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '2.00' ) act = lv_amount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD discount_from_five.
DATA lv_week TYPE string VALUE 'R-DISC'.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'R-DISC' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '9.99' )
( week_key = 'R-DISC' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '9.99' )
( week_key = 'R-DISC' pupil = 'A' meal_no = 3 meal = 'LUNCH' price = '9.99' )
( week_key = 'R-DISC' pupil = 'A' meal_no = 4 meal = 'LUNCH' price = '9.99' )
( week_key = 'R-DISC' pupil = 'A' meal_no = 5 meal = 'LUNCH' price = '9.99' ) ) ).
bill( EXPORTING iv_week = lv_week
IMPORTING ev_meals = DATA(lv_meals)
ev_pupils = DATA(lv_pupils)
ev_amount = DATA(lv_amount)
ev_discount = DATA(lv_discount) ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 5 ) act = lv_meals ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '44.96' ) act = lv_amount ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '4.99' ) act = lv_discount ).
cleanup( lv_week ).
ENDMETHOD.
METHOD rejects_negative_price.
DATA lv_week TYPE string VALUE 'R-NEG'.
DATA lv_amount TYPE decfloat34.
prepare( iv_week = lv_week
it_book = VALUE #(
( week_key = 'R-NEG' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '-1.00' ) ) ).
CALL FUNCTION '{{P}}MEAL_BILL'
EXPORTING
iv_week = lv_week
IMPORTING
ev_amount = lv_amount
EXCEPTIONS
invalid_price = 1
OTHERS = 2.
cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ).
cleanup( lv_week ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,23 @@
CLASS {{p}}meal_data DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS {{p}}meal_data IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA lt_book TYPE STANDARD TABLE OF {{P}}MEALBK.
DELETE FROM {{P}}MEALBK.
lt_book = VALUE #(
( week_key = '2024-15' pupil = 'A' meal_no = 1 meal = 'LUNCH' price = '2.50' )
( week_key = '2024-15' pupil = 'A' meal_no = 2 meal = 'LUNCH' price = '3.00' )
( week_key = '2024-15' pupil = 'B' meal_no = 1 meal = 'LUNCH' price = '4.00' )
( week_key = '2024-15' pupil = 'C' meal_no = 1 meal = 'LUNCH' price = '5.00' cancelled = 'X' ) ).
INSERT {{P}}MEALBK FROM TABLE @lt_book.
out->write( |{ lines( lt_book ) } bookings inserted| ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,14 @@
@EndUserText.label : 'Meal bookings of the canteen'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table {{p}}mealbk {
key mandt : abap.clnt not null;
key week_key : abap.char(10) not null;
key pupil : abap.char(10) not null;
key meal_no : abap.int4 not null;
meal : abap.char(10);
price : abap.dec(9,2);
cancelled : abap.char(1);
}

View File

@@ -0,0 +1,60 @@
# 1. Goal
A school canteen bills the parents for the meals of one week. The billing
program calls one function module for each week. The function module reads the
meal bookings of the week and returns the number of charged meals, the number
of pupils, the total amount, and the total discount.
# 2. Open questions
None.
# 3. Context
- The function group {{P}}FG_MEAL exists in package $TMP.
- The database table {{P}}MEALBK exists in package $TMP. It contains the meal
bookings. Its fields are:
- mandt: the client
- week_key: the week of the booking, for example '2024-15'
- pupil: the pupil who booked the meal
- meal_no: the number of the booking inside the week
- meal: the kind of meal, for example 'LUNCH'
- price: the price of the meal
- cancelled: 'X' when the booking was cancelled, otherwise initial
- The class {{P}}MEAL_DATA fills the table with sample bookings.
# 4. Contract
- Create the function module {{P}}MEAL_BILL in function group {{P}}FG_MEAL.
- Interface of {{P}}MEAL_BILL:
- IMPORTING iv_week TYPE string
- EXPORTING ev_meals TYPE decfloat34
- EXPORTING ev_pupils TYPE decfloat34
- EXPORTING ev_amount TYPE decfloat34
- EXPORTING ev_discount TYPE decfloat34
- EXCEPTIONS invalid_price
# 5. Business rules
1. The function module reads the bookings of the given week. A booking belongs
to the week that is in its field week_key.
2. A booking is charged when cancelled is not 'X' and price is greater than 0.
3. If a booking of the week has a price less than 0, raise the exception
INVALID_PRICE.
4. Each charged booking counts as one meal of its pupil.
5. The gross amount of a pupil is the sum of the prices of the charged bookings
of the pupil.
6. If a pupil has 5 or more charged meals, the amount of the pupil is 90 % of
the gross amount, rounded half up to 2 decimals. If a pupil has fewer than 5
charged meals, the amount of the pupil is the gross amount.
7. ev_meals is the total number of charged meals of the week.
8. ev_pupils is the number of pupils with at least one charged booking.
9. ev_amount is the sum of the amounts of all pupils.
10. ev_discount is the sum of the differences between the gross amount and the
amount of each pupil.
11. If the week has no charged booking, all output parameters are 0.
# 6. Constraints
- Release target: 7.58.
- Coding standards: Clean ABAP. Keep every method below 40 statements.
- Out of scope: do not change {{P}}MEALBK and {{P}}MEAL_DATA.
# 7. Acceptance
- The function module {{P}}MEAL_BILL is active and has no syntax error.
- The hidden tests pass.
- Write ABAP Unit tests for the function module in a global test class.

View File

@@ -0,0 +1,91 @@
{
"id": "G1129",
"category": "C",
"object_type": "FUNC",
"difficulty": 2,
"release_target": "v758",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 60,
"max_activations": 15
},
"seed": [
{
"type": "TABL",
"name": "{{P}}MEALBK",
"file": "seed/mealbk.tabl.abap",
"description": "Meal bookings of the canteen"
},
{
"type": "CLAS",
"name": "{{P}}MEAL_DATA",
"file": "seed/meal_data.clas.abap",
"description": "Sample meal bookings",
"run": true
},
{
"type": "FUGR",
"name": "{{P}}FG_MEAL",
"description": "Canteen billing"
}
],
"contract": [
{
"type": "FUNC",
"name": "{{P}}MEAL_BILL",
"functionGroup": "{{P}}FG_MEAL",
"params": [
{
"name": "iv_week",
"type": "string"
},
{
"name": "ev_meals",
"type": "decfloat34"
},
{
"name": "ev_pupils",
"type": "decfloat34"
},
{
"name": "ev_amount",
"type": "decfloat34"
},
{
"name": "ev_discount",
"type": "decfloat34"
}
]
}
],
"out_of_scope": [
"{{P}}MEALBK",
"{{P}}MEAL_DATA"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T14_HIDDEN",
"file": "hidden/t14_hidden.clas.abap",
"description": "T14 hidden tests"
}
],
"reference": [
{
"type": "FUNC",
"name": "{{P}}MEAL_BILL",
"functionGroup": "{{P}}FG_MEAL",
"file": "reference/meal_bill.func.abap",
"description": "Canteen billing module"
},
{
"type": "CLAS",
"name": "{{P}}T14_TEST",
"file": "reference/t14_test.clas.abap",
"description": "T14 own tests"
}
],
"craft_checks": [
"method_length"
]
}