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,113 @@
CLASS {{p}}heli_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS calculate
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
ev_fee TYPE decfloat34
RAISING
{{p}}cx_heli_invalid.
PRIVATE SECTION.
CONSTANTS:
c_rate_scenic TYPE decfloat34 VALUE '8',
c_rate_training TYPE decfloat34 VALUE '12',
c_pax_surcharge TYPE decfloat34 VALUE '15',
c_member_rate TYPE decfloat34 VALUE '0.875',
c_min_fee TYPE decfloat34 VALUE '50',
c_max_fee TYPE decfloat34 VALUE '1500',
c_max_pax TYPE i VALUE 6,
c_min_minutes TYPE i VALUE 5.
METHODS check_input
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
RAISING
{{p}}cx_heli_invalid.
METHODS scenic_fee
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS round_fee
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS apply_limits
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}heli_pricer IMPLEMENTATION.
METHOD calculate.
check_input( iv_passengers = iv_passengers iv_minutes = iv_minutes ).
ev_skip = abap_false.
CASE iv_tour_type.
WHEN 'SC'.
ev_fee = apply_limits( round_fee( scenic_fee( iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member ) ) ).
WHEN 'TR'.
ev_fee = apply_limits( round_fee( CONV decfloat34( iv_minutes ) / c_rate_training ) ).
WHEN 'CH'.
ev_skip = abap_true.
WHEN OTHERS.
ev_fee = 0.
ENDCASE.
ENDMETHOD.
METHOD check_input.
IF iv_passengers < 1 OR iv_passengers > c_max_pax.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-passengers.
ENDIF.
IF iv_minutes < c_min_minutes.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-minutes.
ENDIF.
ENDMETHOD.
METHOD scenic_fee.
rv_fee = CONV decfloat34( iv_minutes ) * c_rate_scenic
+ CONV decfloat34( iv_passengers ) * c_pax_surcharge.
IF iv_member = abap_true.
rv_fee = rv_fee * c_member_rate.
ENDIF.
ENDMETHOD.
METHOD round_fee.
rv_fee = round( val = iv_fee dec = 2 mode = cl_abap_math=>round_half_up ).
ENDMETHOD.
METHOD apply_limits.
rv_fee = iv_fee.
IF rv_fee < c_min_fee.
rv_fee = c_min_fee.
ELSEIF rv_fee > c_max_fee.
rv_fee = c_max_fee.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,43 @@
FUNCTION {{p}}heli_fee
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
CHANGING
cv_fee TYPE decfloat34
EXCEPTIONS
invalid_passengers
invalid_minutes.
DATA lo_pricer TYPE REF TO {{p}}heli_pricer.
DATA lv_fee TYPE decfloat34.
lo_pricer = NEW #( ).
TRY.
lo_pricer->calculate(
EXPORTING
iv_tour_type = iv_tour_type
iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member
IMPORTING
ev_skip = ev_skip
ev_fee = lv_fee ).
CATCH {{p}}cx_heli_invalid INTO DATA(lo_error).
CASE lo_error->mv_reason.
WHEN {{p}}cx_heli_invalid=>co_reason-passengers.
RAISE invalid_passengers.
WHEN OTHERS.
RAISE invalid_minutes.
ENDCASE.
ENDTRY.
IF ev_skip <> abap_false.
cv_fee = lv_fee.
ENDIF.
ENDFUNCTION.

View File

