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,92 @@
CLASS {{p}}trans_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor.
METHODS calculate_fee
IMPORTING iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE decfloat34.
PRIVATE SECTION.
CONSTANTS c_rate_std TYPE decfloat34 VALUE '0.12'.
CONSTANTS c_rate_rare TYPE decfloat34 VALUE '0.19'.
CONSTANTS c_min_charge TYPE decfloat34 VALUE '35.00'.
CONSTANTS c_certified_fee TYPE decfloat34 VALUE '22.00'.
CONSTANTS c_express_percent TYPE decfloat34 VALUE '150'.
CONSTANTS c_tier_one_words TYPE i VALUE 1000.
CONSTANTS c_tier_two_words TYPE i VALUE 5000.
CONSTANTS c_tier_one_percent TYPE decfloat34 VALUE '10'.
CONSTANTS c_tier_two_percent TYPE decfloat34 VALUE '15'.
METHODS rate
IMPORTING iv_lang_pair TYPE string
RETURNING VALUE(rv_rate) TYPE decfloat34.
METHODS translation_charge
IMPORTING iv_word_count TYPE i
iv_rate TYPE decfloat34
RETURNING VALUE(rv_charge) TYPE decfloat34.
METHODS discount
IMPORTING iv_word_count TYPE i
iv_charge TYPE decfloat34
RETURNING VALUE(rv_discount) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}trans_pricer IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD calculate_fee.
DATA(lv_amount) = translation_charge(
iv_word_count = iv_word_count
iv_rate = rate( iv_lang_pair ) ).
lv_amount = lv_amount - discount( iv_word_count = iv_word_count
iv_charge = lv_amount ).
IF iv_certified <> abap_true.
lv_amount = lv_amount + c_certified_fee.
ENDIF.
IF iv_express = abap_true.
lv_amount = round( val = lv_amount * c_express_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
rv_fee = lv_amount.
ENDMETHOD.
METHOD rate.
CASE iv_lang_pair.
WHEN 'STD'.
rv_rate = c_rate_std.
WHEN 'RARE'.
rv_rate = c_rate_rare.
WHEN OTHERS.
rv_rate = 0.
ENDCASE.
ENDMETHOD.
METHOD translation_charge.
rv_charge = round( val = iv_word_count * iv_rate
dec = 2
mode = cl_abap_math=>round_half_up ).
IF rv_charge < c_min_charge.
rv_charge = c_min_charge.
ENDIF.
ENDMETHOD.
METHOD discount.
IF iv_word_count >= c_tier_two_words.
rv_discount = round( val = iv_charge * c_tier_two_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ELSEIF iv_word_count >= c_tier_one_words.
rv_discount = round( val = iv_charge * c_tier_one_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,28 @@
FUNCTION {{p}}trans_fee
IMPORTING
iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
EXPORTING
ev_fee TYPE decfloat34
EXCEPTIONS
invalid_lang_pair
invalid_word_count.
IF iv_lang_pair = 'STD' AND iv_lang_pair <> 'RARE'.
RAISE invalid_lang_pair.
ENDIF.
IF iv_word_count < 1.
RAISE invalid_word_count.
ENDIF.
DATA(lo_pricer) = NEW {{p}}trans_pricer( ).
ev_fee = lo_pricer->calculate_fee(
iv_lang_pair = iv_lang_pair
iv_word_count = iv_word_count
iv_express = iv_express
iv_certified = iv_certified ).
ENDFUNCTION.

View File

@@ -0,0 +1,92 @@
CLASS {{p}}trans_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor.
METHODS calculate_fee
IMPORTING iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE decfloat34.
PRIVATE SECTION.
CONSTANTS c_rate_std TYPE decfloat34 VALUE '0.12'.
CONSTANTS c_rate_rare TYPE decfloat34 VALUE '0.19'.
CONSTANTS c_min_charge TYPE decfloat34 VALUE '35.00'.
CONSTANTS c_certified_fee TYPE decfloat34 VALUE '22.00'.
CONSTANTS c_express_percent TYPE decfloat34 VALUE '150'.
CONSTANTS c_tier_one_words TYPE i VALUE 1000.
CONSTANTS c_tier_two_words TYPE i VALUE 5000.
CONSTANTS c_tier_one_percent TYPE decfloat34 VALUE '10'.
CONSTANTS c_tier_two_percent TYPE decfloat34 VALUE '15'.
METHODS rate
IMPORTING iv_lang_pair TYPE string
RETURNING VALUE(rv_rate) TYPE decfloat34.
METHODS translation_charge
IMPORTING iv_word_count TYPE i
iv_rate TYPE decfloat34
RETURNING VALUE(rv_charge) TYPE decfloat34.
METHODS discount
IMPORTING iv_word_count TYPE i
iv_charge TYPE decfloat34
RETURNING VALUE(rv_discount) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}trans_pricer IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD calculate_fee.
DATA(lv_amount) = translation_charge(
iv_word_count = iv_word_count
iv_rate = rate( iv_lang_pair ) ).
lv_amount = lv_amount - discount( iv_word_count = iv_word_count
iv_charge = lv_amount ).
IF iv_certified = abap_true.
lv_amount = lv_amount + c_certified_fee.
ENDIF.
IF iv_express = abap_false.
lv_amount = round( val = lv_amount * c_express_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
rv_fee = lv_amount.
ENDMETHOD.
METHOD rate.
CASE iv_lang_pair.
WHEN 'STD'.
rv_rate = c_rate_std.
WHEN 'RARE'.
rv_rate = c_rate_rare.
WHEN OTHERS.
rv_rate = 0.
ENDCASE.
ENDMETHOD.
METHOD translation_charge.
rv_charge = round( val = iv_word_count * iv_rate
dec = 2
mode = cl_abap_math=>round_half_up ).
IF rv_charge < c_min_charge.
rv_charge = c_min_charge.
ENDIF.
ENDMETHOD.
METHOD discount.
IF iv_word_count >= c_tier_two_words.
rv_discount = round( val = iv_charge * c_tier_two_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ELSEIF iv_word_count >= c_tier_one_words.
rv_discount = round( val = iv_charge * c_tier_one_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,28 @@
FUNCTION {{p}}trans_fee
IMPORTING
iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
EXPORTING
ev_fee TYPE decfloat34
EXCEPTIONS
invalid_lang_pair
invalid_word_count.
IF iv_lang_pair <> 'STD' OR iv_lang_pair <> 'RARE'.
RAISE invalid_lang_pair.
ENDIF.
IF iv_word_count < 1.
RAISE invalid_word_count.
ENDIF.
DATA(lo_pricer) = NEW {{p}}trans_pricer( ).
ev_fee = lo_pricer->calculate_fee(
iv_lang_pair = iv_lang_pair
iv_word_count = iv_word_count
iv_express = iv_express
iv_certified = iv_certified ).
ENDFUNCTION.

View File

@@ -0,0 +1,92 @@
CLASS {{p}}trans_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor.
METHODS calculate_fee
IMPORTING iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE decfloat34.
PRIVATE SECTION.
CONSTANTS c_rate_std TYPE decfloat34 VALUE '0.12'.
CONSTANTS c_rate_rare TYPE decfloat34 VALUE '0.19'.
CONSTANTS c_min_charge TYPE decfloat34 VALUE '35.00'.
CONSTANTS c_certified_fee TYPE decfloat34 VALUE '22.00'.
CONSTANTS c_express_percent TYPE decfloat34 VALUE '150'.
CONSTANTS c_tier_one_words TYPE i VALUE 1000.
CONSTANTS c_tier_two_words TYPE i VALUE 5000.
CONSTANTS c_tier_one_percent TYPE decfloat34 VALUE '10'.
CONSTANTS c_tier_two_percent TYPE decfloat34 VALUE '15'.
METHODS rate
IMPORTING iv_lang_pair TYPE string
RETURNING VALUE(rv_rate) TYPE decfloat34.
METHODS translation_charge
IMPORTING iv_word_count TYPE i
iv_rate TYPE decfloat34
RETURNING VALUE(rv_charge) TYPE decfloat34.
METHODS discount
IMPORTING iv_word_count TYPE i
iv_charge TYPE decfloat34
RETURNING VALUE(rv_discount) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}trans_pricer IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD calculate_fee.
DATA(lv_amount) = translation_charge(
iv_word_count = iv_word_count
iv_rate = rate( iv_lang_pair ) ).
lv_amount = lv_amount - discount( iv_word_count = iv_word_count
iv_charge = lv_amount ).
IF iv_certified = abap_true.
lv_amount = lv_amount + c_certified_fee.
ENDIF.
IF iv_express = abap_true.
lv_amount = round( val = lv_amount * c_express_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
rv_fee = lv_amount.
ENDMETHOD.
METHOD rate.
CASE iv_lang_pair.
WHEN 'STD'.
rv_rate = c_rate_std.
WHEN 'RARE'.
rv_rate = c_rate_rare.
WHEN OTHERS.
rv_rate = 0.
ENDCASE.
ENDMETHOD.
METHOD translation_charge.
rv_charge = round( val = iv_word_count * iv_rate
dec = 2
mode = cl_abap_math=>round_half_up ).
IF rv_charge < c_min_charge.
rv_charge = c_min_charge.
ENDIF.
ENDMETHOD.
METHOD discount.
IF iv_word_count >= c_tier_two_words.
rv_discount = round( val = iv_charge / c_tier_two_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ELSEIF iv_word_count >= c_tier_one_words.
rv_discount = round( val = iv_charge * c_tier_one_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,28 @@
{
"id": "G1115",
"pool": "train",
"object_type": "FUNC",
"category": "A",
"attempts": [
{
"stage": "bundle",
"errors": [
"Too close to task G0151 (similarity spec 0.60, rules 0.48, names 1.00). Choose a different business topic and different object names."
],
"by_check": {
"extra": 1
}
},
{
"stage": "validate",
"oracle": 100.0,
"null": 0,
"mutation": {
"valid": 5,
"killed": 5,
"ok": true
}
}
],
"accepted": true
}

View File

@@ -0,0 +1,140 @@
CLASS {{p}}t14_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS call_fee
IMPORTING iv_pair TYPE string
iv_words TYPE i
iv_express TYPE abap_bool DEFAULT abap_false
iv_cert TYPE abap_bool DEFAULT abap_false
EXPORTING ev_fee TYPE decfloat34
ev_subrc TYPE sysubrc.
METHODS pricer_fee
IMPORTING iv_pair TYPE string
iv_words TYPE i
RETURNING VALUE(rv_fee) TYPE decfloat34.
METHODS minimum_charge FOR TESTING.
METHODS rare_rate FOR TESTING.
METHODS tier_one_discount FOR TESTING.
METHODS tier_two_discount FOR TESTING.
METHODS no_discount_below_tier FOR TESTING.
METHODS certified_fee FOR TESTING.
METHODS express_multiplier FOR TESTING.
METHODS discount_rounding FOR TESTING.
METHODS express_rounding FOR TESTING.
METHODS invalid_pair_first FOR TESTING.
METHODS invalid_word_count FOR TESTING.
METHODS pricer_class_fee FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_hidden IMPLEMENTATION.
METHOD call_fee.
ev_fee = 0.
CALL FUNCTION '{{P}}TRANS_FEE'
EXPORTING
iv_lang_pair = iv_pair
iv_word_count = iv_words
iv_express = iv_express
iv_certified = iv_cert
IMPORTING
ev_fee = ev_fee
EXCEPTIONS
invalid_lang_pair = 1
invalid_word_count = 2
OTHERS = 3.
ev_subrc = sy-subrc.
ENDMETHOD.
METHOD pricer_fee.
DATA(lo_pricer) = NEW {{p}}trans_pricer( ).
rv_fee = lo_pricer->calculate_fee(
iv_lang_pair = iv_pair
iv_word_count = iv_words
iv_express = abap_false
iv_certified = abap_false ).
ENDMETHOD.
METHOD minimum_charge.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 100
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '35.00' ) act = lv_fee ).
ENDMETHOD.
METHOD rare_rate.
call_fee( EXPORTING iv_pair = 'RARE' iv_words = 200
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '38.00' ) act = lv_fee ).
ENDMETHOD.
METHOD tier_one_discount.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 1000
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '108.00' ) act = lv_fee ).
ENDMETHOD.
METHOD tier_two_discount.
call_fee( EXPORTING iv_pair = 'RARE' iv_words = 5000
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '807.50' ) act = lv_fee ).
ENDMETHOD.
METHOD no_discount_below_tier.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 999
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '119.88' ) act = lv_fee ).
ENDMETHOD.
METHOD certified_fee.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 300 iv_cert = abap_true
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '58.00' ) act = lv_fee ).
ENDMETHOD.
METHOD express_multiplier.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 300 iv_cert = abap_true iv_express = abap_true
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '87.00' ) act = lv_fee ).
ENDMETHOD.
METHOD discount_rounding.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 1001
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '108.11' ) act = lv_fee ).
ENDMETHOD.
METHOD express_rounding.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 1001 iv_express = abap_true
IMPORTING ev_fee = DATA(lv_fee) ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '162.17' ) act = lv_fee ).
ENDMETHOD.
METHOD invalid_pair_first.
call_fee( EXPORTING iv_pair = 'XX' iv_words = 0
IMPORTING ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_subrc ).
ENDMETHOD.
METHOD invalid_word_count.
call_fee( EXPORTING iv_pair = 'STD' iv_words = 0
IMPORTING ev_subrc = DATA(lv_subrc) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_subrc ).
ENDMETHOD.
METHOD pricer_class_fee.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '807.50' )
act = pricer_fee( iv_pair = 'RARE' iv_words = 5000 ) ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,90 @@
{
"task": "G1115",
"mutants": [
{
"object": "{{P}}TRANS_PRICER",
"mutant": "line 50: = -> <> (eq)",
"status": "killed",
"hidden": "2/12",
"failed_tests": [
"CERTIFIED_FEE",
"DISCOUNT_ROUNDING",
"EXPRESS_MULTIPLIER",
"EXPRESS_ROUNDING",
"MINIMUM_CHARGE",
"NO_DISCOUNT_BELOW_TIER",
"PRICER_CLASS_FEE",
"RARE_RATE",
"TIER_ONE_DISCOUNT",
"TIER_TWO_DISCOUNT"
]
},
{
"object": "{{P}}TRANS_FEE",
"mutant": "line 13: <> -> = (rel)",
"status": "killed",
"hidden": "3/12",
"failed_tests": [
"CERTIFIED_FEE",
"DISCOUNT_ROUNDING",
"EXPRESS_MULTIPLIER",
"EXPRESS_ROUNDING",
"INVALID_PAIR_FIRST",
"INVALID_WORD_COUNT",
"MINIMUM_CHARGE",
"NO_DISCOUNT_BELOW_TIER",
"TIER_ONE_DISCOUNT"
]
},
{
"object": "{{P}}TRANS_PRICER",
"mutant": "line 53: abap_true -> abap_false (bool)",
"status": "killed",
"hidden": "2/12",
"failed_tests": [
"CERTIFIED_FEE",
"DISCOUNT_ROUNDING",
"EXPRESS_MULTIPLIER",
"EXPRESS_ROUNDING",
"MINIMUM_CHARGE",
"NO_DISCOUNT_BELOW_TIER",
"PRICER_CLASS_FEE",
"RARE_RATE",
"TIER_ONE_DISCOUNT",
"TIER_TWO_DISCOUNT"
]
},
{
"object": "{{P}}TRANS_FEE",
"mutant": "line 13: AND -> OR (logic)",
"status": "killed",
"hidden": "2/12",
"failed_tests": [
"CERTIFIED_FEE",
"DISCOUNT_ROUNDING",
"EXPRESS_MULTIPLIER",
"EXPRESS_ROUNDING",
"INVALID_WORD_COUNT",
"MINIMUM_CHARGE",
"NO_DISCOUNT_BELOW_TIER",
"RARE_RATE",
"TIER_ONE_DISCOUNT",
"TIER_TWO_DISCOUNT"
]
},
{
"object": "{{P}}TRANS_PRICER",
"mutant": "line 83: * -> / (arith)",
"status": "killed",
"hidden": "10/12",
"failed_tests": [
"PRICER_CLASS_FEE",
"TIER_TWO_DISCOUNT"
]
}
],
"valid": 5,
"killed": 5,
"kill_rate": 1.0,
"ok": true
}

