67 lines
2.2 KiB
ABAP
67 lines
2.2 KiB
ABAP
CLASS ltc_rideshare_split DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}rideshare_split.
|
|
|
|
METHODS setup.
|
|
METHODS assert_split
|
|
IMPORTING iv_distance_km TYPE {{p}}rideshare_split=>ty_distance
|
|
iv_passengers TYPE i
|
|
iv_exp_total TYPE {{p}}rideshare_split=>ty_amount
|
|
iv_exp_share TYPE {{p}}rideshare_split=>ty_amount.
|
|
|
|
METHODS no_passengers FOR TESTING.
|
|
METHODS single_passenger FOR TESTING.
|
|
METHODS distance_and_detour FOR TESTING.
|
|
METHODS negative_distance FOR TESTING.
|
|
METHODS rounds_half_away FOR TESTING.
|
|
METHODS minimum_share FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_rideshare_split IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}rideshare_split( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD assert_split.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_exp_total
|
|
act = mo_cut->calculate_total( iv_distance_km = iv_distance_km
|
|
iv_passengers = iv_passengers ) ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_exp_share
|
|
act = mo_cut->calculate_share( iv_distance_km = iv_distance_km
|
|
iv_passengers = iv_passengers ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD no_passengers.
|
|
assert_split( iv_distance_km = 12 iv_passengers = 0
|
|
iv_exp_total = '0.00' iv_exp_share = '0.00' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD single_passenger.
|
|
assert_split( iv_distance_km = 4 iv_passengers = 1
|
|
iv_exp_total = '4.60' iv_exp_share = '4.60' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD distance_and_detour.
|
|
assert_split( iv_distance_km = 10 iv_passengers = 3
|
|
iv_exp_total = '9.40' iv_exp_share = '3.13' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD negative_distance.
|
|
assert_split( iv_distance_km = -2 iv_passengers = 2
|
|
iv_exp_total = '4.20' iv_exp_share = '2.10' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rounds_half_away.
|
|
assert_split( iv_distance_km = 2 iv_passengers = 8
|
|
iv_exp_total = '12.20' iv_exp_share = '1.53' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD minimum_share.
|
|
assert_split( iv_distance_km = 0 iv_passengers = 7
|
|
iv_exp_total = '10.20' iv_exp_share = '1.50' ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|