128 lines
5.2 KiB
ABAP
128 lines
5.2 KiB
ABAP
CLASS {{p}}t37_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS call
|
|
IMPORTING
|
|
iv_flavour TYPE string
|
|
iv_scoops TYPE i
|
|
iv_topping TYPE string
|
|
iv_here TYPE abap_bool
|
|
EXPORTING
|
|
ev_price TYPE decfloat34
|
|
ev_subrc TYPE sysubrc.
|
|
METHODS one_scoop_vanilla FOR TESTING.
|
|
METHODS three_scoops_chocolate FOR TESTING.
|
|
METHODS five_scoops_strawberry FOR TESTING.
|
|
METHODS topping_nut FOR TESTING.
|
|
METHODS topping_sprinkles FOR TESTING.
|
|
METHODS empty_topping FOR TESTING.
|
|
METHODS service_charge FOR TESTING.
|
|
METHODS service_rounding FOR TESTING.
|
|
METHODS rejects_zero_scoops FOR TESTING.
|
|
METHODS rejects_six_scoops FOR TESTING.
|
|
METHODS rejects_unknown_flavour FOR TESTING.
|
|
METHODS rejects_unknown_topping FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t37_hidden IMPLEMENTATION.
|
|
METHOD call.
|
|
DATA lv_price TYPE decfloat34.
|
|
CALL FUNCTION '{{P}}ICE_FEE'
|
|
EXPORTING
|
|
iv_flavour = iv_flavour
|
|
iv_scoops = iv_scoops
|
|
iv_topping = iv_topping
|
|
iv_here = iv_here
|
|
IMPORTING
|
|
ev_price = lv_price
|
|
EXCEPTIONS
|
|
invalid_scoops = 1
|
|
unknown_flavour = 2
|
|
unknown_topping = 3
|
|
OTHERS = 4.
|
|
ev_subrc = sy-subrc.
|
|
ev_price = lv_price.
|
|
ENDMETHOD.
|
|
|
|
METHOD one_scoop_vanilla.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 1 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '1.20' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD three_scoops_chocolate.
|
|
call( EXPORTING iv_flavour = 'CH' iv_scoops = 3 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '4.50' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD five_scoops_strawberry.
|
|
call( EXPORTING iv_flavour = 'ST' iv_scoops = 5 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '7.00' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD topping_nut.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 2 iv_topping = 'NUT' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '3.00' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD topping_sprinkles.
|
|
call( EXPORTING iv_flavour = 'ST' iv_scoops = 1 iv_topping = 'SPR' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '1.80' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_topping.
|
|
call( EXPORTING iv_flavour = 'CH' iv_scoops = 2 iv_topping = '' iv_here = abap_false
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '3.00' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD service_charge.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 1 iv_topping = 'NON' iv_here = abap_true
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '1.26' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD service_rounding.
|
|
call( EXPORTING iv_flavour = 'CH' iv_scoops = 1 iv_topping = 'NON' iv_here = abap_true
|
|
IMPORTING ev_price = DATA(lv_price) ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_subrc ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '1.58' ) act = lv_price ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rejects_zero_scoops.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 0 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_subrc ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rejects_six_scoops.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 6 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_subrc ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rejects_unknown_flavour.
|
|
call( EXPORTING iv_flavour = 'XX' iv_scoops = 1 iv_topping = 'NON' iv_here = abap_false
|
|
IMPORTING ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_subrc ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rejects_unknown_topping.
|
|
call( EXPORTING iv_flavour = 'VA' iv_scoops = 1 iv_topping = 'ZZ' iv_here = abap_false
|
|
IMPORTING ev_subrc = DATA(lv_subrc) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_subrc ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|