CLASS {{p}}t71_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. METHODS fee_for IMPORTING iv_category TYPE string iv_holes TYPE i iv_players TYPE i iv_tee_hour TYPE i EXPORTING ev_fee TYPE decfloat34 ev_reason TYPE string ev_message TYPE string. METHODS member_18_fee FOR TESTING. METHODS guest_9_fee FOR TESTING. METHODS junior_18_fee FOR TESTING. METHODS twilight_rate FOR TESTING. METHODS group_discount FOR TESTING. METHODS twilight_and_group FOR TESTING. METHODS rejects_player_count FOR TESTING. METHODS rejects_holes FOR TESTING. METHODS rejects_category FOR TESTING. METHODS rejects_tee_hour FOR TESTING. METHODS exception_message FOR TESTING. ENDCLASS. CLASS {{p}}t71_hidden IMPLEMENTATION. METHOD fee_for. CLEAR: ev_fee, ev_reason, ev_message. TRY. CALL FUNCTION '{{P}}GOLF_FEE' EXPORTING iv_category = iv_category iv_holes = iv_holes iv_players = iv_players iv_tee_hour = iv_tee_hour IMPORTING ev_fee = ev_fee. CATCH {{p}}cx_golf INTO DATA(lo_exc). ev_reason = lo_exc->mv_reason. ev_message = lo_exc->mv_message. ENDTRY. ENDMETHOD. METHOD member_18_fee. fee_for( EXPORTING iv_category = 'M' iv_holes = 18 iv_players = 1 iv_tee_hour = 6 IMPORTING ev_fee = DATA(lv_fee) ev_reason = DATA(lv_reason) ). cl_abap_unit_assert=>assert_initial( act = lv_reason ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 25 ) act = lv_fee ). ENDMETHOD. METHOD guest_9_fee. fee_for( EXPORTING iv_category = 'G' iv_holes = 9 iv_players = 2 iv_tee_hour = 10 IMPORTING ev_fee = DATA(lv_fee) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '62.50' ) act = lv_fee ). ENDMETHOD. METHOD junior_18_fee. fee_for( EXPORTING iv_category = 'J' iv_holes = 18 iv_players = 3 iv_tee_hour = 10 IMPORTING ev_fee = DATA(lv_fee) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '37.50' ) act = lv_fee ). ENDMETHOD. METHOD twilight_rate. fee_for( EXPORTING iv_category = 'G' iv_holes = 18 iv_players = 1 iv_tee_hour = 18 IMPORTING ev_fee = DATA(lv_late) ). fee_for( EXPORTING iv_category = 'G' iv_holes = 18 iv_players = 1 iv_tee_hour = 17 IMPORTING ev_fee = DATA(lv_early) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '46.88' ) act = lv_late ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '62.50' ) act = lv_early ). ENDMETHOD. METHOD group_discount. fee_for( EXPORTING iv_category = 'G' iv_holes = 18 iv_players = 4 iv_tee_hour = 17 IMPORTING ev_fee = DATA(lv_fee) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '225.00' ) act = lv_fee ). ENDMETHOD. METHOD twilight_and_group. fee_for( EXPORTING iv_category = 'G' iv_holes = 18 iv_players = 4 iv_tee_hour = 19 IMPORTING ev_fee = DATA(lv_fee) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '168.77' ) act = lv_fee ). ENDMETHOD. METHOD rejects_player_count. fee_for( EXPORTING iv_category = 'M' iv_holes = 18 iv_players = 0 iv_tee_hour = 10 IMPORTING ev_reason = DATA(lv_zero) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_PLAYERS` act = lv_zero ). fee_for( EXPORTING iv_category = 'M' iv_holes = 18 iv_players = 5 iv_tee_hour = 10 IMPORTING ev_reason = DATA(lv_five) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_PLAYERS` act = lv_five ). ENDMETHOD. METHOD rejects_holes. fee_for( EXPORTING iv_category = 'M' iv_holes = 12 iv_players = 1 iv_tee_hour = 10 IMPORTING ev_reason = DATA(lv_reason) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_HOLES` act = lv_reason ). ENDMETHOD. METHOD rejects_category. fee_for( EXPORTING iv_category = 'X' iv_holes = 18 iv_players = 1 iv_tee_hour = 10 IMPORTING ev_reason = DATA(lv_reason) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_CATEGORY` act = lv_reason ). ENDMETHOD. METHOD rejects_tee_hour. fee_for( EXPORTING iv_category = 'M' iv_holes = 18 iv_players = 1 iv_tee_hour = 5 IMPORTING ev_reason = DATA(lv_early) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_TEE_HOUR` act = lv_early ). fee_for( EXPORTING iv_category = 'M' iv_holes = 18 iv_players = 1 iv_tee_hour = 21 IMPORTING ev_reason = DATA(lv_late) ). cl_abap_unit_assert=>assert_equals( exp = `INVALID_TEE_HOUR` act = lv_late ). ENDMETHOD. METHOD exception_message. fee_for( EXPORTING iv_category = 'M' iv_holes = 12 iv_players = 1 iv_tee_hour = 10 IMPORTING ev_message = DATA(lv_text) ). cl_abap_unit_assert=>assert_equals( exp = `Number of holes must be 9 or 18` act = lv_text ). ENDMETHOD. ENDCLASS.