118 lines
4.7 KiB
ABAP
118 lines
4.7 KiB
ABAP
CLASS {{p}}t21_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS call
|
|
IMPORTING iv_postcode TYPE string
|
|
iv_weight TYPE decfloat34
|
|
iv_express TYPE abap_bool DEFAULT abap_false
|
|
EXPORTING ev_tour TYPE string
|
|
ev_skip TYPE abap_bool
|
|
ev_fee TYPE decfloat34
|
|
ev_subrc TYPE sysubrc.
|
|
METHODS standard_fee FOR TESTING.
|
|
METHODS weight_surcharge FOR TESTING.
|
|
METHODS started_kilogram FOR TESTING.
|
|
METHODS heavy_tour FOR TESTING.
|
|
METHODS tour_boundary FOR TESTING.
|
|
METHODS express_surcharge FOR TESTING.
|
|
METHODS fee_cap FOR TESTING.
|
|
METHODS island_skip FOR TESTING.
|
|
METHODS unknown_zone FOR TESTING.
|
|
METHODS invalid_weight FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t21_hidden IMPLEMENTATION.
|
|
METHOD call.
|
|
CALL FUNCTION '{{P}}PARCEL_FEE'
|
|
EXPORTING
|
|
iv_postcode = iv_postcode
|
|
iv_weight = iv_weight
|
|
iv_express = iv_express
|
|
IMPORTING
|
|
ev_tour = ev_tour
|
|
ev_skip = ev_skip
|
|
ev_fee = ev_fee
|
|
EXCEPTIONS
|
|
unknown_zone = 1
|
|
invalid_weight = 2
|
|
OTHERS = 3.
|
|
ev_subrc = sy-subrc.
|
|
ENDMETHOD.
|
|
|
|
METHOD standard_fee.
|
|
call( EXPORTING iv_postcode = `10115` iv_weight = 1
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `N` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '4.90' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD weight_surcharge.
|
|
call( EXPORTING iv_postcode = `20095` iv_weight = 3
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `W` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '6.20' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD started_kilogram.
|
|
call( EXPORTING iv_postcode = `40213` iv_weight = '3.01'
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `C` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '7.25' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD heavy_tour.
|
|
call( EXPORTING iv_postcode = `60311` iv_weight = '10.01'
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `EH` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '10.60' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD tour_boundary.
|
|
call( EXPORTING iv_postcode = `60311` iv_weight = 10
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `E` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '10.25' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD express_surcharge.
|
|
call( EXPORTING iv_postcode = `10115` iv_weight = 1 iv_express = abap_true
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `N` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '8.40' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD fee_cap.
|
|
call( EXPORTING iv_postcode = `60311` iv_weight = 60
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `EH` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 25 ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD island_skip.
|
|
call( EXPORTING iv_postcode = `80331` iv_weight = 2
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `S` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_true act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_zone.
|
|
call( EXPORTING iv_postcode = `XYZ` iv_weight = 1
|
|
IMPORTING ev_subrc = DATA(lv_rc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_rc ).
|
|
ENDMETHOD.
|
|
|
|
METHOD invalid_weight.
|
|
call( EXPORTING iv_postcode = `10115` iv_weight = 0
|
|
IMPORTING ev_subrc = DATA(lv_rc_zero) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_rc_zero ).
|
|
call( EXPORTING iv_postcode = `10115` iv_weight = -5
|
|
IMPORTING ev_subrc = DATA(lv_rc_neg) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_rc_neg ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|