Snapshot: new training tasks (balanced generation), docs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
183
tasks_gen/train/G1936/hidden/syrup_hidden.clas.abap
Normal file
183
tasks_gen/train/G1936/hidden/syrup_hidden.clas.abap
Normal file
@@ -0,0 +1,183 @@
|
||||
CLASS {{p}}syrup_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
||||
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_fields TYPE dfies_table.
|
||||
|
||||
CLASS-DATA go_env TYPE REF TO if_osql_test_environment.
|
||||
|
||||
CLASS-METHODS class_setup.
|
||||
CLASS-METHODS class_teardown.
|
||||
METHODS setup.
|
||||
|
||||
METHODS all_fields_exist FOR TESTING.
|
||||
METHODS field_types FOR TESTING.
|
||||
METHODS key_structure FOR TESTING.
|
||||
METHODS insert_and_read FOR TESTING.
|
||||
METHODS amount_round_trip FOR TESTING.
|
||||
METHODS duplicate_key FOR TESTING.
|
||||
METHODS filter_by_delivery FOR TESTING.
|
||||
|
||||
METHODS get_fields
|
||||
RETURNING VALUE(rt_fields) TYPE ty_fields.
|
||||
|
||||
METHODS assert_type
|
||||
IMPORTING
|
||||
it_fields TYPE ty_fields
|
||||
iv_name TYPE fieldname
|
||||
iv_type TYPE datatype_d
|
||||
iv_leng TYPE i
|
||||
iv_dec TYPE i.
|
||||
|
||||
METHODS assert_key
|
||||
IMPORTING
|
||||
it_fields TYPE ty_fields
|
||||
iv_name TYPE fieldname
|
||||
iv_key TYPE flag.
|
||||
|
||||
METHODS make_row
|
||||
IMPORTING
|
||||
iv_id TYPE {{p}}syrup-delivery_id
|
||||
iv_grove TYPE {{p}}syrup-grove_id
|
||||
RETURNING
|
||||
VALUE(rs_row) TYPE {{p}}syrup.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}syrup_hidden IMPLEMENTATION.
|
||||
|
||||
METHOD class_setup.
|
||||
go_env = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( '{{P}}SYRUP' ) ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD class_teardown.
|
||||
go_env->destroy( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD setup.
|
||||
go_env->clear_doubles( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD get_fields.
|
||||
DATA(lo_struct) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( '{{P}}SYRUP' ) ).
|
||||
rt_fields = lo_struct->get_ddic_field_list( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD assert_type.
|
||||
READ TABLE it_fields ASSIGNING FIELD-SYMBOL(<field>) WITH KEY fieldname = iv_name.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 msg = |Field { iv_name } is missing| ).
|
||||
DATA lv_leng TYPE i.
|
||||
lv_leng = <field>-leng.
|
||||
DATA lv_dec TYPE i.
|
||||
lv_dec = <field>-decimals.
|
||||
cl_abap_unit_assert=>assert_equals( exp = iv_type act = <field>-datatype msg = |Data type of { iv_name }| ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = iv_leng act = lv_leng msg = |Length of { iv_name }| ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = iv_dec act = lv_dec msg = |Decimals of { iv_name }| ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD assert_key.
|
||||
READ TABLE it_fields ASSIGNING FIELD-SYMBOL(<field>) WITH KEY fieldname = iv_name.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 msg = |Field { iv_name } is missing| ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = iv_key act = <field>-keyflag msg = |Key flag of { iv_name }| ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD make_row.
|
||||
rs_row-client = sy-mandt.
|
||||
rs_row-delivery_id = iv_id.
|
||||
rs_row-grove_id = iv_grove.
|
||||
rs_row-delivery_date = '20250210'.
|
||||
rs_row-sap_liters = '120.50'.
|
||||
rs_row-brix = '3.5'.
|
||||
rs_row-quality_grade = '02'.
|
||||
rs_row-payout = '250.00'.
|
||||
rs_row-currency_code = 'EUR'.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD all_fields_exist.
|
||||
DATA(lt_fields) = get_fields( ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 9 act = lines( lt_fields ) ).
|
||||
DATA lt_expected TYPE STANDARD TABLE OF fieldname WITH EMPTY KEY.
|
||||
lt_expected = VALUE #( ( 'CLIENT' ) ( 'DELIVERY_ID' ) ( 'GROVE_ID' )
|
||||
( 'DELIVERY_DATE' ) ( 'SAP_LITERS' ) ( 'BRIX' )
|
||||
( 'QUALITY_GRADE' ) ( 'PAYOUT' ) ( 'CURRENCY_CODE' ) ).
|
||||
LOOP AT lt_expected ASSIGNING FIELD-SYMBOL(<name>).
|
||||
READ TABLE lt_fields TRANSPORTING NO FIELDS WITH KEY fieldname = <name>.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 msg = |Field { <name> } is missing| ).
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD field_types.
|
||||
DATA(lt_fields) = get_fields( ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'CLIENT' iv_type = 'CLNT' iv_leng = 3 iv_dec = 0 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'DELIVERY_ID' iv_type = 'CHAR' iv_leng = 10 iv_dec = 0 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'GROVE_ID' iv_type = 'CHAR' iv_leng = 8 iv_dec = 0 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'DELIVERY_DATE' iv_type = 'DATS' iv_leng = 8 iv_dec = 0 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'SAP_LITERS' iv_type = 'DEC' iv_leng = 9 iv_dec = 2 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'BRIX' iv_type = 'DEC' iv_leng = 4 iv_dec = 1 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'QUALITY_GRADE' iv_type = 'NUMC' iv_leng = 2 iv_dec = 0 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'PAYOUT' iv_type = 'CURR' iv_leng = 15 iv_dec = 2 ).
|
||||
assert_type( it_fields = lt_fields iv_name = 'CURRENCY_CODE' iv_type = 'CUKY' iv_leng = 5 iv_dec = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD key_structure.
|
||||
DATA(lt_fields) = get_fields( ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'CLIENT' iv_key = 'X' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'DELIVERY_ID' iv_key = 'X' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'GROVE_ID' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'DELIVERY_DATE' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'SAP_LITERS' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'BRIX' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'QUALITY_GRADE' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'PAYOUT' iv_key = '' ).
|
||||
assert_key( it_fields = lt_fields iv_name = 'CURRENCY_CODE' iv_key = '' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD insert_and_read.
|
||||
DATA(ls_row) = make_row( iv_id = 'D1' iv_grove = 'G1' ).
|
||||
INSERT {{p}}syrup FROM @ls_row.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
SELECT SINGLE * FROM {{p}}syrup WHERE delivery_id = 'D1' INTO @DATA(ls_read).
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'G1' act = ls_read-grove_id ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = '20250210' act = ls_read-delivery_date ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = '02' act = ls_read-quality_grade ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD amount_round_trip.
|
||||
DATA(ls_row) = make_row( iv_id = 'D3' iv_grove = 'G3' ).
|
||||
ls_row-sap_liters = '88.25'.
|
||||
ls_row-payout = '1234.56'.
|
||||
ls_row-currency_code = 'CHF'.
|
||||
INSERT {{p}}syrup FROM @ls_row.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
SELECT SINGLE sap_liters, payout, currency_code FROM {{p}}syrup
|
||||
WHERE delivery_id = 'D3' INTO @DATA(ls_read).
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '88.25' )
|
||||
act = CONV decfloat34( ls_read-sap_liters ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '1234.56' )
|
||||
act = CONV decfloat34( ls_read-payout ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'CHF' act = ls_read-currency_code ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD duplicate_key.
|
||||
DATA(ls_row) = make_row( iv_id = 'D7' iv_grove = 'G7' ).
|
||||
INSERT {{p}}syrup FROM @ls_row.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
INSERT {{p}}syrup FROM @ls_row.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 4 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD filter_by_delivery.
|
||||
DATA(ls_first) = make_row( iv_id = 'D5' iv_grove = 'G5' ).
|
||||
INSERT {{p}}syrup FROM @ls_first.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
DATA(ls_second) = make_row( iv_id = 'D6' iv_grove = 'G6' ).
|
||||
INSERT {{p}}syrup FROM @ls_second.
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
SELECT SINGLE grove_id FROM {{p}}syrup WHERE delivery_id = 'D6' INTO @DATA(lv_grove).
|
||||
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'G6' act = lv_grove ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user