CLASS {{p}}feed_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. DATA mo_cut TYPE REF TO {{p}}if_feed_stock. METHODS setup. METHODS assert_stock IMPORTING it_exp TYPE {{p}}if_feed_stock=>tt_stock it_act TYPE {{p}}if_feed_stock=>tt_stock. METHODS empty_inputs FOR TESTING. METHODS sums_one_supplier FOR TESTING. METHODS merges_same_feed_type FOR TESTING. METHODS ignores_empty_feed_type FOR TESTING. METHODS ignores_zero_quantity FOR TESTING. METHODS negative_reduces_total FOR TESTING. METHODS removes_zero_total FOR TESTING. METHODS result_sorted FOR TESTING. METHODS unit_from_first_row FOR TESTING. METHODS counts_deliveries FOR TESTING. METHODS quantity_of_lookup FOR TESTING. METHODS top_feed_and_tie FOR TESTING. ENDCLASS. CLASS {{p}}feed_hidden IMPLEMENTATION. METHOD setup. mo_cut = NEW {{p}}feed_stock( ). ENDMETHOD. METHOD assert_stock. cl_abap_unit_assert=>assert_equals( exp = lines( it_exp ) act = lines( it_act ) msg = `row count` ). DATA(lv_index) = 0. LOOP AT it_exp ASSIGNING FIELD-SYMBOL(). lv_index = lv_index + 1. READ TABLE it_act ASSIGNING FIELD-SYMBOL() INDEX lv_index. cl_abap_unit_assert=>assert_subrc( exp = 0 act = sy-subrc msg = `row missing` ). cl_abap_unit_assert=>assert_equals( exp = -feed_type act = -feed_type msg = `feed type` ). cl_abap_unit_assert=>assert_equals( exp = -unit act = -unit msg = `unit` ). cl_abap_unit_assert=>assert_equals( exp = -quantity act = -quantity msg = `quantity` ). cl_abap_unit_assert=>assert_equals( exp = -deliveries act = -deliveries msg = `deliveries` ). ENDLOOP. ENDMETHOD. METHOD empty_inputs. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). cl_abap_unit_assert=>assert_initial( lt_stock ). ENDMETHOD. METHOD sums_one_supplier. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '10.500' ) ( feed_type = 'HAY' unit = 'KG' quantity = '4.500' ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '20.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'KG' quantity = '15.000' deliveries = 2 ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '20.000' deliveries = 1 ) ) it_act = lt_stock ). ENDMETHOD. METHOD merges_same_feed_type. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '10.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' ) ( feed_type = 'FISH' unit = 'KG' quantity = '3.000' ) ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'FISH' unit = 'KG' quantity = '3.000' deliveries = 1 ) ( feed_type = 'HAY' unit = 'KG' quantity = '15.000' deliveries = 2 ) ) it_act = lt_stock ). ENDMETHOD. METHOD ignores_empty_feed_type. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = '' unit = 'KG' quantity = '100.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' deliveries = 1 ) ) it_act = lt_stock ). ENDMETHOD. METHOD ignores_zero_quantity. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'BOX' quantity = '0.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' deliveries = 1 ) ) it_act = lt_stock ). ENDMETHOD. METHOD negative_reduces_total. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '10.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '-4.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'KG' quantity = '6.000' deliveries = 2 ) ) it_act = lt_stock ). ENDMETHOD. METHOD removes_zero_total. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '10.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '-10.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'PELLETS' unit = 'KG' quantity = '5.000' ) ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'PELLETS' unit = 'KG' quantity = '5.000' deliveries = 1 ) ) it_act = lt_stock ). ENDMETHOD. METHOD result_sorted. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'PELLETS' unit = 'KG' quantity = '1.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '2.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'FISH' unit = 'KG' quantity = '3.000' ) ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'FISH' unit = 'KG' quantity = '3.000' deliveries = 1 ) ( feed_type = 'HAY' unit = 'KG' quantity = '2.000' deliveries = 1 ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '1.000' deliveries = 1 ) ) it_act = lt_stock ). ENDMETHOD. METHOD unit_from_first_row. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'BOX' quantity = '5.000' ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '2.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '7.000' ) ( feed_type = 'PELLETS' unit = 'BOX' quantity = '3.000' ) ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'BOX' quantity = '12.000' deliveries = 2 ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '5.000' deliveries = 2 ) ) it_act = lt_stock ). ENDMETHOD. METHOD counts_deliveries. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '1.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '1.000' ) ( feed_type = 'HAY' unit = 'KG' quantity = '1.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '-1.000' ) ) ). assert_stock( it_exp = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'HAY' unit = 'KG' quantity = '2.000' deliveries = 4 ) ) it_act = lt_stock ). ENDMETHOD. METHOD quantity_of_lookup. DATA(lt_stock) = mo_cut->consolidate( it_supplier_a = VALUE {{p}}if_feed_stock=>tt_delivery( ( feed_type = 'HAY' unit = 'KG' quantity = '10.000' ) ( feed_type = 'PELLETS' unit = 'KG' quantity = '4.000' ) ) it_supplier_b = VALUE {{p}}if_feed_stock=>tt_delivery( ) ). DATA lv_expected TYPE {{p}}if_feed_stock=>ty_quantity. lv_expected = '10.000'. cl_abap_unit_assert=>assert_equals( exp = lv_expected act = mo_cut->quantity_of( it_stock = lt_stock iv_feed_type = 'HAY' ) msg = `HAY` ). CLEAR lv_expected. cl_abap_unit_assert=>assert_equals( exp = lv_expected act = mo_cut->quantity_of( it_stock = lt_stock iv_feed_type = 'FISH' ) msg = `FISH` ). cl_abap_unit_assert=>assert_equals( exp = lv_expected act = mo_cut->quantity_of( it_stock = VALUE {{p}}if_feed_stock=>tt_stock( ) iv_feed_type = 'HAY' ) msg = `empty list` ). ENDMETHOD. METHOD top_feed_and_tie. cl_abap_unit_assert=>assert_initial( mo_cut->top_feed( it_stock = VALUE {{p}}if_feed_stock=>tt_stock( ) ) ). DATA(lt_stock) = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'PELLETS' unit = 'KG' quantity = '9.000' deliveries = 1 ) ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' deliveries = 1 ) ). DATA lv_expected TYPE {{p}}if_feed_stock=>ty_feed_type. lv_expected = 'PELLETS'. cl_abap_unit_assert=>assert_equals( exp = lv_expected act = mo_cut->top_feed( it_stock = lt_stock ) ). DATA(lt_tie) = VALUE {{p}}if_feed_stock=>tt_stock( ( feed_type = 'PELLETS' unit = 'KG' quantity = '5.000' deliveries = 1 ) ( feed_type = 'HAY' unit = 'KG' quantity = '5.000' deliveries = 1 ) ). lv_expected = 'HAY'. cl_abap_unit_assert=>assert_equals( exp = lv_expected act = mo_cut->top_feed( it_stock = lt_tie ) ). ENDMETHOD. ENDCLASS.