@@ -0,0 +1,113 @@
CLASS {{p}}heli_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS calculate
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
ev_fee TYPE decfloat34
RAISING
{{p}}cx_heli_invalid.
PRIVATE SECTION.
CONSTANTS:
c_rate_scenic TYPE decfloat34 VALUE '8',
c_rate_training TYPE decfloat34 VALUE '12',
c_pax_surcharge TYPE decfloat34 VALUE '15',
c_member_rate TYPE decfloat34 VALUE '0.875',
c_min_fee TYPE decfloat34 VALUE '50',
c_max_fee TYPE decfloat34 VALUE '1500',
c_max_pax TYPE i VALUE 6,
c_min_minutes TYPE i VALUE 5.
METHODS check_input
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
RAISING
{{p}}cx_heli_invalid.
METHODS scenic_fee
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS round_fee
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS apply_limits
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}heli_pricer IMPLEMENTATION.
METHOD calculate.
check_input( iv_passengers = iv_passengers iv_minutes = iv_minutes ).
ev_skip = abap_false.
CASE iv_tour_type.
WHEN 'SC'.
ev_fee = apply_limits( round_fee( scenic_fee( iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member ) ) ).
WHEN 'TR'.
ev_fee = apply_limits( round_fee( CONV decfloat34( iv_minutes ) * c_rate_training ) ).
WHEN 'CH'.
ev_skip = abap_true.
WHEN OTHERS.
ev_fee = 0.
ENDCASE.
ENDMETHOD.
METHOD check_input.
IF iv_passengers < 1 AND iv_passengers > c_max_pax.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-passengers.
ENDIF.
IF iv_minutes < c_min_minutes.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-minutes.
ENDIF.
ENDMETHOD.
METHOD scenic_fee.
rv_fee = CONV decfloat34( iv_minutes ) * c_rate_scenic
+ CONV decfloat34( iv_passengers ) * c_pax_surcharge.
IF iv_member = abap_true.
rv_fee = rv_fee * c_member_rate.
ENDIF.
ENDMETHOD.
METHOD round_fee.
rv_fee = round( val = iv_fee dec = 2 mode = cl_abap_math=>round_half_up ).
ENDMETHOD.
METHOD apply_limits.
rv_fee = iv_fee.
IF rv_fee < c_min_fee.
rv_fee = c_min_fee.
ELSEIF rv_fee > c_max_fee.
rv_fee = c_max_fee.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,43 @@
FUNCTION {{p}}heli_fee
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
CHANGING
cv_fee TYPE decfloat34
EXCEPTIONS
invalid_passengers
invalid_minutes.
DATA lo_pricer TYPE REF TO {{p}}heli_pricer.
DATA lv_fee TYPE decfloat34.
lo_pricer = NEW #( ).
TRY.
lo_pricer->calculate(
EXPORTING
iv_tour_type = iv_tour_type
iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member
IMPORTING
ev_skip = ev_skip
ev_fee = lv_fee ).
CATCH {{p}}cx_heli_invalid INTO DATA(lo_error).
CASE lo_error->mv_reason.
WHEN {{p}}cx_heli_invalid=>co_reason-passengers.
RAISE invalid_passengers.
WHEN OTHERS.
RAISE invalid_minutes.
ENDCASE.
ENDTRY.
IF ev_skip = abap_true.
cv_fee = lv_fee.
ENDIF.
ENDFUNCTION.

View File

@@ -0,0 +1,113 @@
CLASS {{p}}heli_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS calculate
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
ev_fee TYPE decfloat34
RAISING
{{p}}cx_heli_invalid.
PRIVATE SECTION.
CONSTANTS:
c_rate_scenic TYPE decfloat34 VALUE '8',
c_rate_training TYPE decfloat34 VALUE '12',
c_pax_surcharge TYPE decfloat34 VALUE '15',
c_member_rate TYPE decfloat34 VALUE '0.875',
c_min_fee TYPE decfloat34 VALUE '50',
c_max_fee TYPE decfloat34 VALUE '1500',
c_max_pax TYPE i VALUE 6,
c_min_minutes TYPE i VALUE 5.
METHODS check_input
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
RAISING
{{p}}cx_heli_invalid.
METHODS scenic_fee
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS round_fee
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS apply_limits
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}heli_pricer IMPLEMENTATION.
METHOD calculate.
check_input( iv_passengers = iv_passengers iv_minutes = iv_minutes ).
ev_skip = abap_false.
CASE iv_tour_type.
WHEN 'SC'.
ev_fee = apply_limits( round_fee( scenic_fee( iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member ) ) ).
WHEN 'TR'.
ev_fee = apply_limits( round_fee( CONV decfloat34( iv_minutes ) * c_rate_training ) ).
WHEN 'CH'.
ev_skip = abap_true.
WHEN OTHERS.
ev_fee = 0.
ENDCASE.
ENDMETHOD.
METHOD check_input.
IF iv_passengers < 1 OR iv_passengers > c_max_pax.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-passengers.
ENDIF.
IF iv_minutes < c_min_minutes.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-minutes.
ENDIF.
ENDMETHOD.
METHOD scenic_fee.
rv_fee = CONV decfloat34( iv_minutes ) * c_rate_scenic
+ CONV decfloat34( iv_passengers ) * c_pax_surcharge.
IF iv_member <> abap_true.
rv_fee = rv_fee * c_member_rate.
ENDIF.
ENDMETHOD.
METHOD round_fee.
rv_fee = round( val = iv_fee dec = 2 mode = cl_abap_math=>round_half_up ).
ENDMETHOD.
METHOD apply_limits.
rv_fee = iv_fee.
IF rv_fee < c_min_fee.
rv_fee = c_min_fee.
ELSEIF rv_fee > c_max_fee.
rv_fee = c_max_fee.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

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

