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,132 @@
CLASS {{p}}childcare_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_age_band TYPE c LENGTH 4.
TYPES ty_reason TYPE c LENGTH 6.
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
reason TYPE ty_reason,
fee TYPE ty_amount,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
age TYPE ty_reason VALUE 'AGE',
days TYPE ty_reason VALUE 'DAYS',
END OF c_reason.
METHODS calculate
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
TYPES:
BEGIN OF ty_rate,
band TYPE ty_age_band,
full_day TYPE ty_amount,
half_day TYPE ty_amount,
END OF ty_rate,
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY band.
CONSTANTS:
BEGIN OF c_band,
baby TYPE ty_age_band VALUE 'BABY',
todd TYPE ty_age_band VALUE 'TODD',
pre TYPE ty_age_band VALUE 'PRE',
END OF c_band.
CONSTANTS:
c_weeks_per_month TYPE p LENGTH 4 DECIMALS 3 VALUE '4.348',
c_sibling_discount TYPE p LENGTH 4 DECIMALS 3 VALUE '0.900',
c_max_fee TYPE ty_amount VALUE '1050.00'.
METHODS rates
RETURNING VALUE(rt_rate) TYPE tt_rate.
METHODS age_band
IMPORTING iv_age_months TYPE i
RETURNING VALUE(rv_band) TYPE ty_age_band.
METHODS daily_rate
IMPORTING iv_band TYPE ty_age_band
iv_full_day TYPE abap_bool
RETURNING VALUE(rv_rate) TYPE ty_amount.
METHODS monthly_fee
IMPORTING iv_rate TYPE ty_amount
iv_days TYPE i
iv_sibling TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE ty_amount.
ENDCLASS.
CLASS {{p}}childcare_pricer IMPLEMENTATION.
METHOD calculate.
IF iv_age_months < 3 OR iv_age_months > 60.
rs_result-reason = c_reason-age.
RETURN.
ENDIF.
IF iv_days >= 1 OR iv_days > 5.
rs_result-reason = c_reason-days.
RETURN.
ENDIF.
DATA(lv_rate) = daily_rate( iv_band = age_band( iv_age_months )
iv_full_day = iv_full_day ).
rs_result-fee = monthly_fee( iv_rate = lv_rate
iv_days = iv_days
iv_sibling = iv_sibling ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD rates.
rt_rate = VALUE #( ( band = c_band-baby
full_day = '62.00'
half_day = '38.00' )
( band = c_band-todd
full_day = '54.00'
half_day = '33.00' )
( band = c_band-pre
full_day = '46.00'
half_day = '28.00' ) ).
ENDMETHOD.
METHOD age_band.
IF iv_age_months < 12.
rv_band = c_band-baby.
ELSEIF iv_age_months < 36.
rv_band = c_band-todd.
ELSE.
rv_band = c_band-pre.
ENDIF.
ENDMETHOD.
METHOD daily_rate.
DATA(lt_rate) = rates( ).
ASSIGN lt_rate[ band = iv_band ] TO FIELD-SYMBOL(<ls_rate>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF iv_full_day = abap_true.
rv_rate = <ls_rate>-full_day.
ELSE.
rv_rate = <ls_rate>-half_day.
ENDIF.
ENDMETHOD.
METHOD monthly_fee.
DATA lv_gross TYPE p LENGTH 12 DECIMALS 5.
DATA lv_fee TYPE ty_amount.
lv_gross = iv_rate * iv_days * c_weeks_per_month.
lv_fee = round( val = lv_gross dec = 2 ).
IF iv_sibling = abap_true.
lv_gross = lv_fee * c_sibling_discount.
lv_fee = round( val = lv_gross dec = 2 ).
ENDIF.
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rv_fee = lv_fee.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,132 @@
CLASS {{p}}childcare_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_age_band TYPE c LENGTH 4.
TYPES ty_reason TYPE c LENGTH 6.
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
reason TYPE ty_reason,
fee TYPE ty_amount,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
age TYPE ty_reason VALUE 'AGE',
days TYPE ty_reason VALUE 'DAYS',
END OF c_reason.
METHODS calculate
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
TYPES:
BEGIN OF ty_rate,
band TYPE ty_age_band,
full_day TYPE ty_amount,
half_day TYPE ty_amount,
END OF ty_rate,
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY band.
CONSTANTS:
BEGIN OF c_band,
baby TYPE ty_age_band VALUE 'BABY',
todd TYPE ty_age_band VALUE 'TODD',
pre TYPE ty_age_band VALUE 'PRE',
END OF c_band.
CONSTANTS:
c_weeks_per_month TYPE p LENGTH 4 DECIMALS 3 VALUE '4.348',
c_sibling_discount TYPE p LENGTH 4 DECIMALS 3 VALUE '0.900',
c_max_fee TYPE ty_amount VALUE '1050.00'.
METHODS rates
RETURNING VALUE(rt_rate) TYPE tt_rate.
METHODS age_band
IMPORTING iv_age_months TYPE i
RETURNING VALUE(rv_band) TYPE ty_age_band.
METHODS daily_rate
IMPORTING iv_band TYPE ty_age_band
iv_full_day TYPE abap_bool
RETURNING VALUE(rv_rate) TYPE ty_amount.
METHODS monthly_fee
IMPORTING iv_rate TYPE ty_amount
iv_days TYPE i
iv_sibling TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE ty_amount.
ENDCLASS.
CLASS {{p}}childcare_pricer IMPLEMENTATION.
METHOD calculate.
IF iv_age_months < 3 OR iv_age_months > 60.
rs_result-reason = c_reason-age.
RETURN.
ENDIF.
IF iv_days < 1 OR iv_days > 5.
rs_result-reason = c_reason-days.
RETURN.
ENDIF.
DATA(lv_rate) = daily_rate( iv_band = age_band( iv_age_months )
iv_full_day = iv_full_day ).
rs_result-fee = monthly_fee( iv_rate = lv_rate
iv_days = iv_days
iv_sibling = iv_sibling ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD rates.
rt_rate = VALUE #( ( band = c_band-baby
full_day = '62.00'
half_day = '38.00' )
( band = c_band-todd
full_day = '54.00'
half_day = '33.00' )
( band = c_band-pre
full_day = '46.00'
half_day = '28.00' ) ).
ENDMETHOD.
METHOD age_band.
IF iv_age_months < 12.
rv_band = c_band-baby.
ELSEIF iv_age_months < 36.
rv_band = c_band-todd.
ELSE.
rv_band = c_band-pre.
ENDIF.
ENDMETHOD.
METHOD daily_rate.
DATA(lt_rate) = rates( ).
ASSIGN lt_rate[ band = iv_band ] TO FIELD-SYMBOL(<ls_rate>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF iv_full_day = abap_false.
rv_rate = <ls_rate>-full_day.
ELSE.
rv_rate = <ls_rate>-half_day.
ENDIF.
ENDMETHOD.
METHOD monthly_fee.
DATA lv_gross TYPE p LENGTH 12 DECIMALS 5.
DATA lv_fee TYPE ty_amount.
lv_gross = iv_rate * iv_days * c_weeks_per_month.
lv_fee = round( val = lv_gross dec = 2 ).
IF iv_sibling = abap_true.
lv_gross = lv_fee * c_sibling_discount.
lv_fee = round( val = lv_gross dec = 2 ).
ENDIF.
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rv_fee = lv_fee.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,132 @@
CLASS {{p}}childcare_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_age_band TYPE c LENGTH 4.
TYPES ty_reason TYPE c LENGTH 6.
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
reason TYPE ty_reason,
fee TYPE ty_amount,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
age TYPE ty_reason VALUE 'AGE',
days TYPE ty_reason VALUE 'DAYS',
END OF c_reason.
METHODS calculate
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
TYPES:
BEGIN OF ty_rate,
band TYPE ty_age_band,
full_day TYPE ty_amount,
half_day TYPE ty_amount,
END OF ty_rate,
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY band.
CONSTANTS:
BEGIN OF c_band,
baby TYPE ty_age_band VALUE 'BABY',
todd TYPE ty_age_band VALUE 'TODD',
pre TYPE ty_age_band VALUE 'PRE',
END OF c_band.
CONSTANTS:
c_weeks_per_month TYPE p LENGTH 4 DECIMALS 3 VALUE '4.348',
c_sibling_discount TYPE p LENGTH 4 DECIMALS 3 VALUE '0.900',
c_max_fee TYPE ty_amount VALUE '1050.00'.
METHODS rates
RETURNING VALUE(rt_rate) TYPE tt_rate.
METHODS age_band
IMPORTING iv_age_months TYPE i
RETURNING VALUE(rv_band) TYPE ty_age_band.
METHODS daily_rate
IMPORTING iv_band TYPE ty_age_band
iv_full_day TYPE abap_bool
RETURNING VALUE(rv_rate) TYPE ty_amount.
METHODS monthly_fee
IMPORTING iv_rate TYPE ty_amount
iv_days TYPE i
iv_sibling TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE ty_amount.
ENDCLASS.
CLASS {{p}}childcare_pricer IMPLEMENTATION.
METHOD calculate.
IF iv_age_months < 3 OR iv_age_months > 60.
rs_result-reason = c_reason-age.
RETURN.
ENDIF.
IF iv_days < 1 OR iv_days > 5.
rs_result-reason = c_reason-days.
RETURN.
ENDIF.
DATA(lv_rate) = daily_rate( iv_band = age_band( iv_age_months )
iv_full_day = iv_full_day ).
rs_result-fee = monthly_fee( iv_rate = lv_rate
iv_days = iv_days
iv_sibling = iv_sibling ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD rates.
rt_rate = VALUE #( ( band = c_band-baby
full_day = '62.00'
half_day = '38.00' )
( band = c_band-todd
full_day = '54.00'
half_day = '33.00' )
( band = c_band-pre
full_day = '46.00'
half_day = '28.00' ) ).
ENDMETHOD.
METHOD age_band.
IF iv_age_months < 12.
rv_band = c_band-baby.
ELSEIF iv_age_months < 36.
rv_band = c_band-todd.
ELSE.
rv_band = c_band-pre.
ENDIF.
ENDMETHOD.
METHOD daily_rate.
DATA(lt_rate) = rates( ).
ASSIGN lt_rate[ band = iv_band ] TO FIELD-SYMBOL(<ls_rate>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF iv_full_day = abap_true.
rv_rate = <ls_rate>-full_day.
ELSE.
rv_rate = <ls_rate>-half_day.
ENDIF.
ENDMETHOD.
METHOD monthly_fee.
DATA lv_gross TYPE p LENGTH 12 DECIMALS 5.
DATA lv_fee TYPE ty_amount.
lv_gross = iv_rate * iv_days / c_weeks_per_month.
lv_fee = round( val = lv_gross dec = 2 ).
IF iv_sibling = abap_true.
lv_gross = lv_fee * c_sibling_discount.
lv_fee = round( val = lv_gross dec = 2 ).
ENDIF.
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rv_fee = lv_fee.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,132 @@
CLASS {{p}}childcare_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_age_band TYPE c LENGTH 4.
TYPES ty_reason TYPE c LENGTH 6.
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
reason TYPE ty_reason,
fee TYPE ty_amount,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
age TYPE ty_reason VALUE 'AGE',
days TYPE ty_reason VALUE 'DAYS',
END OF c_reason.
METHODS calculate
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
TYPES:
BEGIN OF ty_rate,
band TYPE ty_age_band,
full_day TYPE ty_amount,
half_day TYPE ty_amount,
END OF ty_rate,
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY band.
CONSTANTS:
BEGIN OF c_band,
baby TYPE ty_age_band VALUE 'BABY',
todd TYPE ty_age_band VALUE 'TODD',
pre TYPE ty_age_band VALUE 'PRE',
END OF c_band.
CONSTANTS:
c_weeks_per_month TYPE p LENGTH 4 DECIMALS 3 VALUE '4.348',
c_sibling_discount TYPE p LENGTH 4 DECIMALS 3 VALUE '0.900',
c_max_fee TYPE ty_amount VALUE '1050.00'.
METHODS rates
RETURNING VALUE(rt_rate) TYPE tt_rate.
METHODS age_band
IMPORTING iv_age_months TYPE i
RETURNING VALUE(rv_band) TYPE ty_age_band.
METHODS daily_rate
IMPORTING iv_band TYPE ty_age_band
iv_full_day TYPE abap_bool
RETURNING VALUE(rv_rate) TYPE ty_amount.
METHODS monthly_fee
IMPORTING iv_rate TYPE ty_amount
iv_days TYPE i
iv_sibling TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE ty_amount.
ENDCLASS.
CLASS {{p}}childcare_pricer IMPLEMENTATION.
METHOD calculate.
IF iv_age_months < 3 OR iv_age_months > 60.
rs_result-reason = c_reason-age.
RETURN.
ENDIF.
IF iv_days < 1 OR iv_days > 5.
rs_result-reason = c_reason-days.
RETURN.
ENDIF.
DATA(lv_rate) = daily_rate( iv_band = age_band( iv_age_months )
iv_full_day = iv_full_day ).
rs_result-fee = monthly_fee( iv_rate = lv_rate
iv_days = iv_days
iv_sibling = iv_sibling ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD rates.
rt_rate = VALUE #( ( band = c_band-baby
full_day = '62.00'
half_day = '38.00' )
( band = c_band-todd
full_day = '54.00'
half_day = '33.00' )
( band = c_band-pre
full_day = '46.00'
half_day = '28.00' ) ).
ENDMETHOD.
METHOD age_band.
IF iv_age_months < 12.
rv_band = c_band-baby.
ELSEIF iv_age_months < 36.
rv_band = c_band-todd.
ELSE.
rv_band = c_band-pre.
ENDIF.
ENDMETHOD.
METHOD daily_rate.
DATA(lt_rate) = rates( ).
ASSIGN lt_rate[ band = iv_band ] TO FIELD-SYMBOL(<ls_rate>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF iv_full_day = abap_true.
rv_rate = <ls_rate>-full_day.
ELSE.
rv_rate = <ls_rate>-half_day.
ENDIF.
ENDMETHOD.
METHOD monthly_fee.
DATA lv_gross TYPE p LENGTH 12 DECIMALS 5.
DATA lv_fee TYPE ty_amount.
lv_gross = iv_rate * iv_days * c_weeks_per_month.
lv_fee = round( val = lv_gross dec = 2 ).
IF iv_sibling <> abap_true.
lv_gross = lv_fee * c_sibling_discount.
lv_fee = round( val = lv_gross dec = 2 ).
ENDIF.
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rv_fee = lv_fee.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,24 @@
{
"id": "G1075",
"pool": "train",
"object_type": "CLAS",
"category": "A",
"attempts": [
{
"stage": "validate",
"oracle": 0,
"null": 0
},
{
"stage": "validate",
"oracle": 100.0,
"null": 0,
"mutation": {
"valid": 5,
"killed": 4,
"ok": true
}
}
],
"accepted": true
}

View File

@@ -0,0 +1,196 @@
CLASS {{p}}t02_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}childcare_pricer.
METHODS setup.
METHODS assert_fee
IMPORTING iv_expected TYPE {{p}}childcare_pricer=>ty_amount
iv_actual TYPE {{p}}childcare_pricer=>ty_amount.
METHODS baby_full_day_fee FOR TESTING.
METHODS toddler_half_day_fee FOR TESTING.
METHODS preschool_full_fee FOR TESTING.
METHODS band_boundaries FOR TESTING.
METHODS rounding_up FOR TESTING.
METHODS rounding_down FOR TESTING.
METHODS sibling_discount FOR TESTING.
METHODS fee_is_capped FOR TESTING.
METHODS cap_after_discount FOR TESTING.
METHODS sibling_below_cap FOR TESTING.
METHODS age_out_of_range FOR TESTING.
METHODS days_out_of_range FOR TESTING.
ENDCLASS.
CLASS {{p}}t02_hidden IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}childcare_pricer( ).
ENDMETHOD.
METHOD assert_fee.
cl_abap_unit_assert=>assert_equals( exp = iv_expected act = iv_actual ).
ENDMETHOD.
METHOD baby_full_day_fee.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 3
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '808.73' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD toddler_half_day_fee.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 3
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '430.45' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD preschool_full_fee.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 48
iv_days = 5
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '1000.04' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD band_boundaries.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 3
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '165.22' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 11
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '165.22' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 12
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '143.48' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 35
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '143.48' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 36
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '121.74' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 60
iv_days = 1
iv_full_day = abap_false
iv_sibling = abap_false ).
assert_fee( iv_expected = '121.74' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD rounding_up.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 48
iv_days = 1
iv_full_day = abap_true
iv_sibling = abap_false ).
assert_fee( iv_expected = '200.01' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD rounding_down.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 2
iv_full_day = abap_true
iv_sibling = abap_false ).
assert_fee( iv_expected = '539.15' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD sibling_discount.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 5
iv_full_day = abap_false
iv_sibling = abap_true ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '645.68' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD fee_is_capped.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 5
iv_full_day = abap_true
iv_sibling = abap_false ).
assert_fee( iv_expected = '1050.00' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD cap_after_discount.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 5
iv_full_day = abap_true
iv_sibling = abap_true ).
assert_fee( iv_expected = '1050.00' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD sibling_below_cap.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 4
iv_full_day = abap_true
iv_sibling = abap_true ).
assert_fee( iv_expected = '970.47' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD age_out_of_range.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 2
iv_days = 3
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-age
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 61
iv_days = 3
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-age
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD days_out_of_range.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 0
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-days
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 24
iv_days = 6
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-days
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ls_result = mo_cut->calculate( iv_age_months = 2
iv_days = 9
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-age
act = ls_result-reason ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,87 @@
{
"task": "G1075",
"mutants": [
{
"object": "{{P}}CHILDCARE_PRICER",
"mutant": "line 71: < -> >= (rel)",
"status": "killed",
"hidden": "1/12",
"failed_tests": [
"BABY_FULL_DAY_FEE",
"BAND_BOUNDARIES",
"CAP_AFTER_DISCOUNT",
"DAYS_OUT_OF_RANGE",
"FEE_IS_CAPPED",
"PRESCHOOL_FULL_FEE",
"ROUNDING_DOWN",
"ROUNDING_UP",
"SIBLING_BELOW_CAP",
"SIBLING_DISCOUNT",
"TODDLER_HALF_DAY_FEE"
]
},
{
"object": "{{P}}CHILDCARE_PRICER",
"mutant": "line 111: abap_true -> abap_false (bool)",
"status": "killed",
"hidden": "2/12",
"failed_tests": [
"BABY_FULL_DAY_FEE",
"BAND_BOUNDARIES",
"CAP_AFTER_DISCOUNT",
"FEE_IS_CAPPED",
"PRESCHOOL_FULL_FEE",
"ROUNDING_DOWN",
"ROUNDING_UP",
"SIBLING_BELOW_CAP",
"SIBLING_DISCOUNT",
"TODDLER_HALF_DAY_FEE"
]
},
{
"object": "{{P}}CHILDCARE_PRICER",
"mutant": "line 121: * -> / (arith)",
"status": "killed",
"hidden": "2/12",
"failed_tests": [
"BABY_FULL_DAY_FEE",
"BAND_BOUNDARIES",
"CAP_AFTER_DISCOUNT",
"FEE_IS_CAPPED",
"PRESCHOOL_FULL_FEE",
"ROUNDING_DOWN",
"ROUNDING_UP",
"SIBLING_BELOW_CAP",
"SIBLING_DISCOUNT",
"TODDLER_HALF_DAY_FEE"
]
},
{
"object": "{{P}}CHILDCARE_PRICER",
"mutant": "line 123: = -> <> (eq)",
"status": "killed",
"hidden": "4/12",
"failed_tests": [
"BABY_FULL_DAY_FEE",
"BAND_BOUNDARIES",
"PRESCHOOL_FULL_FEE",
"ROUNDING_DOWN",
"ROUNDING_UP",
"SIBLING_BELOW_CAP",
"SIBLING_DISCOUNT",
"TODDLER_HALF_DAY_FEE"
]
},
{
"object": "{{P}}CHILDCARE_PRICER",
"mutant": "line 125: 2 -> 3 (const)",
"status": "survived",
"hidden": "12/12",
"failed_tests": []
}
],
"valid": 5,
"killed": 4,
"kill_rate": 0.8,
"ok": true
}

View File

@@ -0,0 +1,132 @@
CLASS {{p}}childcare_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_age_band TYPE c LENGTH 4.
TYPES ty_reason TYPE c LENGTH 6.
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
reason TYPE ty_reason,
fee TYPE ty_amount,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
age TYPE ty_reason VALUE 'AGE',
days TYPE ty_reason VALUE 'DAYS',
END OF c_reason.
METHODS calculate
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
TYPES:
BEGIN OF ty_rate,
band TYPE ty_age_band,
full_day TYPE ty_amount,
half_day TYPE ty_amount,
END OF ty_rate,
tt_rate TYPE HASHED TABLE OF ty_rate WITH UNIQUE KEY band.
CONSTANTS:
BEGIN OF c_band,
baby TYPE ty_age_band VALUE 'BABY',
todd TYPE ty_age_band VALUE 'TODD',
pre TYPE ty_age_band VALUE 'PRE',
END OF c_band.
CONSTANTS:
c_weeks_per_month TYPE p LENGTH 4 DECIMALS 3 VALUE '4.348',
c_sibling_discount TYPE p LENGTH 4 DECIMALS 3 VALUE '0.900',
c_max_fee TYPE ty_amount VALUE '1050.00'.
METHODS rates
RETURNING VALUE(rt_rate) TYPE tt_rate.
METHODS age_band
IMPORTING iv_age_months TYPE i
RETURNING VALUE(rv_band) TYPE ty_age_band.
METHODS daily_rate
IMPORTING iv_band TYPE ty_age_band
iv_full_day TYPE abap_bool
RETURNING VALUE(rv_rate) TYPE ty_amount.
METHODS monthly_fee
IMPORTING iv_rate TYPE ty_amount
iv_days TYPE i
iv_sibling TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE ty_amount.
ENDCLASS.
CLASS {{p}}childcare_pricer IMPLEMENTATION.
METHOD calculate.
IF iv_age_months < 3 OR iv_age_months > 60.
rs_result-reason = c_reason-age.
RETURN.
ENDIF.
IF iv_days < 1 OR iv_days > 5.
rs_result-reason = c_reason-days.
RETURN.
ENDIF.
DATA(lv_rate) = daily_rate( iv_band = age_band( iv_age_months )
iv_full_day = iv_full_day ).
rs_result-fee = monthly_fee( iv_rate = lv_rate
iv_days = iv_days
iv_sibling = iv_sibling ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD rates.
rt_rate = VALUE #( ( band = c_band-baby
full_day = '62.00'
half_day = '38.00' )
( band = c_band-todd
full_day = '54.00'
half_day = '33.00' )
( band = c_band-pre
full_day = '46.00'
half_day = '28.00' ) ).
ENDMETHOD.
METHOD age_band.
IF iv_age_months < 12.
rv_band = c_band-baby.
ELSEIF iv_age_months < 36.
rv_band = c_band-todd.
ELSE.
rv_band = c_band-pre.
ENDIF.
ENDMETHOD.
METHOD daily_rate.
DATA(lt_rate) = rates( ).
ASSIGN lt_rate[ band = iv_band ] TO FIELD-SYMBOL(<ls_rate>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF iv_full_day = abap_true.
rv_rate = <ls_rate>-full_day.
ELSE.
rv_rate = <ls_rate>-half_day.
ENDIF.
ENDMETHOD.
METHOD monthly_fee.
DATA lv_gross TYPE p LENGTH 12 DECIMALS 5.
DATA lv_fee TYPE ty_amount.
lv_gross = iv_rate * iv_days * c_weeks_per_month.
lv_fee = round( val = lv_gross dec = 2 ).
IF iv_sibling = abap_true.
lv_gross = lv_fee * c_sibling_discount.
lv_fee = round( val = lv_gross dec = 2 ).
ENDIF.
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rv_fee = lv_fee.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,85 @@
CLASS ltc_childcare_pricer DEFINITION FINAL FOR TESTING
DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}childcare_pricer.
METHODS setup.
METHODS assert_fee
IMPORTING iv_expected TYPE {{p}}childcare_pricer=>ty_amount
iv_actual TYPE {{p}}childcare_pricer=>ty_amount.
METHODS baby_full_day FOR TESTING.
METHODS toddler_half_day FOR TESTING.
METHODS sibling_discount FOR TESTING.
METHODS fee_is_capped FOR TESTING.
METHODS age_out_of_range FOR TESTING.
METHODS days_out_of_range FOR TESTING.
ENDCLASS.
CLASS ltc_childcare_pricer IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}childcare_pricer( ).
ENDMETHOD.
METHOD assert_fee.
cl_abap_unit_assert=>assert_equals( exp = iv_expected act = iv_actual ).
ENDMETHOD.
METHOD baby_full_day.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 3
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '808.73' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD toddler_half_day.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 3
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-ok
act = ls_result-reason ).
assert_fee( iv_expected = '430.45' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD sibling_discount.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 5
iv_full_day = abap_false
iv_sibling = abap_true ).
assert_fee( iv_expected = '645.68' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD fee_is_capped.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 6
iv_days = 5
iv_full_day = abap_true
iv_sibling = abap_false ).
assert_fee( iv_expected = '1050.00' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD age_out_of_range.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 2
iv_days = 3
iv_full_day = abap_true
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-age
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ENDMETHOD.
METHOD days_out_of_range.
DATA(ls_result) = mo_cut->calculate( iv_age_months = 24
iv_days = 6
iv_full_day = abap_false
iv_sibling = abap_false ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}childcare_pricer=>c_reason-days
act = ls_result-reason ).
assert_fee( iv_expected = '0.00' iv_actual = ls_result-fee ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,65 @@
# 1. Goal
Calculate the monthly fee for a child at a day care centre. The billing program
calls the calculation for each child before it creates the invoice. The program
needs the fee and one reason code for each child.
# 2. Open questions
None.
# 3. Context
- The class {{P}}CHILDCARE_PRICER does not exist yet. Create it in package $TMP.
- The billing program is not part of this task. It calls the calculation for
each child and reads the reason and the fee.
# 4. Contract
- Create the class {{P}}CHILDCARE_PRICER in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- Define these public types:
TY_AGE_BAND TYPE c LENGTH 4
TY_REASON TYPE c LENGTH 6
TY_AMOUNT TYPE p LENGTH 8 DECIMALS 2
TY_RESULT a structure with the components REASON (TY_REASON) and
FEE (TY_AMOUNT)
- Define the public constant structure C_REASON with the components OK, AGE and
DAYS. Each component has the type TY_REASON.
- Add one public method:
CALCULATE
IMPORTING iv_age_months TYPE i
iv_days TYPE i
iv_full_day TYPE abap_bool
iv_sibling TYPE abap_bool
RETURNING VALUE(rs_result) TYPE ty_result
- Do not add other public methods.
# 5. Business rules
Apply the rules in this sequence.
1. If iv_age_months is less than 3 or more than 60, return the reason AGE and
the fee 0.
2. If iv_days is less than 1 or more than 5, return the reason DAYS and the fee
0.
3. Find the age band of the child:
3 to 11 months: BABY
12 to 35 months: TODD
36 to 60 months: PRE
4. Find the daily rate of the age band:
BABY: 62.00 for a full day, 38.00 for a half day
TODD: 54.00 for a full day, 33.00 for a half day
PRE: 46.00 for a full day, 28.00 for a half day
iv_full_day = abap_true means a full day. All other values mean a half day.
5. The monthly fee is the daily rate multiplied by iv_days and by 4.348. Round
the result to 2 decimal places.
6. If iv_sibling = abap_true, multiply the monthly fee by 0.9 and round the
result to 2 decimal places.
7. If the monthly fee is more than 1050.00, set it to 1050.00.
8. Return the reason OK and the monthly fee.
# 6. Constraints
- Release target: 8.16.
- Coding standards: Clean ABAP. Method length below 40 statements. No global
variables. No comment that restates the code.
- Out of scope: no other object.
# 7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.

View File

@@ -0,0 +1,41 @@
{
"id": "G1075",
"category": "A",
"object_type": "CLAS",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 60,
"max_activations": 15
},
"seed": [],
"contract": [
{
"type": "CLAS",
"name": "{{P}}CHILDCARE_PRICER"
}
],
"out_of_scope": [],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T02_HIDDEN",
"file": "hidden/t02_hidden.clas.abap",
"description": "T02 hidden tests for the childcare monthly fee"
}
],
"reference": [
{
"type": "CLAS",
"name": "{{P}}CHILDCARE_PRICER",
"file": "reference/childcare_pricer.clas.abap",
"description": "Childcare monthly fee calculation",
"testclasses_file": "reference/childcare_pricer.testclasses.abap"
}
],
"craft_checks": [
"method_length",
"db_operation_in_loop"
]
}