94 lines
3.1 KiB
ABAP
94 lines
3.1 KiB
ABAP
CLASS {{p}}t21_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
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 negative_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.
|
|
METHODS minimum_boundary FOR TESTING.
|
|
METHODS long_ride FOR TESTING.
|
|
METHODS two_passengers FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t21_hidden 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 )
|
|
msg = |total, { iv_distance_km } km, { iv_passengers } 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 )
|
|
msg = |share, { iv_distance_km } km, { iv_passengers } passengers| ).
|
|
ENDMETHOD.
|
|
|
|
METHOD no_passengers.
|
|
assert_split( iv_distance_km = 10 iv_passengers = 0
|
|
iv_exp_total = '0.00' iv_exp_share = '0.00' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD negative_passengers.
|
|
assert_split( iv_distance_km = 5 iv_passengers = -3
|
|
iv_exp_total = '0.00' iv_exp_share = '0.00' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD single_passenger.
|
|
assert_split( iv_distance_km = 0 iv_passengers = 1
|
|
iv_exp_total = '3.00' iv_exp_share = '3.00' ).
|
|
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 = -5 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.
|
|
|
|
METHOD minimum_boundary.
|
|
assert_split( iv_distance_km = 0 iv_passengers = 6
|
|
iv_exp_total = '9.00' iv_exp_share = '1.50' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD long_ride.
|
|
assert_split( iv_distance_km = 100 iv_passengers = 5
|
|
iv_exp_total = '47.80' iv_exp_share = '9.56' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD two_passengers.
|
|
assert_split( iv_distance_km = 5 iv_passengers = 2
|
|
iv_exp_total = '6.20' iv_exp_share = '3.10' ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|