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,103 @@
CLASS {{p}}boat_hire_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_reason TYPE c LENGTH 10.
TYPES ty_price TYPE p LENGTH 10 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
price TYPE ty_price,
reason TYPE ty_reason,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
category TYPE ty_reason VALUE 'CATEGORY',
days TYPE ty_reason VALUE 'DAYS',
crew TYPE ty_reason VALUE 'CREW',
month TYPE ty_reason VALUE 'MONTH',
END OF c_reason.
METHODS price
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
CONSTANTS:
c_max_days TYPE i VALUE 28,
c_max_crew TYPE i VALUE 12,
c_max_month TYPE i VALUE 12,
c_free_crew TYPE i VALUE 6,
c_long_hire_days TYPE i VALUE 7,
c_long_hire_discount TYPE ty_price VALUE '0.90',
c_crew_surcharge TYPE ty_price VALUE '15.00'.
METHODS validate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rv_reason) TYPE ty_reason.
METHODS calculate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_factor TYPE ty_price
RETURNING VALUE(rv_price) TYPE ty_price.
ENDCLASS.
CLASS {{p}}boat_hire_pricer IMPLEMENTATION.
METHOD price.
DATA(lo_rates) = NEW {{p}}hire_rates( ).
DATA(lv_rate) = lo_rates->get_daily_rate( iv_category ).
DATA(lv_reason) = validate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_month = iv_month ).
IF lv_reason <> c_reason-ok.
rs_result-reason = lv_reason.
RETURN.
ENDIF.
rs_result-price = calculate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_factor = lo_rates->get_season_factor( iv_month ) ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD validate.
IF iv_rate <= 0.
rv_reason = c_reason-category.
ELSEIF iv_days < 1 AND iv_days > c_max_days.
rv_reason = c_reason-days.
ELSEIF iv_crew < 1 OR iv_crew > c_max_crew.
rv_reason = c_reason-crew.
ELSEIF iv_month < 1 OR iv_month > c_max_month.
rv_reason = c_reason-month.
ELSE.
rv_reason = c_reason-ok.
ENDIF.
ENDMETHOD.
METHOD calculate.
DATA lv_price TYPE ty_price.
lv_price = iv_rate * iv_days * iv_factor.
IF iv_days >= c_long_hire_days.
lv_price = lv_price * c_long_hire_discount.
ENDIF.
IF iv_crew > c_free_crew.
lv_price = lv_price + ( iv_crew - c_free_crew ) * c_crew_surcharge * iv_days.
ENDIF.
rv_price = lv_price.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,103 @@
CLASS {{p}}boat_hire_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_reason TYPE c LENGTH 10.
TYPES ty_price TYPE p LENGTH 10 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
price TYPE ty_price,
reason TYPE ty_reason,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
category TYPE ty_reason VALUE 'CATEGORY',
days TYPE ty_reason VALUE 'DAYS',
crew TYPE ty_reason VALUE 'CREW',
month TYPE ty_reason VALUE 'MONTH',
END OF c_reason.
METHODS price
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
CONSTANTS:
c_max_days TYPE i VALUE 28,
c_max_crew TYPE i VALUE 12,
c_max_month TYPE i VALUE 12,
c_free_crew TYPE i VALUE 6,
c_long_hire_days TYPE i VALUE 7,
c_long_hire_discount TYPE ty_price VALUE '0.90',
c_crew_surcharge TYPE ty_price VALUE '15.00'.
METHODS validate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rv_reason) TYPE ty_reason.
METHODS calculate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_factor TYPE ty_price
RETURNING VALUE(rv_price) TYPE ty_price.
ENDCLASS.
CLASS {{p}}boat_hire_pricer IMPLEMENTATION.
METHOD price.
DATA(lo_rates) = NEW {{p}}hire_rates( ).
DATA(lv_rate) = lo_rates->get_daily_rate( iv_category ).
DATA(lv_reason) = validate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_month = iv_month ).
IF lv_reason <> c_reason-ok.
rs_result-reason = lv_reason.
RETURN.
ENDIF.
rs_result-price = calculate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_factor = lo_rates->get_season_factor( iv_month ) ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD validate.
IF iv_rate <= 0.
rv_reason = c_reason-category.
ELSEIF iv_days < 1 OR iv_days <= c_max_days.
rv_reason = c_reason-days.
ELSEIF iv_crew < 1 OR iv_crew > c_max_crew.
rv_reason = c_reason-crew.
ELSEIF iv_month < 1 OR iv_month > c_max_month.
rv_reason = c_reason-month.
ELSE.
rv_reason = c_reason-ok.
ENDIF.
ENDMETHOD.
METHOD calculate.
DATA lv_price TYPE ty_price.
lv_price = iv_rate * iv_days * iv_factor.
IF iv_days >= c_long_hire_days.
lv_price = lv_price * c_long_hire_discount.
ENDIF.
IF iv_crew > c_free_crew.
lv_price = lv_price + ( iv_crew - c_free_crew ) * c_crew_surcharge * iv_days.
ENDIF.
rv_price = lv_price.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,103 @@
CLASS {{p}}boat_hire_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_reason TYPE c LENGTH 10.
TYPES ty_price TYPE p LENGTH 10 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
price TYPE ty_price,
reason TYPE ty_reason,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
category TYPE ty_reason VALUE 'CATEGORY',
days TYPE ty_reason VALUE 'DAYS',
crew TYPE ty_reason VALUE 'CREW',
month TYPE ty_reason VALUE 'MONTH',
END OF c_reason.
METHODS price
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
CONSTANTS:
c_max_days TYPE i VALUE 28,
c_max_crew TYPE i VALUE 12,
c_max_month TYPE i VALUE 12,
c_free_crew TYPE i VALUE 6,
c_long_hire_days TYPE i VALUE 7,
c_long_hire_discount TYPE ty_price VALUE '0.90',
c_crew_surcharge TYPE ty_price VALUE '15.00'.
METHODS validate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rv_reason) TYPE ty_reason.
METHODS calculate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_factor TYPE ty_price
RETURNING VALUE(rv_price) TYPE ty_price.
ENDCLASS.
CLASS {{p}}boat_hire_pricer IMPLEMENTATION.
METHOD price.
DATA(lo_rates) = NEW {{p}}hire_rates( ).
DATA(lv_rate) = lo_rates->get_daily_rate( iv_category ).
DATA(lv_reason) = validate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_month = iv_month ).
IF lv_reason <> c_reason-ok.
rs_result-reason = lv_reason.
RETURN.
ENDIF.
rs_result-price = calculate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_factor = lo_rates->get_season_factor( iv_month ) ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD validate.
IF iv_rate <= 0.
rv_reason = c_reason-category.
ELSEIF iv_days < 1 OR iv_days > c_max_days.
rv_reason = c_reason-days.
ELSEIF iv_crew < 1 AND iv_crew > c_max_crew.
rv_reason = c_reason-crew.
ELSEIF iv_month < 1 OR iv_month > c_max_month.
rv_reason = c_reason-month.
ELSE.
rv_reason = c_reason-ok.
ENDIF.
ENDMETHOD.
METHOD calculate.
DATA lv_price TYPE ty_price.
lv_price = iv_rate * iv_days * iv_factor.
IF iv_days >= c_long_hire_days.
lv_price = lv_price * c_long_hire_discount.
ENDIF.
IF iv_crew > c_free_crew.
lv_price = lv_price + ( iv_crew - c_free_crew ) * c_crew_surcharge * iv_days.
ENDIF.
rv_price = lv_price.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,103 @@
CLASS {{p}}boat_hire_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_reason TYPE c LENGTH 10.
TYPES ty_price TYPE p LENGTH 10 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
price TYPE ty_price,
reason TYPE ty_reason,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
category TYPE ty_reason VALUE 'CATEGORY',
days TYPE ty_reason VALUE 'DAYS',
crew TYPE ty_reason VALUE 'CREW',
month TYPE ty_reason VALUE 'MONTH',
END OF c_reason.
METHODS price
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
CONSTANTS:
c_max_days TYPE i VALUE 28,
c_max_crew TYPE i VALUE 12,
c_max_month TYPE i VALUE 12,
c_free_crew TYPE i VALUE 6,
c_long_hire_days TYPE i VALUE 7,
c_long_hire_discount TYPE ty_price VALUE '0.90',
c_crew_surcharge TYPE ty_price VALUE '15.00'.
METHODS validate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rv_reason) TYPE ty_reason.
METHODS calculate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_factor TYPE ty_price
RETURNING VALUE(rv_price) TYPE ty_price.
ENDCLASS.
CLASS {{p}}boat_hire_pricer IMPLEMENTATION.
METHOD price.
DATA(lo_rates) = NEW {{p}}hire_rates( ).
DATA(lv_rate) = lo_rates->get_daily_rate( iv_category ).
DATA(lv_reason) = validate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_month = iv_month ).
IF lv_reason <> c_reason-ok.
rs_result-reason = lv_reason.
RETURN.
ENDIF.
rs_result-price = calculate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_factor = lo_rates->get_season_factor( iv_month ) ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD validate.
IF iv_rate <= 0.
rv_reason = c_reason-category.
ELSEIF iv_days < 1 OR iv_days > c_max_days.
rv_reason = c_reason-days.
ELSEIF iv_crew < 1 OR iv_crew > c_max_crew.
rv_reason = c_reason-crew.
ELSEIF iv_month < 1 OR iv_month > c_max_month.
rv_reason = c_reason-month.
ELSE.
rv_reason = c_reason-ok.
ENDIF.
ENDMETHOD.
METHOD calculate.
DATA lv_price TYPE ty_price.
lv_price = iv_rate * iv_days * iv_factor.
IF iv_days >= c_long_hire_days.
lv_price = lv_price * c_long_hire_discount.
ENDIF.
IF iv_crew > c_free_crew.
lv_price = lv_price + ( iv_crew - c_free_crew ) / c_crew_surcharge * iv_days.
ENDIF.
rv_price = lv_price.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,19 @@
{
"id": "G1065",
"pool": "train",
"object_type": "CLAS",
"category": "F",
"attempts": [
{
"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.
CONSTANTS:
c_208 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '208.00',
c_312 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '312.00',
c_468 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '468.00',
c_513 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '513.00',
c_936 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '936.00',
c_1344 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '1344.00',
c_6451 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '6451.20',
c_zero TYPE {{p}}boat_hire_pricer=>ty_price VALUE 0.
DATA mo_cut TYPE REF TO {{p}}boat_hire_pricer.
METHODS setup.
METHODS narrow_high_season FOR TESTING.
METHODS wide_long_hire FOR TESTING.
METHODS barge_low_season FOR TESTING.
METHODS lowercase_category FOR TESTING.
METHODS six_days_no_discount FOR TESTING.
METHODS crew_surcharge_boundary FOR TESTING.
METHODS max_bounds_ok FOR TESTING.
METHODS unknown_category FOR TESTING.
METHODS days_out_of_range FOR TESTING.
METHODS crew_out_of_range FOR TESTING.
METHODS month_out_of_range FOR TESTING.
METHODS reason_order FOR TESTING.
ENDCLASS.
CLASS {{p}}t02_hidden IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}boat_hire_pricer( ).
ENDMETHOD.
METHOD narrow_high_season.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_468 act = ls_result-price ).
ENDMETHOD.
METHOD wide_long_hire.
DATA(ls_result) = mo_cut->price( iv_category = 'WIDE'
iv_days = 7
iv_crew = 8
iv_month = 5 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_1344 act = ls_result-price ).
ENDMETHOD.
METHOD barge_low_season.
DATA(ls_result) = mo_cut->price( iv_category = 'BARGE'
iv_days = 1
iv_crew = 1
iv_month = 12 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_208 act = ls_result-price ).
ENDMETHOD.
METHOD lowercase_category.
DATA(ls_result) = mo_cut->price( iv_category = 'narrow'
iv_days = 2
iv_crew = 2
iv_month = 6 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_312 act = ls_result-price ).
ENDMETHOD.
METHOD six_days_no_discount.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 6
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = c_936 act = ls_result-price ).
ENDMETHOD.
METHOD crew_surcharge_boundary.
DATA(ls_six) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 6
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = c_468 act = ls_six-price ).
DATA(ls_seven) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 7
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = c_513 act = ls_seven-price ).
ENDMETHOD.
METHOD max_bounds_ok.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 28
iv_crew = 12
iv_month = 6 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_6451 act = ls_result-price ).
ENDMETHOD.
METHOD unknown_category.
DATA(ls_result) = mo_cut->price( iv_category = 'CANOE'
iv_days = 3
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-category
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_zero act = ls_result-price ).
ENDMETHOD.
METHOD days_out_of_range.
DATA(ls_zero) = mo_cut->price( iv_category = 'NARROW'
iv_days = 0
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-days
act = ls_zero-reason ).
DATA(ls_high) = mo_cut->price( iv_category = 'NARROW'
iv_days = 29
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-days
act = ls_high-reason ).
ENDMETHOD.
METHOD crew_out_of_range.
DATA(ls_zero) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 0
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-crew
act = ls_zero-reason ).
DATA(ls_high) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 13
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-crew
act = ls_high-reason ).
ENDMETHOD.
METHOD month_out_of_range.
DATA(ls_zero) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 0 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-month
act = ls_zero-reason ).
DATA(ls_high) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 13 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-month
act = ls_high-reason ).
ENDMETHOD.
METHOD reason_order.
DATA(ls_result) = mo_cut->price( iv_category = 'CANOE'
iv_days = 0
iv_crew = 0
iv_month = 0 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-category
act = ls_result-reason msg = `category first` ).
ls_result = mo_cut->price( iv_category = 'NARROW'
iv_days = 0
iv_crew = 0
iv_month = 0 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-days
act = ls_result-reason msg = `days before crew` ).
ls_result = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 0
iv_month = 0 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-crew
act = ls_result-reason msg = `crew before month` ).
ls_result = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 0 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-month
act = ls_result-reason msg = `month last` ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,66 @@
{
"task": "G1065",
"mutants": [
{
"object": "{{P}}BOAT_HIRE_PRICER",
"mutant": "line 78: OR -> AND (logic)",
"status": "killed",
"hidden": "10/12",
"failed_tests": [
"DAYS_OUT_OF_RANGE",
"REASON_ORDER"
]
},
{
"object": "{{P}}BOAT_HIRE_PRICER",
"mutant": "line 78: > -> <= (rel)",
"status": "killed",
"hidden": "1/12",
"failed_tests": [
"BARGE_LOW_SEASON",
"CREW_OUT_OF_RANGE",
"CREW_SURCHARGE_BOUNDARY",
"DAYS_OUT_OF_RANGE",
"LOWERCASE_CATEGORY",
"MAX_BOUNDS_OK",
"MONTH_OUT_OF_RANGE",
"NARROW_HIGH_SEASON",
"REASON_ORDER",
"SIX_DAYS_NO_DISCOUNT",
"WIDE_LONG_HIRE"
]
},
{
"object": "{{P}}BOAT_HIRE_PRICER",
"mutant": "line 80: OR -> AND (logic)",
"status": "killed",
"hidden": "10/12",
"failed_tests": [
"CREW_OUT_OF_RANGE",
"REASON_ORDER"
]
},
{
"object": "{{P}}BOAT_HIRE_PRICER",
"mutant": "line 82: 1 -> 2 (const)",
"status": "survived",
"hidden": "12/12",
"failed_tests": []
},
{
"object": "{{P}}BOAT_HIRE_PRICER",
"mutant": "line 98: * -> / (arith)",
"status": "killed",
"hidden": "9/12",
"failed_tests": [
"CREW_SURCHARGE_BOUNDARY",
"MAX_BOUNDS_OK",
"WIDE_LONG_HIRE"
]
}
],
"valid": 5,
"killed": 4,
"kill_rate": 0.8,
"ok": true
}