View File

@@ -0,0 +1,128 @@
CLASS {{p}}t14_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS call
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool DEFAULT abap_false
iv_fee TYPE decfloat34 DEFAULT 7
EXPORTING
ev_skip TYPE abap_bool
ev_fee TYPE decfloat34
ev_subrc TYPE sysubrc.
METHODS scenic_fee FOR TESTING.
METHODS member_discount FOR TESTING.
METHODS scenic_minimum FOR TESTING.
METHODS scenic_maximum FOR TESTING.
METHODS training_fee FOR TESTING.
METHODS training_ignores_member FOR TESTING.
METHODS charter_skips FOR TESTING.
METHODS other_type_zero FOR TESTING.
METHODS rejects_zero_passengers FOR TESTING.
METHODS rejects_too_many_passengers FOR TESTING.
METHODS rejects_short_flight FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_hidden IMPLEMENTATION.
METHOD call.
ev_fee = iv_fee.
CALL FUNCTION '{{P}}HELI_FEE'
EXPORTING
iv_tour_type = iv_tour_type
iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member
IMPORTING
ev_skip = ev_skip
CHANGING
cv_fee = ev_fee
EXCEPTIONS
invalid_passengers = 1
invalid_minutes = 2
OTHERS = 3.
ev_subrc = sy-subrc.
ENDMETHOD.
METHOD scenic_fee.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 2 iv_minutes = 10
IMPORTING ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) 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( 110 ) act = lv_fee ).
cl_abap_unit_assert=>assert_false( lv_skip ).
ENDMETHOD.
METHOD member_discount.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 3 iv_minutes = 7 iv_member = abap_true
IMPORTING ev_fee = DATA(lv_fee) 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( '88.38' ) act = lv_fee ).
ENDMETHOD.
METHOD scenic_minimum.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 1 iv_minutes = 5 iv_member = abap_true
IMPORTING ev_fee = DATA(lv_fee) 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( 50 ) act = lv_fee ).
ENDMETHOD.
METHOD scenic_maximum.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 6 iv_minutes = 200
IMPORTING ev_fee = DATA(lv_fee) 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( 1500 ) act = lv_fee ).
ENDMETHOD.
METHOD training_fee.
call( EXPORTING iv_tour_type = `TR` iv_passengers = 2 iv_minutes = 10
IMPORTING ev_fee = DATA(lv_fee) 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( 120 ) act = lv_fee ).
ENDMETHOD.
METHOD training_ignores_member.
call( EXPORTING iv_tour_type = `TR` iv_passengers = 2 iv_minutes = 10 iv_member = abap_true
IMPORTING ev_fee = DATA(lv_fee) 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( 120 ) act = lv_fee ).
ENDMETHOD.
METHOD charter_skips.
call( EXPORTING iv_tour_type = `CH` iv_passengers = 2 iv_minutes = 10 iv_fee = 7
IMPORTING ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_true( lv_skip ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 7 ) act = lv_fee ).
ENDMETHOD.
METHOD other_type_zero.
call( EXPORTING iv_tour_type = `XX` iv_passengers = 2 iv_minutes = 10
IMPORTING ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) 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_fee ).
cl_abap_unit_assert=>assert_false( lv_skip ).
ENDMETHOD.
METHOD rejects_zero_passengers.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 0 iv_minutes = 10
IMPORTING ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
ENDMETHOD.
METHOD rejects_too_many_passengers.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 7 iv_minutes = 10
IMPORTING ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
ENDMETHOD.
METHOD rejects_short_flight.
call( EXPORTING iv_tour_type = `SC` iv_passengers = 2 iv_minutes = 4
IMPORTING ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_rc ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,73 @@
{
"task": "G1095",
"mutants": [
{
"object": "{{P}}HELI_PRICER",
"mutant": "line 72: * -> / (arith)",
"status": "killed",
"hidden": "9/11",
"failed_tests": [
"TRAINING_FEE",
"TRAINING_IGNORES_MEMBER"
]
},
{
"object": "{{P}}HELI_FEE",
"mutant": "line 39: = -> <> (eq)",
"status": "killed",
"hidden": "3/11",
"failed_tests": [
"CHARTER_SKIPS",
"MEMBER_DISCOUNT",
"OTHER_TYPE_ZERO",
"SCENIC_FEE",
"SCENIC_MAXIMUM",
"SCENIC_MINIMUM",
"TRAINING_FEE",
"TRAINING_IGNORES_MEMBER"
]
},
{
"object": "{{P}}HELI_PRICER",
"mutant": "line 81: OR -> AND (logic)",
"status": "killed",
"hidden": "9/11",
"failed_tests": [
"REJECTS_TOO_MANY_PASSENGERS",
"REJECTS_ZERO_PASSENGERS"
]
},
{
"object": "{{P}}HELI_FEE",
"mutant": "line 39: abap_false -> abap_true (bool)",
"status": "killed",
"hidden": "3/11",
"failed_tests": [
"CHARTER_SKIPS",
"MEMBER_DISCOUNT",
"OTHER_TYPE_ZERO",
"SCENIC_FEE",
"SCENIC_MAXIMUM",
"SCENIC_MINIMUM",
"TRAINING_FEE",
"TRAINING_IGNORES_MEMBER"
]
},
{
"object": "{{P}}HELI_PRICER",
"mutant": "line 96: = -> <> (eq)",
"status": "killed",
"hidden": "7/11",
"failed_tests": [
"MEMBER_DISCOUNT",
"SCENIC_FEE",
"SCENIC_MAXIMUM",
"SCENIC_MINIMUM"
]
}
],
"valid": 5,
"killed": 5,
"kill_rate": 1.0,
"ok": true
}

View File

@@ -0,0 +1,27 @@
CLASS {{p}}cx_heli_invalid DEFINITION
PUBLIC
INHERITING FROM cx_static_check
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
CONSTANTS:
BEGIN OF co_reason,
passengers TYPE string VALUE 'PASSENGERS',
minutes TYPE string VALUE 'MINUTES',
END OF co_reason.
DATA mv_reason TYPE string READ-ONLY.
METHODS constructor
IMPORTING
iv_reason TYPE string.
ENDCLASS.
CLASS {{p}}cx_heli_invalid IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
mv_reason = iv_reason.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,43 @@
FUNCTION {{p}}heli_fee
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
CHANGING
cv_fee TYPE decfloat34
EXCEPTIONS
invalid_passengers
invalid_minutes.
DATA lo_pricer TYPE REF TO {{p}}heli_pricer.
DATA lv_fee TYPE decfloat34.
lo_pricer = NEW #( ).
TRY.
lo_pricer->calculate(
EXPORTING
iv_tour_type = iv_tour_type
iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member
IMPORTING
ev_skip = ev_skip
ev_fee = lv_fee ).
CATCH {{p}}cx_heli_invalid INTO DATA(lo_error).
CASE lo_error->mv_reason.
WHEN {{p}}cx_heli_invalid=>co_reason-passengers.
RAISE invalid_passengers.
WHEN OTHERS.
RAISE invalid_minutes.
ENDCASE.
ENDTRY.
IF ev_skip = abap_false.
cv_fee = lv_fee.
ENDIF.
ENDFUNCTION.

View File

@@ -0,0 +1,113 @@
CLASS {{p}}heli_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS calculate
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
ev_fee TYPE decfloat34
RAISING
{{p}}cx_heli_invalid.
PRIVATE SECTION.
CONSTANTS:
c_rate_scenic TYPE decfloat34 VALUE '8',
c_rate_training TYPE decfloat34 VALUE '12',
c_pax_surcharge TYPE decfloat34 VALUE '15',
c_member_rate TYPE decfloat34 VALUE '0.875',
c_min_fee TYPE decfloat34 VALUE '50',
c_max_fee TYPE decfloat34 VALUE '1500',
c_max_pax TYPE i VALUE 6,
c_min_minutes TYPE i VALUE 5.
METHODS check_input
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
RAISING
{{p}}cx_heli_invalid.
METHODS scenic_fee
IMPORTING
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS round_fee
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
METHODS apply_limits
IMPORTING
iv_fee TYPE decfloat34
RETURNING
VALUE(rv_fee) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}heli_pricer IMPLEMENTATION.
METHOD calculate.
check_input( iv_passengers = iv_passengers iv_minutes = iv_minutes ).
ev_skip = abap_false.
CASE iv_tour_type.
WHEN 'SC'.
ev_fee = apply_limits( round_fee( scenic_fee( iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member ) ) ).
WHEN 'TR'.
ev_fee = apply_limits( round_fee( CONV decfloat34( iv_minutes ) * c_rate_training ) ).
WHEN 'CH'.
ev_skip = abap_true.
WHEN OTHERS.
ev_fee = 0.
ENDCASE.
ENDMETHOD.
METHOD check_input.
IF iv_passengers < 1 OR iv_passengers > c_max_pax.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-passengers.
ENDIF.
IF iv_minutes < c_min_minutes.
RAISE EXCEPTION TYPE {{p}}cx_heli_invalid
EXPORTING
iv_reason = {{p}}cx_heli_invalid=>co_reason-minutes.
ENDIF.
ENDMETHOD.
METHOD scenic_fee.
rv_fee = CONV decfloat34( iv_minutes ) * c_rate_scenic
+ CONV decfloat34( iv_passengers ) * c_pax_surcharge.
IF iv_member = abap_true.
rv_fee = rv_fee * c_member_rate.
ENDIF.
ENDMETHOD.
METHOD round_fee.
rv_fee = round( val = iv_fee dec = 2 mode = cl_abap_math=>round_half_up ).
ENDMETHOD.
METHOD apply_limits.
rv_fee = iv_fee.
IF rv_fee < c_min_fee.
rv_fee = c_min_fee.
ELSEIF rv_fee > c_max_fee.
rv_fee = c_max_fee.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,97 @@
CLASS ltc_pricer DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}heli_pricer.
METHODS setup.
METHODS scenic_fee FOR TESTING.
METHODS member_discount FOR TESTING.
METHODS training_fee FOR TESTING.
METHODS charter_skips FOR TESTING.
METHODS rejects_zero_passengers FOR TESTING.
ENDCLASS.
CLASS ltc_pricer IMPLEMENTATION.
METHOD setup.
mo_cut = NEW #( ).
ENDMETHOD.
METHOD scenic_fee.
DATA lv_fee TYPE decfloat34.
DATA lv_skip TYPE abap_bool.
mo_cut->calculate(
EXPORTING
iv_tour_type = `SC`
iv_passengers = 2
iv_minutes = 10
iv_member = abap_false
IMPORTING
ev_skip = lv_skip
ev_fee = lv_fee ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 110 ) act = lv_fee ).
cl_abap_unit_assert=>assert_false( lv_skip ).
ENDMETHOD.
METHOD member_discount.
DATA lv_fee TYPE decfloat34.
mo_cut->calculate(
EXPORTING
iv_tour_type = `SC`
iv_passengers = 3
iv_minutes = 7
iv_member = abap_true
IMPORTING
ev_fee = lv_fee ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '88.38' ) act = lv_fee ).
ENDMETHOD.
METHOD training_fee.
DATA lv_fee TYPE decfloat34.
mo_cut->calculate(
EXPORTING
iv_tour_type = `TR`
iv_passengers = 2
iv_minutes = 10
iv_member = abap_false
IMPORTING
ev_fee = lv_fee ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 120 ) act = lv_fee ).
ENDMETHOD.
METHOD charter_skips.
DATA lv_fee TYPE decfloat34.
DATA lv_skip TYPE abap_bool.
mo_cut->calculate(
EXPORTING
iv_tour_type = `CH`
iv_passengers = 2
iv_minutes = 10
iv_member = abap_false
IMPORTING
ev_skip = lv_skip
ev_fee = lv_fee ).
cl_abap_unit_assert=>assert_true( lv_skip ).
ENDMETHOD.
METHOD rejects_zero_passengers.
TRY.
mo_cut->calculate(
EXPORTING
iv_tour_type = `SC`
iv_passengers = 0
iv_minutes = 10
iv_member = abap_false
IMPORTING
ev_fee = DATA(lv_fee) ).
cl_abap_unit_assert=>fail( ).
CATCH {{p}}cx_heli_invalid INTO DATA(lo_error).
cl_abap_unit_assert=>assert_equals(
exp = {{p}}cx_heli_invalid=>co_reason-passengers
act = lo_error->mv_reason ).
ENDTRY.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,85 @@
CLASS {{p}}t14_test DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS call_fee
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool DEFAULT abap_false
iv_fee TYPE decfloat34 DEFAULT 7
EXPORTING
ev_fee TYPE decfloat34
ev_skip TYPE abap_bool
ev_subrc TYPE sysubrc.
METHODS scenic_price FOR TESTING.
METHODS member_price FOR TESTING.
METHODS training_price FOR TESTING.
METHODS charter_price FOR TESTING.
METHODS invalid_input FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_test IMPLEMENTATION.
METHOD call_fee.
ev_fee = iv_fee.
CALL FUNCTION '{{P}}HELI_FEE'
EXPORTING
iv_tour_type = iv_tour_type
iv_passengers = iv_passengers
iv_minutes = iv_minutes
iv_member = iv_member
IMPORTING
ev_skip = ev_skip
CHANGING
cv_fee = ev_fee
EXCEPTIONS
invalid_passengers = 1
invalid_minutes = 2
OTHERS = 3.
ev_subrc = sy-subrc.
ENDMETHOD.
METHOD scenic_price.
call_fee( EXPORTING iv_tour_type = `SC` iv_passengers = 2 iv_minutes = 10
IMPORTING ev_fee = DATA(lv_fee) ev_skip = DATA(lv_skip) 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( 110 ) act = lv_fee ).
cl_abap_unit_assert=>assert_false( lv_skip ).
ENDMETHOD.
METHOD member_price.
call_fee( EXPORTING iv_tour_type = `SC` iv_passengers = 3 iv_minutes = 7 iv_member = abap_true
IMPORTING ev_fee = DATA(lv_fee) 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( '88.38' ) act = lv_fee ).
ENDMETHOD.
METHOD training_price.
call_fee( EXPORTING iv_tour_type = `TR` iv_passengers = 2 iv_minutes = 10
IMPORTING ev_fee = DATA(lv_fee) 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( 120 ) act = lv_fee ).
ENDMETHOD.
METHOD charter_price.
call_fee( EXPORTING iv_tour_type = `CH` iv_passengers = 2 iv_minutes = 10 iv_fee = 7
IMPORTING ev_fee = DATA(lv_fee) ev_skip = DATA(lv_skip) ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rc ).
cl_abap_unit_assert=>assert_true( lv_skip ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 7 ) act = lv_fee ).
ENDMETHOD.
METHOD invalid_input.
call_fee( EXPORTING iv_tour_type = `SC` iv_passengers = 0 iv_minutes = 10
IMPORTING ev_subrc = DATA(lv_rc) ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
call_fee( EXPORTING iv_tour_type = `TR` iv_passengers = 2 iv_minutes = 4
IMPORTING ev_subrc = DATA(lv_rc_minutes) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_rc_minutes ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,17 @@
FUNCTION {{p}}heli_fee
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
CHANGING
cv_fee TYPE decfloat34
EXCEPTIONS
invalid_passengers
invalid_minutes.
" Skeleton: the implementation of this flight module is still missing.
ENDFUNCTION.

View File

@@ -0,0 +1,17 @@
FUNCTION {{p}}heli_sample
IMPORTING
iv_tour_type TYPE string
iv_passengers TYPE i
iv_minutes TYPE i
iv_member TYPE abap_bool
EXPORTING
ev_skip TYPE abap_bool
CHANGING
cv_fee TYPE decfloat34
EXCEPTIONS
invalid_passengers
invalid_minutes.
ev_skip = abap_false.
ENDFUNCTION.

View File

@@ -0,0 +1,53 @@
# 1. Goal
Calculate the price of a sightseeing flight for a helicopter operator. The
booking program calls one function module for each flight that a customer books.
The function module must use the interface of the sample module, because the
booking program calls all flight modules in the same way.
# 2. Open questions
None.
# 3. Context
- Function group {{P}}FG_HELI exists in package $TMP.
- Function module {{P}}HELI_FEE exists in this group. It has the correct
interface, but its implementation is empty.
- Function module {{P}}HELI_SAMPLE exists in this group. It is the sample
module. Its interface is the interface that all flight modules must use.
- A flight has a tour type, a number of passengers, and a flight time in
minutes.
- A customer is a member of the flying club or not.
# 4. Contract
- Implement the function module {{P}}HELI_FEE in function group {{P}}FG_HELI.
- Keep exactly the interface of {{P}}HELI_SAMPLE: the same parameter names,
kinds, types, and exceptions.
# 5. Business rules
1. If the number of passengers is less than 1 or greater than 6, raise the
exception INVALID_PASSENGERS.
2. If the flight time is less than 5 minutes, raise the exception
INVALID_MINUTES.
3. Set the skip flag to false, except in rule 6.
4. Tour type SC (sightseeing circuit):
- The gross price is 8.00 per minute plus 15.00 per passenger.
- If the customer is a member, subtract 12.5 % of the gross price.
- Round the result half up to 2 decimals.
- The minimum price is 50.00. The maximum price is 1500.00.
5. Tour type TR (training flight):
- The gross price is 12.00 per minute. There is no passenger surcharge.
- The member discount does not apply.
- Round the result half up to 2 decimals.
- The minimum price is 50.00. The maximum price is 1500.00.
6. Tour type CH (charter flight): set the skip flag to true. Do not change the
price.
7. All other tour types: the price is 0.
# 6. Constraints
- Release target: SAP_BASIS 816.
- Use Clean ABAP. Keep every method below 40 statements.
- Out of scope: do not change {{P}}HELI_SAMPLE.
# 7. Acceptance
- The function module 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,108 @@
{
"id": "G1095",
"category": "A",
"object_type": "FUNC",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 60,
"max_activations": 15
},
"seed": [
{
"type": "FUGR",
"name": "{{P}}FG_HELI",
"description": "Flight booking modules"
},
{
"type": "FUNC",
"name": "{{P}}HELI_FEE",
"functionGroup": "{{P}}FG_HELI",
"file": "seed/heli_fee.func.abap",
"description": "Skeleton of the flight price module (empty implementation)"
},
{
"type": "FUNC",
"name": "{{P}}HELI_SAMPLE",
"functionGroup": "{{P}}FG_HELI",
"file": "seed/heli_sample.func.abap",
"description": "Sample flight module"
}
],
"contract": [
{
"type": "FUNC",
"name": "{{P}}HELI_FEE",
"functionGroup": "{{P}}FG_HELI",
"params": [
{
"name": "iv_tour_type",
"type": "string"
},
{
"name": "iv_passengers",
"type": "i"
},
{
"name": "iv_minutes",
"type": "i"
},
{
"name": "iv_member",
"type": "abap_bool"
},
{
"name": "ev_skip",
"type": "abap_bool"
},
{
"name": "cv_fee",
"type": "decfloat34"
}
]
}
],
"out_of_scope": [
"{{P}}HELI_SAMPLE"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T14_HIDDEN",
"file": "hidden/t14_hidden.clas.abap",
"description": "T14 hidden tests"
}
],
"reference": [
{
"type": "CLAS",
"name": "{{P}}CX_HELI_INVALID",
"file": "reference/cx_heli_invalid.clas.abap",
"description": "Invalid flight input"
},
{
"type": "CLAS",
"name": "{{P}}HELI_PRICER",
"file": "reference/heli_pricer.clas.abap",
"testclasses_file": "reference/heli_pricer_testclasses.clas.abap",
"description": "Pure flight price logic"
},
{
"type": "FUNC",
"name": "{{P}}HELI_FEE",
"functionGroup": "{{P}}FG_HELI",
"file": "reference/heli_fee.func.abap",
"description": "Flight price module"
},
{
"type": "CLAS",
"name": "{{P}}T14_TEST",
"file": "reference/t14_test.clas.abap",
"description": "T14 own tests"
}
],
"craft_checks": [
"method_length"
]
}