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:
Kral
2026-10-03 08:44:35 +02:00
parent fb576b0954
commit 03ab36149e
388 changed files with 28620 additions and 339 deletions

View File

@@ -0,0 +1,102 @@
CLASS {{p}}park_fee_calculator DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES {{p}}if_park_fee.
PRIVATE SECTION.
CONSTANTS:
c_price_per_hour TYPE {{p}}if_park_fee=>ty_amount VALUE '2.50',
c_lost_ticket TYPE {{p}}if_park_fee=>ty_amount VALUE '45.00',
c_max_fee TYPE {{p}}if_park_fee=>ty_amount VALUE '60.00',
c_discount_rate TYPE p LENGTH 3 DECIMALS 2 VALUE '0.75',
c_free_minutes TYPE i VALUE 15,
c_max_minutes TYPE i VALUE 43200,
c_seconds_per_day TYPE i VALUE 86400,
c_reference_date TYPE d VALUE '19000101',
c_sunday_offset TYPE i VALUE 6.
METHODS duration_in_minutes
IMPORTING iv_entry_date TYPE d
iv_entry_time TYPE t
iv_exit_date TYPE d
iv_exit_time TYPE t
RETURNING VALUE(rv_minutes) TYPE i.
METHODS started_hours
IMPORTING iv_minutes TYPE i
RETURNING VALUE(rv_hours) TYPE i.
METHODS is_sunday
IMPORTING iv_date TYPE d
RETURNING VALUE(rv_sunday) TYPE abap_bool.
METHODS discounted
IMPORTING iv_fee TYPE {{p}}if_park_fee=>ty_amount
iv_discount TYPE abap_bool
RETURNING VALUE(rv_fee) TYPE {{p}}if_park_fee=>ty_amount.
ENDCLASS.
CLASS {{p}}park_fee_calculator IMPLEMENTATION.
METHOD {{p}}if_park_fee~calculate.
DATA(lv_minutes) = duration_in_minutes( iv_entry_date = iv_entry_date
iv_entry_time = iv_entry_time
iv_exit_date = iv_exit_date
iv_exit_time = iv_exit_time ).
IF lv_minutes < 0.
rs_result = VALUE #( reason = {{p}}if_park_fee=>c_reason-bad_time
fee = 0 ).
RETURN.
ENDIF.
IF lv_minutes > c_max_minutes.
rs_result = VALUE #( reason = {{p}}if_park_fee=>c_reason-too_long
fee = 0 ).
RETURN.
ENDIF.
IF iv_lost_ticket = abap_true.
rs_result = VALUE #( reason = {{p}}if_park_fee=>c_reason-ok
fee = c_lost_ticket ).
RETURN.
ENDIF.
IF lv_minutes <= c_free_minutes OR is_sunday( iv_entry_date ) = abap_true.
rs_result = VALUE #( reason = {{p}}if_park_fee=>c_reason-ok
fee = 0 ).
RETURN.
ENDIF.
DATA lv_fee TYPE {{p}}if_park_fee=>ty_amount.
lv_fee = started_hours( lv_minutes ) * c_price_per_hour.
lv_fee = discounted( iv_fee = lv_fee iv_discount = iv_discount ).
IF lv_fee > c_max_fee.
lv_fee = c_max_fee.
ENDIF.
rs_result = VALUE #( reason = {{p}}if_park_fee=>c_reason-ok
fee = lv_fee ).
ENDMETHOD.
METHOD duration_in_minutes.
DATA(lv_entry_time) = iv_entry_time.
DATA(lv_exit_time) = iv_exit_time.
lv_entry_time+4(2) = '00'.
lv_exit_time+4(2) = '00'.
DATA(lv_seconds) = ( iv_exit_date - iv_entry_date ) * c_seconds_per_day
+ ( lv_exit_time - lv_entry_time ).
rv_minutes = lv_seconds DIV 60.
ENDMETHOD.
METHOD started_hours.
rv_hours = iv_minutes DIV 60.
IF iv_minutes MOD 60 <> 0.
rv_hours = rv_hours + 1.
ENDIF.
ENDMETHOD.
METHOD is_sunday.
DATA(lv_offset) = iv_date - c_reference_date.
rv_sunday = xsdbool( lv_offset MOD 7 = c_sunday_offset ).
ENDMETHOD.
METHOD discounted.
rv_fee = iv_fee.
IF iv_discount = abap_true.
rv_fee = round( val = iv_fee * c_discount_rate
dec = 2
mode = cl_abap_math=>round_half_up ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,143 @@
CLASS ltc_park_fee DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}if_park_fee.
METHODS setup.
METHODS assert_result
IMPORTING is_result TYPE {{p}}if_park_fee=>ty_result
iv_fee TYPE {{p}}if_park_fee=>ty_amount
iv_reason TYPE {{p}}if_park_fee=>ty_reason.
METHODS free_period_is_free FOR TESTING.
METHODS one_hour_costs_250 FOR TESTING.
METHODS two_hours_cost_500 FOR TESTING.
METHODS sunday_is_free FOR TESTING.
METHODS lost_ticket_is_flat FOR TESTING.
METHODS discount_is_rounded FOR TESTING.
METHODS discount_rounds_up FOR TESTING.
METHODS fee_is_capped FOR TESTING.
METHODS exit_before_entry FOR TESTING.
METHODS long_parking FOR TESTING.
ENDCLASS.
CLASS ltc_park_fee IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}park_fee_calculator( ).
ENDMETHOD.
METHOD assert_result.
cl_abap_unit_assert=>assert_equals( exp = iv_fee act = is_result-fee ).
cl_abap_unit_assert=>assert_equals( exp = iv_reason act = is_result-reason ).
ENDMETHOD.
METHOD free_period_is_free.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '100015'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '0.00'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD one_hour_costs_250.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '103000'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '2.50'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD two_hours_cost_500.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '110100'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '5.00'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD sunday_is_free.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240107'
iv_entry_time = '090000'
iv_exit_date = '20240107'
iv_exit_time = '120000'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '0.00'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD lost_ticket_is_flat.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '100500'
iv_lost_ticket = abap_true
iv_discount = abap_false )
iv_fee = '45.00'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD discount_is_rounded.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '110100'
iv_lost_ticket = abap_false
iv_discount = abap_true )
iv_fee = '3.75'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD discount_rounds_up.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240108'
iv_exit_time = '103000'
iv_lost_ticket = abap_false
iv_discount = abap_true )
iv_fee = '1.88'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD fee_is_capped.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '060000'
iv_exit_date = '20240109'
iv_exit_time = '120000'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '60.00'
iv_reason = {{p}}if_park_fee=>c_reason-ok ).
ENDMETHOD.
METHOD exit_before_entry.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '120000'
iv_exit_date = '20240108'
iv_exit_time = '110000'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '0.00'
iv_reason = {{p}}if_park_fee=>c_reason-bad_time ).
ENDMETHOD.
METHOD long_parking.
assert_result( is_result = mo_cut->calculate( iv_entry_date = '20240108'
iv_entry_time = '100000'
iv_exit_date = '20240208'
iv_exit_time = '100100'
iv_lost_ticket = abap_false
iv_discount = abap_false )
iv_fee = '0.00'
iv_reason = {{p}}if_park_fee=>c_reason-too_long ).
ENDMETHOD.
ENDCLASS.