- Static bundle checks (name length, seed type, reserved words, contract test classes, testclasses_file), local abaplint parser check before SAP, max_tokens, robust JSON parse - Runner: G2 for CDS views with parameters, contract_check detail in report - G0020 and G0013 fixed by review and revalidated (oracle 100, null 0) - Pilot results in docs/faz1-tasarim.md 11e; handover notes merged into CLAUDE.md and docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
11 KiB
ABAP
208 lines
11 KiB
ABAP
CLASS {{p}}stock_age_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
CONSTANTS c_key_date TYPE dats VALUE '20240401'.
|
|
|
|
DATA mo_cut TYPE REF TO {{p}}if_stock_age.
|
|
|
|
METHODS setup.
|
|
METHODS gr_date_for_age
|
|
IMPORTING iv_age TYPE i
|
|
RETURNING VALUE(rv_date) TYPE dats.
|
|
|
|
METHODS empty_input FOR TESTING.
|
|
METHODS single_batch_bucket_01 FOR TESTING.
|
|
METHODS bucket_boundaries FOR TESTING.
|
|
METHODS groups_sum_quantity_and_count FOR TESTING.
|
|
METHODS result_is_sorted FOR TESTING.
|
|
METHODS invalid_rows_are_ignored FOR TESTING.
|
|
METHODS negative_and_zero_quantity FOR TESTING.
|
|
METHODS total_groups_by_material FOR TESTING.
|
|
METHODS total_is_sorted FOR TESTING.
|
|
METHODS total_ignores_invalid_rows FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}stock_age_hidden IMPLEMENTATION.
|
|
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}stock_age( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD gr_date_for_age.
|
|
rv_date = c_key_date - iv_age.
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_input.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch( )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_initial( act = lt_result ).
|
|
ENDMETHOD.
|
|
|
|
METHOD single_batch_bucket_01.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-1' batch = 'B1' quantity = 10
|
|
gr_date = gr_date_for_age( 0 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 1 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-material
|
|
exp = 'MAT-1' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d0_30 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-quantity exp = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 1 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD bucket_boundaries.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-B' batch = 'B1' quantity = 1 gr_date = gr_date_for_age( 30 ) )
|
|
( material = 'MAT-B' batch = 'B2' quantity = 1 gr_date = gr_date_for_age( 31 ) )
|
|
( material = 'MAT-B' batch = 'B3' quantity = 1 gr_date = gr_date_for_age( 60 ) )
|
|
( material = 'MAT-B' batch = 'B4' quantity = 1 gr_date = gr_date_for_age( 61 ) )
|
|
( material = 'MAT-B' batch = 'B5' quantity = 1 gr_date = gr_date_for_age( 90 ) )
|
|
( material = 'MAT-B' batch = 'B6' quantity = 1 gr_date = gr_date_for_age( 91 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 4 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d0_30 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 1 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d31_60 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-batch_count exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 3 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d61_90 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 3 ]-batch_count exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 4 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d91_plus ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 4 ]-batch_count exp = 1 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD groups_sum_quantity_and_count.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-A' batch = 'B1' quantity = 10 gr_date = gr_date_for_age( 1 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 5 gr_date = gr_date_for_age( 2 ) )
|
|
( material = 'MAT-A' batch = 'B3' quantity = 2 gr_date = gr_date_for_age( 200 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d0_30 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-quantity exp = 15 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-bucket
|
|
exp = {{p}}if_stock_age=>c_bucket-d91_plus ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-quantity exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-batch_count exp = 1 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD result_is_sorted.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-C' batch = 'B1' quantity = 1 gr_date = gr_date_for_age( 200 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 1 gr_date = gr_date_for_age( 40 ) )
|
|
( material = 'MAT-B' batch = 'B3' quantity = 1 gr_date = gr_date_for_age( 1 ) )
|
|
( material = 'MAT-A' batch = 'B4' quantity = 1 gr_date = gr_date_for_age( 1 ) )
|
|
( material = 'MAT-C' batch = 'B5' quantity = 1 gr_date = gr_date_for_age( 1 ) )
|
|
( material = 'MAT-B' batch = 'B6' quantity = 1 gr_date = gr_date_for_age( 70 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
DATA(lt_expected) = VALUE {{p}}if_stock_age=>tt_age_row(
|
|
( material = 'MAT-A' bucket = {{p}}if_stock_age=>c_bucket-d0_30 )
|
|
( material = 'MAT-A' bucket = {{p}}if_stock_age=>c_bucket-d31_60 )
|
|
( material = 'MAT-B' bucket = {{p}}if_stock_age=>c_bucket-d0_30 )
|
|
( material = 'MAT-B' bucket = {{p}}if_stock_age=>c_bucket-d61_90 )
|
|
( material = 'MAT-C' bucket = {{p}}if_stock_age=>c_bucket-d0_30 )
|
|
( material = 'MAT-C' bucket = {{p}}if_stock_age=>c_bucket-d91_plus ) ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 6 ).
|
|
|
|
DATA lv_index TYPE i.
|
|
LOOP AT lt_expected INTO DATA(ls_expected).
|
|
lv_index = lv_index + 1.
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ lv_index ]-material
|
|
exp = ls_expected-material ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ lv_index ]-bucket
|
|
exp = ls_expected-bucket ).
|
|
ENDLOOP.
|
|
ENDMETHOD.
|
|
|
|
METHOD invalid_rows_are_ignored.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-A' batch = 'B1' quantity = 10 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 99 gr_date = '00000000' )
|
|
( material = 'MAT-A' batch = 'B3' quantity = 99 gr_date = gr_date_for_age( -5 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 1 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-quantity exp = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 1 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD negative_and_zero_quantity.
|
|
DATA(lt_result) = mo_cut->analyze(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-A' batch = 'B1' quantity = 10 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = -4 gr_date = gr_date_for_age( 6 ) )
|
|
( material = 'MAT-B' batch = 'B3' quantity = 5 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-B' batch = 'B4' quantity = -5 gr_date = gr_date_for_age( 6 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-material exp = 'MAT-A' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-quantity exp = 6 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-material exp = 'MAT-B' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-quantity exp = 0 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-batch_count exp = 2 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_groups_by_material.
|
|
DATA(lt_result) = mo_cut->total_by_material(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-A' batch = 'B1' quantity = 10 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 5 gr_date = gr_date_for_age( 100 ) )
|
|
( material = 'MAT-B' batch = 'B3' quantity = 7 gr_date = gr_date_for_age( 5 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-material exp = 'MAT-A' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-quantity exp = 15 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-batch_count exp = 2 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-material exp = 'MAT-B' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-quantity exp = 7 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-batch_count exp = 1 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_is_sorted.
|
|
DATA(lt_result) = mo_cut->total_by_material(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-Z' batch = 'B1' quantity = 1 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 1 gr_date = gr_date_for_age( 5 ) )
|
|
( material = 'MAT-M' batch = 'B3' quantity = 1 gr_date = gr_date_for_age( 5 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 3 ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 1 ]-material exp = 'MAT-A' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 2 ]-material exp = 'MAT-M' ).
|
|
cl_abap_unit_assert=>assert_equals( act = lt_result[ 3 ]-material exp = 'MAT-Z' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_ignores_invalid_rows.
|
|
DATA(lt_result) = mo_cut->total_by_material(
|
|
it_batch = VALUE {{p}}if_stock_age=>tt_batch(
|
|
( material = 'MAT-A' batch = 'B1' quantity = 99 gr_date = '00000000' )
|
|
( material = 'MAT-A' batch = 'B2' quantity = 99 gr_date = gr_date_for_age( -1 ) ) )
|
|
iv_key_date = c_key_date ).
|
|
|
|
cl_abap_unit_assert=>assert_initial( act = lt_result ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|