Stage 2 summary at 50 accepted trajectories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
64
tasks_gen/train/G1081/reference/studio_summary.clas.abap
Normal file
64
tasks_gen/train/G1081/reference/studio_summary.clas.abap
Normal file
@@ -0,0 +1,64 @@
|
||||
CLASS {{p}}studio_summary DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
PUBLIC SECTION.
|
||||
TYPES:
|
||||
BEGIN OF ty_attendance,
|
||||
studio TYPE c LENGTH 4,
|
||||
class_id TYPE c LENGTH 8,
|
||||
class_type TYPE c LENGTH 10,
|
||||
member_id TYPE c LENGTH 8,
|
||||
fee TYPE p LENGTH 8 DECIMALS 2,
|
||||
END OF ty_attendance,
|
||||
tt_attendance TYPE STANDARD TABLE OF ty_attendance WITH EMPTY KEY,
|
||||
BEGIN OF ty_summary,
|
||||
class_type TYPE c LENGTH 10,
|
||||
class_count TYPE i,
|
||||
member_count TYPE i,
|
||||
total_fee TYPE p LENGTH 8 DECIMALS 2,
|
||||
END OF ty_summary,
|
||||
tt_summary TYPE STANDARD TABLE OF ty_summary WITH EMPTY KEY.
|
||||
|
||||
METHODS summarize
|
||||
IMPORTING it_attendance TYPE tt_attendance
|
||||
RETURNING VALUE(rt_summary) TYPE tt_summary.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}studio_summary IMPLEMENTATION.
|
||||
METHOD summarize.
|
||||
DATA lt_seen TYPE HASHED TABLE OF ty_attendance
|
||||
WITH UNIQUE KEY studio class_id member_id.
|
||||
DATA lt_class TYPE HASHED TABLE OF ty_attendance
|
||||
WITH UNIQUE KEY studio class_id class_type.
|
||||
DATA lt_member TYPE HASHED TABLE OF ty_attendance
|
||||
WITH UNIQUE KEY class_type member_id.
|
||||
DATA lt_groups TYPE HASHED TABLE OF ty_summary WITH UNIQUE KEY class_type.
|
||||
|
||||
LOOP AT it_attendance ASSIGNING FIELD-SYMBOL(<ls_attendance>).
|
||||
IF <ls_attendance>-class_type IS INITIAL OR <ls_attendance>-fee <= 0.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
INSERT <ls_attendance> INTO TABLE lt_seen.
|
||||
IF sy-subrc <> 0.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
ASSIGN lt_groups[ class_type = <ls_attendance>-class_type ]
|
||||
TO FIELD-SYMBOL(<ls_group>).
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE ty_summary( class_type = <ls_attendance>-class_type )
|
||||
INTO TABLE lt_groups ASSIGNING <ls_group>.
|
||||
ENDIF.
|
||||
<ls_group>-total_fee = <ls_group>-total_fee + <ls_attendance>-fee.
|
||||
INSERT <ls_attendance> INTO TABLE lt_class.
|
||||
IF sy-subrc = 0.
|
||||
<ls_group>-class_count = <ls_group>-class_count + 1.
|
||||
ENDIF.
|
||||
INSERT <ls_attendance> INTO TABLE lt_member.
|
||||
IF sy-subrc = 0.
|
||||
<ls_group>-member_count = <ls_group>-member_count + 1.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
rt_summary = lt_groups.
|
||||
SORT rt_summary BY class_type.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,71 @@
|
||||
CLASS ltc_studio_summary DEFINITION FINAL FOR TESTING
|
||||
DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_fee TYPE p LENGTH 8 DECIMALS 2.
|
||||
DATA mo_cut TYPE REF TO {{p}}studio_summary.
|
||||
METHODS setup.
|
||||
METHODS single_entry FOR TESTING.
|
||||
METHODS ignores_invalid_fee FOR TESTING.
|
||||
METHODS removes_duplicates FOR TESTING.
|
||||
METHODS groups_two_studios FOR TESTING.
|
||||
METHODS sorts_by_class_type FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltc_studio_summary IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}studio_summary( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD single_entry.
|
||||
DATA lt_input TYPE {{p}}studio_summary=>tt_attendance.
|
||||
lt_input = VALUE #( ( studio = 'S001' class_id = 'C0000001' class_type = 'YOGA'
|
||||
member_id = 'M0000001' fee = '12.50' ) ).
|
||||
DATA(lt_result) = mo_cut->summarize( lt_input ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_result ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_fee( '12.50' )
|
||||
act = lt_result[ 1 ]-total_fee ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD ignores_invalid_fee.
|
||||
DATA lt_input TYPE {{p}}studio_summary=>tt_attendance.
|
||||
lt_input = VALUE #( ( studio = 'S001' class_id = 'C0000001' class_type = 'YOGA'
|
||||
member_id = 'M0000001' fee = '0.00' ) ).
|
||||
DATA(lt_result) = mo_cut->summarize( lt_input ).
|
||||
cl_abap_unit_assert=>assert_initial( act = lt_result ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD removes_duplicates.
|
||||
DATA lt_input TYPE {{p}}studio_summary=>tt_attendance.
|
||||
lt_input = VALUE #( ( studio = 'S001' class_id = 'C0000001' class_type = 'YOGA'
|
||||
member_id = 'M0000001' fee = '10.00' )
|
||||
( studio = 'S001' class_id = 'C0000001' class_type = 'YOGA'
|
||||
member_id = 'M0000001' fee = '99.00' ) ).
|
||||
DATA(lt_result) = mo_cut->summarize( lt_input ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_result[ 1 ]-class_count ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_fee( '10.00' )
|
||||
act = lt_result[ 1 ]-total_fee ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD groups_two_studios.
|
||||
DATA lt_input TYPE {{p}}studio_summary=>tt_attendance.
|
||||
lt_input = VALUE #( ( studio = 'S001' class_id = 'C0000001' class_type = 'YOGA'
|
||||
member_id = 'M0000001' fee = '10.00' )
|
||||
( studio = 'S002' class_id = 'C0000002' class_type = 'YOGA'
|
||||
member_id = 'M0000002' fee = '15.00' ) ).
|
||||
DATA(lt_result) = mo_cut->summarize( lt_input ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_result ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_result[ 1 ]-class_count ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_result[ 1 ]-member_count ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sorts_by_class_type.
|
||||
DATA lt_input TYPE {{p}}studio_summary=>tt_attendance.
|
||||
lt_input = VALUE #( ( studio = 'S001' class_id = 'C0000001' class_type = 'ZUMBA'
|
||||
member_id = 'M0000001' fee = '10.00' )
|
||||
( studio = 'S001' class_id = 'C0000002' class_type = 'AEROBIC'
|
||||
member_id = 'M0000002' fee = '10.00' ) ).
|
||||
DATA(lt_result) = mo_cut->summarize( lt_input ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'AEROBIC' act = lt_result[ 1 ]-class_type ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user