View File

@@ -0,0 +1,103 @@
CLASS {{p}}boat_hire_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_reason TYPE c LENGTH 10.
TYPES ty_price TYPE p LENGTH 10 DECIMALS 2.
TYPES:
BEGIN OF ty_result,
price TYPE ty_price,
reason TYPE ty_reason,
END OF ty_result.
CONSTANTS:
BEGIN OF c_reason,
ok TYPE ty_reason VALUE 'OK',
category TYPE ty_reason VALUE 'CATEGORY',
days TYPE ty_reason VALUE 'DAYS',
crew TYPE ty_reason VALUE 'CREW',
month TYPE ty_reason VALUE 'MONTH',
END OF c_reason.
METHODS price
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
PRIVATE SECTION.
CONSTANTS:
c_max_days TYPE i VALUE 28,
c_max_crew TYPE i VALUE 12,
c_max_month TYPE i VALUE 12,
c_free_crew TYPE i VALUE 6,
c_long_hire_days TYPE i VALUE 7,
c_long_hire_discount TYPE ty_price VALUE '0.90',
c_crew_surcharge TYPE ty_price VALUE '15.00'.
METHODS validate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rv_reason) TYPE ty_reason.
METHODS calculate
IMPORTING iv_rate TYPE ty_price
iv_days TYPE i
iv_crew TYPE i
iv_factor TYPE ty_price
RETURNING VALUE(rv_price) TYPE ty_price.
ENDCLASS.
CLASS {{p}}boat_hire_pricer IMPLEMENTATION.
METHOD price.
DATA(lo_rates) = NEW {{p}}hire_rates( ).
DATA(lv_rate) = lo_rates->get_daily_rate( iv_category ).
DATA(lv_reason) = validate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_month = iv_month ).
IF lv_reason <> c_reason-ok.
rs_result-reason = lv_reason.
RETURN.
ENDIF.
rs_result-price = calculate( iv_rate = lv_rate
iv_days = iv_days
iv_crew = iv_crew
iv_factor = lo_rates->get_season_factor( iv_month ) ).
rs_result-reason = c_reason-ok.
ENDMETHOD.
METHOD validate.
IF iv_rate <= 0.
rv_reason = c_reason-category.
ELSEIF iv_days < 1 OR iv_days > c_max_days.
rv_reason = c_reason-days.
ELSEIF iv_crew < 1 OR iv_crew > c_max_crew.
rv_reason = c_reason-crew.
ELSEIF iv_month < 1 OR iv_month > c_max_month.
rv_reason = c_reason-month.
ELSE.
rv_reason = c_reason-ok.
ENDIF.
ENDMETHOD.
METHOD calculate.
DATA lv_price TYPE ty_price.
lv_price = iv_rate * iv_days * iv_factor.
IF iv_days >= c_long_hire_days.
lv_price = lv_price * c_long_hire_discount.
ENDIF.
IF iv_crew > c_free_crew.
lv_price = lv_price + ( iv_crew - c_free_crew ) * c_crew_surcharge * iv_days.
ENDIF.
rv_price = lv_price.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,90 @@
CLASS ltc_boat_hire_pricer DEFINITION FINAL FOR TESTING
DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
CONSTANTS:
c_468 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '468.00',
c_1344 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '1344.00',
c_208 TYPE {{p}}boat_hire_pricer=>ty_price VALUE '208.00',
c_zero TYPE {{p}}boat_hire_pricer=>ty_price VALUE 0.
DATA mo_cut TYPE REF TO {{p}}boat_hire_pricer.
METHODS setup.
METHODS narrow_ok FOR TESTING.
METHODS wide_discount FOR TESTING.
METHODS low_season FOR TESTING.
METHODS unknown_category FOR TESTING.
METHODS bad_days FOR TESTING.
METHODS bad_crew FOR TESTING.
METHODS bad_month FOR TESTING.
ENDCLASS.
CLASS ltc_boat_hire_pricer IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}boat_hire_pricer( ).
ENDMETHOD.
METHOD narrow_ok.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-ok
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_468 act = ls_result-price ).
ENDMETHOD.
METHOD wide_discount.
DATA(ls_result) = mo_cut->price( iv_category = 'WIDE'
iv_days = 7
iv_crew = 8
iv_month = 5 ).
cl_abap_unit_assert=>assert_equals( exp = c_1344 act = ls_result-price ).
ENDMETHOD.
METHOD low_season.
DATA(ls_result) = mo_cut->price( iv_category = 'BARGE'
iv_days = 1
iv_crew = 1
iv_month = 12 ).
cl_abap_unit_assert=>assert_equals( exp = c_208 act = ls_result-price ).
ENDMETHOD.
METHOD unknown_category.
DATA(ls_result) = mo_cut->price( iv_category = 'CANOE'
iv_days = 3
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-category
act = ls_result-reason ).
cl_abap_unit_assert=>assert_equals( exp = c_zero act = ls_result-price ).
ENDMETHOD.
METHOD bad_days.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 0
iv_crew = 4
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-days
act = ls_result-reason ).
ENDMETHOD.
METHOD bad_crew.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 13
iv_month = 7 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-crew
act = ls_result-reason ).
ENDMETHOD.
METHOD bad_month.
DATA(ls_result) = mo_cut->price( iv_category = 'NARROW'
iv_days = 3
iv_crew = 4
iv_month = 13 ).
cl_abap_unit_assert=>assert_equals( exp = {{p}}boat_hire_pricer=>c_reason-month
act = ls_result-reason ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,40 @@
CLASS {{p}}hire_rates DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_rate TYPE p LENGTH 10 DECIMALS 2.
METHODS get_daily_rate
IMPORTING iv_category TYPE string
RETURNING VALUE(rv_rate) TYPE ty_rate.
METHODS get_season_factor
IMPORTING iv_month TYPE i
RETURNING VALUE(rv_factor) TYPE ty_rate.
ENDCLASS.
CLASS {{p}}hire_rates IMPLEMENTATION.
METHOD get_daily_rate.
CASE to_upper( iv_category ).
WHEN 'NARROW'.
rv_rate = 120.
WHEN 'WIDE'.
rv_rate = 180.
WHEN 'BARGE'.
rv_rate = 260.
WHEN OTHERS.
rv_rate = 0.
ENDCASE.
ENDMETHOD.
METHOD get_season_factor.
IF iv_month >= 6 AND iv_month <= 9.
rv_factor = '1.30'.
ELSEIF iv_month = 4 OR iv_month = 5 OR iv_month = 10.
rv_factor = '1.00'.
ELSEIF iv_month >= 1 AND iv_month <= 12.
rv_factor = '0.80'.
ELSE.
rv_factor = 0.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,60 @@
# 1. Goal
A canal boat hire company prices the hire of a narrowboat. The booking program
calls the calculation before it creates a booking confirmation. The calculation
returns the hire price in euro and a reason code. A valid request returns the
reason OK.
# 2. Open questions
None.
# 3. Context
- The class {{P}}HIRE_RATES exists in package $TMP. It is active and public.
- The class provides the daily rate of each boat category and the season factor
of each month. Read the class in the system to learn its interface, the
category names and the rates. Do not change the class.
# 4. Contract
- Create the class {{P}}BOAT_HIRE_PRICER in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- Public types:
- TY_REASON, type c, length 10.
- TY_PRICE, type p, length 10, 2 decimals.
- TY_RESULT, a structure with the components PRICE (type TY_PRICE) and
REASON (type TY_REASON).
- Public constant structure C_REASON with the components OK, CATEGORY, DAYS,
CREW and MONTH. Each component has the type TY_REASON. The values are 'OK',
'CATEGORY', 'DAYS', 'CREW' and 'MONTH'.
- One public method:
PRICE
IMPORTING iv_category TYPE string
iv_days TYPE i
iv_crew TYPE i
iv_month TYPE i
RETURNING VALUE(rs_result) TYPE ty_result.
- Do not add other public methods.
# 5. Business rules
Apply the rules in this sequence. The first rule that fails decides the reason.
If a rule fails, the result has this reason and the price 0.
1. The category must be a category that {{P}}HIRE_RATES knows. The category
name is not case-sensitive. If not, return CATEGORY.
2. iv_days must be between 1 and 28. If not, return DAYS.
3. iv_crew must be between 1 and 12. If not, return CREW.
4. iv_month must be between 1 and 12. If not, return MONTH.
5. Calculate the base price: the daily rate of the category multiplied by
iv_days multiplied by the season factor of iv_month.
6. If iv_days is 7 or more, subtract 10 % from the base price.
7. If iv_crew is more than 6, add 15.00 EUR for each crew member above 6 for
each day of the hire.
8. Round the result of rule 7 to 2 decimals. Return OK.
# 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: do not change {{P}}HIRE_RATES.
# 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,50 @@
{
"id": "G1065",
"category": "F",
"object_type": "CLAS",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 60,
"max_activations": 15
},
"seed": [
{
"type": "CLAS",
"name": "{{P}}HIRE_RATES",
"file": "seed/hire_rates.clas.abap",
"description": "Daily rates per boat category and season factors per month"
}
],
"contract": [
{
"type": "CLAS",
"name": "{{P}}BOAT_HIRE_PRICER"
}
],
"out_of_scope": [
"{{P}}HIRE_RATES"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T02_HIDDEN",
"file": "hidden/t02_hidden.clas.abap",
"description": "T02 hidden tests"
}
],
"reference": [
{
"type": "CLAS",
"name": "{{P}}BOAT_HIRE_PRICER",
"file": "reference/boat_hire_pricer.clas.abap",
"description": "Canal boat hire pricer",
"testclasses_file": "reference/boat_hire_pricer.testclasses.abap"
}
],
"craft_checks": [
"method_length",
"db_operation_in_loop"
]
}