CLASS {{p}}t14_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. TYPES ty_plan TYPE STANDARD TABLE OF {{p}}botpln WITH EMPTY KEY. CLASS-DATA mo_env TYPE REF TO if_osql_test_environment. CLASS-METHODS class_setup. CLASS-METHODS class_teardown. METHODS setup. METHODS add_order IMPORTING iv_id TYPE {{p}}botord-order_id iv_type TYPE {{p}}botord-beer_type iv_volume TYPE {{p}}botord-volume_hl. METHODS add_old_plan_row IMPORTING iv_type TYPE {{p}}botpln-beer_type. METHODS run_plan IMPORTING iv_min_hl TYPE decfloat34 EXPORTING ev_total TYPE decfloat34 ev_count TYPE int4. METHODS read_plan RETURNING VALUE(rt_plan) TYPE ty_plan. METHODS empty_input FOR TESTING. METHODS single_order FOR TESTING. METHODS sums_same_type FOR TESTING. METHODS ignores_bad_volume FOR TESTING. METHODS sorts_by_total FOR TESTING. METHODS tie_break_by_type FOR TESTING. METHODS total_over_groups FOR TESTING. METHODS min_volume_filters FOR TESTING. METHODS min_volume_boundary FOR TESTING. METHODS counts_orders FOR TESTING. METHODS replaces_old_plan FOR TESTING. ENDCLASS. CLASS {{p}}t14_hidden IMPLEMENTATION. METHOD class_setup. mo_env = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( '{{P}}BOTORD' ) ( '{{P}}BOTPLN' ) ) ). ENDMETHOD. METHOD class_teardown. IF mo_env IS BOUND. mo_env->destroy( ). ENDIF. ENDMETHOD. METHOD setup. DELETE FROM {{p}}botord. DELETE FROM {{p}}botpln. ENDMETHOD. METHOD add_order. DATA ls_order TYPE {{p}}botord. ls_order-client = sy-mandt. ls_order-order_id = iv_id. ls_order-beer_type = iv_type. ls_order-volume_hl = iv_volume. INSERT {{p}}botord FROM @ls_order. ENDMETHOD. METHOD add_old_plan_row. DATA ls_row TYPE {{p}}botpln. ls_row-client = sy-mandt. ls_row-beer_type = iv_type. ls_row-plan_pos = 99. ls_row-total_hl = 999. ls_row-order_count = 99. INSERT {{p}}botpln FROM @ls_row. ENDMETHOD. METHOD run_plan. CALL FUNCTION '{{P}}BOT_PLAN' EXPORTING iv_min_hl = iv_min_hl IMPORTING ev_total_hl = ev_total ev_plan_count = ev_count. ENDMETHOD. METHOD read_plan. SELECT beer_type, plan_pos, total_hl, order_count FROM {{p}}botpln INTO TABLE @rt_plan. SORT rt_plan BY plan_pos. ENDMETHOD. METHOD empty_input. run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_count ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_total ). cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( lt_plan ) ). ENDMETHOD. METHOD single_order. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 1 ]-plan_pos ). cl_abap_unit_assert=>assert_equals( exp = 100 act = lt_plan[ 1 ]-total_hl ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 1 ]-order_count ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 100 ) act = lv_total ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ). ENDMETHOD. METHOD sums_same_type. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'PILS' iv_volume = 50 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 150 act = lt_plan[ 1 ]-total_hl ). cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_plan[ 1 ]-order_count ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 150 ) act = lv_total ). ENDMETHOD. METHOD ignores_bad_volume. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'PILS' iv_volume = 0 ). add_order( iv_id = '3' iv_type = 'ZERO' iv_volume = 0 ). add_order( iv_id = '4' iv_type = 'ZERO' iv_volume = -5 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 100 act = lt_plan[ 1 ]-total_hl ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 1 ]-order_count ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ). ENDMETHOD. METHOD sorts_by_total. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 300 ). add_order( iv_id = '3' iv_type = 'STOU' iv_volume = 200 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 3 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'ALE' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 'STOU' act = lt_plan[ 2 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 3 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 1 ]-plan_pos ). cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_plan[ 2 ]-plan_pos ). cl_abap_unit_assert=>assert_equals( exp = 3 act = lt_plan[ 3 ]-plan_pos ). ENDMETHOD. METHOD tie_break_by_type. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 100 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'ALE' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 2 ]-beer_type ). ENDMETHOD. METHOD total_over_groups. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 300 ). add_order( iv_id = '3' iv_type = 'STOU' iv_volume = 200 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 600 ) act = lv_total ). cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_count ). ENDMETHOD. METHOD min_volume_filters. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). add_order( iv_id = '2' iv_type = 'ALE' iv_volume = 50 ). run_plan( EXPORTING iv_min_hl = 75 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 100 ) act = lv_total ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ). ENDMETHOD. METHOD min_volume_boundary. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). run_plan( EXPORTING iv_min_hl = 100 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). ENDMETHOD. METHOD counts_orders. add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 10 ). add_order( iv_id = '2' iv_type = 'PILS' iv_volume = 20 ). add_order( iv_id = '3' iv_type = 'PILS' iv_volume = 30 ). add_order( iv_id = '4' iv_type = 'ALE' iv_volume = 40 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 3 act = lt_plan[ 1 ]-order_count ). cl_abap_unit_assert=>assert_equals( exp = 'ALE' act = lt_plan[ 2 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_plan[ 2 ]-order_count ). cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_count ). ENDMETHOD. METHOD replaces_old_plan. add_old_plan_row( iv_type = 'OLD' ). add_order( iv_id = '1' iv_type = 'PILS' iv_volume = 100 ). run_plan( EXPORTING iv_min_hl = 0 IMPORTING ev_total = DATA(lv_total) ev_count = DATA(lv_count) ). DATA(lt_plan) = read_plan( ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_plan ) ). cl_abap_unit_assert=>assert_equals( exp = 'PILS' act = lt_plan[ 1 ]-beer_type ). cl_abap_unit_assert=>assert_equals( exp = 1 act = lv_count ). ENDMETHOD. ENDCLASS.