View File

@@ -0,0 +1,73 @@
CLASS {{p}}t14_test DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS fee_for
IMPORTING iv_pair TYPE string
iv_words TYPE i
iv_express TYPE abap_bool
iv_cert TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE decfloat34.
METHODS minimum_charge FOR TESTING.
METHODS tier_discount FOR TESTING.
METHODS express_surcharge FOR TESTING.
METHODS invalid_input FOR TESTING.
ENDCLASS.
CLASS {{p}}t14_test IMPLEMENTATION.
METHOD fee_for.
CALL FUNCTION '{{P}}TRANS_FEE'
EXPORTING
iv_lang_pair = iv_pair
iv_word_count = iv_words
iv_express = iv_express
iv_certified = iv_cert
IMPORTING
ev_fee = rv_fee
EXCEPTIONS
invalid_lang_pair = 1
invalid_word_count = 2
OTHERS = 3.
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
ENDMETHOD.
METHOD minimum_charge.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '35.00' )
act = fee_for( iv_pair = 'STD' iv_words = 100
iv_express = abap_false iv_cert = abap_false ) ).
ENDMETHOD.
METHOD tier_discount.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '108.00' )
act = fee_for( iv_pair = 'STD' iv_words = 1000
iv_express = abap_false iv_cert = abap_false ) ).
ENDMETHOD.
METHOD express_surcharge.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '87.00' )
act = fee_for( iv_pair = 'STD' iv_words = 300
iv_express = abap_true iv_cert = abap_true ) ).
ENDMETHOD.
METHOD invalid_input.
DATA lv_fee TYPE decfloat34.
CALL FUNCTION '{{P}}TRANS_FEE'
EXPORTING
iv_lang_pair = 'STD'
iv_word_count = 0
iv_express = abap_false
iv_certified = abap_false
IMPORTING
ev_fee = lv_fee
EXCEPTIONS
invalid_lang_pair = 1
invalid_word_count = 2
OTHERS = 3.
cl_abap_unit_assert=>assert_equals( exp = 2 act = sy-subrc ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,28 @@
FUNCTION {{p}}trans_fee
IMPORTING
iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
EXPORTING
ev_fee TYPE decfloat34
EXCEPTIONS
invalid_lang_pair
invalid_word_count.
IF iv_lang_pair <> 'STD' AND iv_lang_pair <> 'RARE'.
RAISE invalid_lang_pair.
ENDIF.
IF iv_word_count < 1.
RAISE invalid_word_count.
ENDIF.
DATA(lo_pricer) = NEW {{p}}trans_pricer( ).
ev_fee = lo_pricer->calculate_fee(
iv_lang_pair = iv_lang_pair
iv_word_count = iv_word_count
iv_express = iv_express
iv_certified = iv_certified ).
ENDFUNCTION.

View File

@@ -0,0 +1,92 @@
CLASS {{p}}trans_pricer DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor.
METHODS calculate_fee
IMPORTING iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE decfloat34.
PRIVATE SECTION.
CONSTANTS c_rate_std TYPE decfloat34 VALUE '0.12'.
CONSTANTS c_rate_rare TYPE decfloat34 VALUE '0.19'.
CONSTANTS c_min_charge TYPE decfloat34 VALUE '35.00'.
CONSTANTS c_certified_fee TYPE decfloat34 VALUE '22.00'.
CONSTANTS c_express_percent TYPE decfloat34 VALUE '150'.
CONSTANTS c_tier_one_words TYPE i VALUE 1000.
CONSTANTS c_tier_two_words TYPE i VALUE 5000.
CONSTANTS c_tier_one_percent TYPE decfloat34 VALUE '10'.
CONSTANTS c_tier_two_percent TYPE decfloat34 VALUE '15'.
METHODS rate
IMPORTING iv_lang_pair TYPE string
RETURNING VALUE(rv_rate) TYPE decfloat34.
METHODS translation_charge
IMPORTING iv_word_count TYPE i
iv_rate TYPE decfloat34
RETURNING VALUE(rv_charge) TYPE decfloat34.
METHODS discount
IMPORTING iv_word_count TYPE i
iv_charge TYPE decfloat34
RETURNING VALUE(rv_discount) TYPE decfloat34.
ENDCLASS.
CLASS {{p}}trans_pricer IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD calculate_fee.
DATA(lv_amount) = translation_charge(
iv_word_count = iv_word_count
iv_rate = rate( iv_lang_pair ) ).
lv_amount = lv_amount - discount( iv_word_count = iv_word_count
iv_charge = lv_amount ).
IF iv_certified = abap_true.
lv_amount = lv_amount + c_certified_fee.
ENDIF.
IF iv_express = abap_true.
lv_amount = round( val = lv_amount * c_express_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
rv_fee = lv_amount.
ENDMETHOD.
METHOD rate.
CASE iv_lang_pair.
WHEN 'STD'.
rv_rate = c_rate_std.
WHEN 'RARE'.
rv_rate = c_rate_rare.
WHEN OTHERS.
rv_rate = 0.
ENDCASE.
ENDMETHOD.
METHOD translation_charge.
rv_charge = round( val = iv_word_count * iv_rate
dec = 2
mode = cl_abap_math=>round_half_up ).
IF rv_charge < c_min_charge.
rv_charge = c_min_charge.
ENDIF.
ENDMETHOD.
METHOD discount.
IF iv_word_count >= c_tier_two_words.
rv_discount = round( val = iv_charge * c_tier_two_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ELSEIF iv_word_count >= c_tier_one_words.
rv_discount = round( val = iv_charge * c_tier_one_percent / 100
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,40 @@
CLASS ltc_pricer DEFINITION FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}trans_pricer.
METHODS setup.
METHODS minimum_charge FOR TESTING.
METHODS tier_discount FOR TESTING.
METHODS certified_and_express FOR TESTING.
ENDCLASS.
CLASS ltc_pricer IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}trans_pricer( ).
ENDMETHOD.
METHOD minimum_charge.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '35.00' )
act = mo_cut->calculate_fee( iv_lang_pair = 'STD' iv_word_count = 100
iv_express = abap_false iv_certified = abap_false ) ).
ENDMETHOD.
METHOD tier_discount.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '807.50' )
act = mo_cut->calculate_fee( iv_lang_pair = 'RARE' iv_word_count = 5000
iv_express = abap_false iv_certified = abap_false ) ).
ENDMETHOD.
METHOD certified_and_express.
cl_abap_unit_assert=>assert_equals(
exp = CONV decfloat34( '87.00' )
act = mo_cut->calculate_fee( iv_lang_pair = 'STD' iv_word_count = 300
iv_express = abap_true iv_certified = abap_true ) ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,15 @@
FUNCTION {{p}}trans_sample
IMPORTING
iv_lang_pair TYPE string
iv_word_count TYPE i
iv_express TYPE abap_bool
iv_certified TYPE abap_bool
EXPORTING
ev_fee TYPE decfloat34
EXCEPTIONS
invalid_lang_pair
invalid_word_count.
ev_fee = 0.
ENDFUNCTION.

View File

@@ -0,0 +1,86 @@
# 1. Goal
A translation agency prices translation jobs. The order desk calls one function
module for each job. The function module must have the same interface as the
sample module {{P}}TRANS_SAMPLE, because the order desk calls all pricing modules
of the agency in the same way. Other programs of the agency also need the price.
Therefore the calculation is available in a separate class.
# 2. Open questions
None.
# 3. Context
- Function group {{P}}FG_TRANS exists in package $TMP.
- Function module {{P}}TRANS_SAMPLE exists in this group. It is the sample
pricing module. Its interface is the interface that all pricing modules of the
agency use.
# 4. Contract
## 4.1 Function module {{P}}TRANS_FEE
- Function group: {{P}}FG_TRANS.
- Interface: exactly the interface of {{P}}TRANS_SAMPLE.
- Importing parameters:
- iv_lang_pair TYPE string
- iv_word_count TYPE i
- iv_express TYPE abap_bool
- iv_certified TYPE abap_bool
- Exporting parameter: ev_fee TYPE decfloat34
- Exceptions: invalid_lang_pair, invalid_word_count
## 4.2 Class {{P}}TRANS_PRICER
- Package $TMP.
- Public and final.
- Public constructor without parameters.
- Public instance method calculate_fee:
- Importing parameters:
- iv_lang_pair TYPE string
- iv_word_count TYPE i
- iv_express TYPE abap_bool
- iv_certified TYPE abap_bool
- Returning parameter: rv_fee TYPE decfloat34
- The method has no exceptions. It expects valid input.
# 5. Business rules
1. The language pair is STD or RARE. Any other value is invalid.
2. The word count is 1 or more. A word count of 0 or a negative word count is
invalid.
3. The function module {{P}}TRANS_FEE checks the language pair first and the
word count second. It raises the exception INVALID_LANG_PAIR for an invalid
language pair and the exception INVALID_WORD_COUNT for an invalid word count.
4. The price of one word is 0.12 for language pair STD and 0.19 for language
pair RARE.
5. The translation charge is the word count multiplied by the price of one
word. Round the translation charge half up to 2 decimals.
6. The minimum translation charge is 35.00. If the translation charge is less
than 35.00, the translation charge is 35.00.
7. The agency grants a volume discount on the translation charge after rule 6:
- 10 % for 1000 words up to 4999 words,
- 15 % for 5000 words or more.
Round the discount half up to 2 decimals. The discounted charge is the
translation charge minus the discount.
8. A certified translation adds a flat fee of 22.00 to the discounted charge.
9. Express delivery multiplies the amount after rules 7 and 8 by 1.5. Round the
result half up to 2 decimals.
10. Without express delivery, the fee is the amount after rules 7 and 8.
11. The class {{P}}TRANS_PRICER returns the fee in rv_fee. The function module
{{P}}TRANS_FEE returns the fee in ev_fee.
# 6. Constraints
- Release target: 8.16 (SAP_BASIS 816).
- Package $TMP. Do not use a transport.
- Clean ABAP. Keep every method below 40 statements.
- Out of scope: do not change {{P}}TRANS_SAMPLE.
# 7. Acceptance
- All objects are active and have no syntax error.
- The hidden tests pass.
- Write ABAP Unit tests: local test classes for {{P}}TRANS_PRICER and a global
test class for {{P}}TRANS_FEE.

View File

@@ -0,0 +1,95 @@
{
"id": "G1115",
"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_TRANS",
"description": "Translation job pricing function group"
},
{
"type": "FUNC",
"name": "{{P}}TRANS_SAMPLE",
"functionGroup": "{{P}}FG_TRANS",
"file": "seed/trans_sample.func.abap",
"description": "Sample pricing module of the translation agency"
}
],
"contract": [
{
"type": "FUNC",
"name": "{{P}}TRANS_FEE",
"functionGroup": "{{P}}FG_TRANS",
"params": [
{
"name": "iv_lang_pair",
"type": "string"
},
{
"name": "iv_word_count",
"type": "i"
},
{
"name": "iv_express",
"type": "abap_bool"
},
{
"name": "iv_certified",
"type": "abap_bool"
},
{
"name": "ev_fee",
"type": "decfloat34"
}
]
},
{
"type": "CLAS",
"name": "{{P}}TRANS_PRICER"
}
],
"out_of_scope": [
"{{P}}TRANS_SAMPLE"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T14_HIDDEN",
"file": "hidden/t14_hidden.clas.abap",
"description": "T14 hidden tests"
}
],
"reference": [
{
"type": "CLAS",
"name": "{{P}}TRANS_PRICER",
"file": "reference/trans_pricer.clas.abap",
"testclasses_file": "reference/trans_pricer.testclasses.abap",
"description": "Pure translation price calculation"
},
{
"type": "FUNC",
"name": "{{P}}TRANS_FEE",
"functionGroup": "{{P}}FG_TRANS",
"file": "reference/trans_fee.func.abap",
"description": "Translation fee module"
},
{
"type": "CLAS",
"name": "{{P}}T14_TEST",
"file": "reference/t14_test.clas.abap",
"description": "T14 own tests for the function module"
}
],
"craft_checks": [
"method_length"
]
}