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:
102
tasks_gen/eval/G0101/reference/park_fee_calculator.clas.abap
Normal file
102
tasks_gen/eval/G0101/reference/park_fee_calculator.clas.abap
Normal 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.
|
||||
Reference in New Issue
Block a user