Fix coverage with several contract classes; table annotation and file path checks; clean task dir on write
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
This commit is contained in:
51
tasks_gen/eval/G0107/reference/energy_bill.func.abap
Normal file
51
tasks_gen/eval/G0107/reference/energy_bill.func.abap
Normal file
@@ -0,0 +1,51 @@
|
||||
FUNCTION {{p}}energy_bill
|
||||
IMPORTING
|
||||
iv_consumption TYPE decfloat34
|
||||
iv_tariff TYPE string
|
||||
iv_direct_debit TYPE abap_bool
|
||||
EXPORTING
|
||||
ev_bill TYPE decfloat34
|
||||
EXCEPTIONS
|
||||
invalid_consumption
|
||||
invalid_tariff.
|
||||
|
||||
CONSTANTS lc_base_fee TYPE decfloat34 VALUE '12.00'.
|
||||
CONSTANTS lc_tier_limit TYPE decfloat34 VALUE '300'.
|
||||
CONSTANTS lc_tier_factor TYPE decfloat34 VALUE '0.8'.
|
||||
CONSTANTS lc_debit_factor TYPE decfloat34 VALUE '0.98'.
|
||||
|
||||
IF iv_consumption < 0.
|
||||
RAISE invalid_consumption.
|
||||
ENDIF.
|
||||
|
||||
DATA lv_rate TYPE decfloat34.
|
||||
CASE iv_tariff.
|
||||
WHEN 'BASIC'.
|
||||
lv_rate = '0.32'.
|
||||
WHEN 'GREEN'.
|
||||
lv_rate = '0.38'.
|
||||
WHEN 'NIGHT'.
|
||||
lv_rate = '0.24'.
|
||||
WHEN OTHERS.
|
||||
RAISE invalid_tariff.
|
||||
ENDCASE.
|
||||
|
||||
DATA lv_standard_qty TYPE decfloat34.
|
||||
DATA lv_reduced_qty TYPE decfloat34.
|
||||
IF iv_consumption > lc_tier_limit.
|
||||
lv_standard_qty = lc_tier_limit.
|
||||
lv_reduced_qty = iv_consumption - lc_tier_limit.
|
||||
ELSE.
|
||||
lv_standard_qty = iv_consumption.
|
||||
lv_reduced_qty = 0.
|
||||
ENDIF.
|
||||
|
||||
DATA lv_bill TYPE decfloat34.
|
||||
lv_bill = lc_base_fee + lv_standard_qty * lv_rate
|
||||
+ lv_reduced_qty * lv_rate * lc_tier_factor.
|
||||
IF iv_direct_debit = abap_true.
|
||||
lv_bill = lv_bill * lc_debit_factor.
|
||||
ENDIF.
|
||||
|
||||
ev_bill = round( val = lv_bill dec = 2 mode = cl_abap_math=>round_half_up ).
|
||||
ENDFUNCTION.
|
||||
68
tasks_gen/eval/G0107/reference/t21_test.clas.abap
Normal file
68
tasks_gen/eval/G0107/reference/t21_test.clas.abap
Normal file
@@ -0,0 +1,68 @@
|
||||
CLASS {{p}}t21_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
METHODS bill
|
||||
IMPORTING
|
||||
iv_consumption TYPE decfloat34
|
||||
iv_tariff TYPE string
|
||||
iv_direct_debit TYPE abap_bool DEFAULT abap_false
|
||||
EXPORTING
|
||||
ev_bill TYPE decfloat34
|
||||
ev_subrc TYPE sysubrc.
|
||||
METHODS basic_bill FOR TESTING.
|
||||
METHODS tier_bill FOR TESTING.
|
||||
METHODS debit_bill FOR TESTING.
|
||||
METHODS invalid_input FOR TESTING.
|
||||
METHODS unknown_tariff FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}t21_test IMPLEMENTATION.
|
||||
METHOD bill.
|
||||
CALL FUNCTION '{{P}}ENERGY_BILL'
|
||||
EXPORTING
|
||||
iv_consumption = iv_consumption
|
||||
iv_tariff = iv_tariff
|
||||
iv_direct_debit = iv_direct_debit
|
||||
IMPORTING
|
||||
ev_bill = ev_bill
|
||||
EXCEPTIONS
|
||||
invalid_consumption = 1
|
||||
invalid_tariff = 2
|
||||
OTHERS = 3.
|
||||
ev_subrc = sy-subrc.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD basic_bill.
|
||||
bill( EXPORTING iv_consumption = 100 iv_tariff = `BASIC`
|
||||
IMPORTING ev_bill = DATA(lv_bill) 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( '44.00' ) act = lv_bill ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD tier_bill.
|
||||
bill( EXPORTING iv_consumption = 400 iv_tariff = `BASIC`
|
||||
IMPORTING ev_bill = DATA(lv_bill) 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( '133.60' ) act = lv_bill ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD debit_bill.
|
||||
bill( EXPORTING iv_consumption = 400 iv_tariff = `BASIC` iv_direct_debit = abap_true
|
||||
IMPORTING ev_bill = DATA(lv_bill) 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( '130.93' ) act = lv_bill ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD invalid_input.
|
||||
bill( EXPORTING iv_consumption = -1 iv_tariff = `BASIC`
|
||||
IMPORTING ev_subrc = DATA(lv_rc) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD unknown_tariff.
|
||||
bill( EXPORTING iv_consumption = 100 iv_tariff = `ECO`
|
||||
IMPORTING ev_subrc = DATA(lv_rc) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_rc ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user