Pipeline controller: plan 2 (hard +, error +50 %), backlog throttle, 2 trajectory workers, stop rules, summaries every 50; budget reserve
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
96
tasks_gen/train/G1311/reference/fish_auction.clas.abap
Normal file
96
tasks_gen/train/G1311/reference/fish_auction.clas.abap
Normal file
@@ -0,0 +1,96 @@
|
||||
CLASS {{p}}fish_auction DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
|
||||
PUBLIC SECTION.
|
||||
TYPES ty_species TYPE c LENGTH 10.
|
||||
TYPES ty_boat_id TYPE c LENGTH 10.
|
||||
|
||||
TYPES:
|
||||
BEGIN OF ty_catch,
|
||||
boat_id TYPE ty_boat_id,
|
||||
species TYPE ty_species,
|
||||
weight_kg TYPE i,
|
||||
END OF ty_catch.
|
||||
TYPES tt_catch TYPE STANDARD TABLE OF ty_catch WITH EMPTY KEY.
|
||||
|
||||
TYPES:
|
||||
BEGIN OF ty_summary,
|
||||
species TYPE ty_species,
|
||||
total_weight TYPE i,
|
||||
boat_count TYPE i,
|
||||
END OF ty_summary.
|
||||
TYPES tt_summary TYPE STANDARD TABLE OF ty_summary WITH EMPTY KEY.
|
||||
|
||||
METHODS summarize
|
||||
IMPORTING it_catch TYPE tt_catch
|
||||
RETURNING VALUE(rt_summary) TYPE tt_summary.
|
||||
|
||||
METHODS best_species
|
||||
IMPORTING it_catch TYPE tt_catch
|
||||
RETURNING VALUE(rv_species) TYPE ty_species.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES:
|
||||
BEGIN OF ty_boat_species,
|
||||
species TYPE ty_species,
|
||||
boat_id TYPE ty_boat_id,
|
||||
END OF ty_boat_species,
|
||||
tt_boat_species TYPE HASHED TABLE OF ty_boat_species
|
||||
WITH UNIQUE KEY species boat_id.
|
||||
|
||||
METHODS species_key
|
||||
IMPORTING iv_species TYPE ty_species
|
||||
RETURNING VALUE(rv_species) TYPE ty_species.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}fish_auction IMPLEMENTATION.
|
||||
|
||||
METHOD summarize.
|
||||
DATA lt_total TYPE SORTED TABLE OF ty_summary WITH UNIQUE KEY species.
|
||||
DATA lt_boat_species TYPE tt_boat_species.
|
||||
DATA lv_species TYPE ty_species.
|
||||
|
||||
LOOP AT it_catch INTO DATA(ls_catch).
|
||||
lv_species = species_key( ls_catch-species ).
|
||||
IF lv_species IS INITIAL OR ls_catch-weight_kg <= 0.
|
||||
CONTINUE.
|
||||
ENDIF.
|
||||
|
||||
READ TABLE lt_total WITH TABLE KEY species = lv_species
|
||||
ASSIGNING FIELD-SYMBOL(<ls_total>).
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE #( species = lv_species ) INTO TABLE lt_total.
|
||||
READ TABLE lt_total WITH TABLE KEY species = lv_species
|
||||
ASSIGNING <ls_total>.
|
||||
ENDIF.
|
||||
<ls_total>-total_weight = <ls_total>-total_weight + ls_catch-weight_kg.
|
||||
|
||||
INSERT VALUE #( species = lv_species boat_id = ls_catch-boat_id )
|
||||
INTO TABLE lt_boat_species.
|
||||
IF sy-subrc = 0.
|
||||
<ls_total>-boat_count = <ls_total>-boat_count + 1.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
rt_summary = lt_total.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD best_species.
|
||||
DATA(lt_summary) = summarize( it_catch ).
|
||||
DATA lv_best_weight TYPE i.
|
||||
|
||||
LOOP AT lt_summary INTO DATA(ls_summary).
|
||||
IF ls_summary-total_weight > lv_best_weight.
|
||||
lv_best_weight = ls_summary-total_weight.
|
||||
rv_species = ls_summary-species.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD species_key.
|
||||
DATA lv_species TYPE ty_species.
|
||||
lv_species = iv_species.
|
||||
SHIFT lv_species LEFT DELETING LEADING space.
|
||||
rv_species = to_upper( lv_species ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,77 @@
|
||||
CLASS ltc_fish_auction DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
DATA mo_cut TYPE REF TO {{p}}fish_auction.
|
||||
METHODS setup.
|
||||
METHODS sums_and_counts FOR TESTING.
|
||||
METHODS ignores_invalid_entries FOR TESTING.
|
||||
METHODS normalizes_species FOR TESTING.
|
||||
METHODS result_is_sorted FOR TESTING.
|
||||
METHODS best_species_wins FOR TESTING.
|
||||
METHODS best_species_tie FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltc_fish_auction IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}fish_auction( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sums_and_counts.
|
||||
DATA lt_result TYPE STANDARD TABLE OF {{p}}fish_auction=>ty_summary WITH EMPTY KEY.
|
||||
lt_result = mo_cut->summarize( VALUE #(
|
||||
( boat_id = 'B1' species = 'COD' weight_kg = 100 )
|
||||
( boat_id = 'B2' species = 'COD' weight_kg = 50 )
|
||||
( boat_id = 'B1' species = 'COD' weight_kg = 25 ) ) ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 1 ).
|
||||
READ TABLE lt_result INTO DATA(ls_row) WITH KEY species = 'COD'.
|
||||
cl_abap_unit_assert=>assert_equals( act = ls_row-total_weight exp = 175 ).
|
||||
cl_abap_unit_assert=>assert_equals( act = ls_row-boat_count exp = 2 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD ignores_invalid_entries.
|
||||
DATA lt_result TYPE STANDARD TABLE OF {{p}}fish_auction=>ty_summary WITH EMPTY KEY.
|
||||
lt_result = mo_cut->summarize( VALUE #(
|
||||
( boat_id = 'B1' species = ' ' weight_kg = 10 )
|
||||
( boat_id = 'B2' species = 'COD' weight_kg = 0 ) ) ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 0 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD normalizes_species.
|
||||
DATA lt_result TYPE STANDARD TABLE OF {{p}}fish_auction=>ty_summary WITH EMPTY KEY.
|
||||
lt_result = mo_cut->summarize( VALUE #(
|
||||
( boat_id = 'B1' species = ' tuna' weight_kg = 10 )
|
||||
( boat_id = 'B2' species = 'TUNA ' weight_kg = 20 ) ) ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( act = lines( lt_result ) exp = 1 ).
|
||||
READ TABLE lt_result INTO DATA(ls_row) WITH KEY species = 'TUNA'.
|
||||
cl_abap_unit_assert=>assert_equals( act = ls_row-total_weight exp = 30 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD result_is_sorted.
|
||||
DATA lt_result TYPE STANDARD TABLE OF {{p}}fish_auction=>ty_summary WITH EMPTY KEY.
|
||||
lt_result = mo_cut->summarize( VALUE #(
|
||||
( boat_id = 'B1' species = 'TUNA' weight_kg = 10 )
|
||||
( boat_id = 'B2' species = 'COD' weight_kg = 10 ) ) ).
|
||||
|
||||
READ TABLE lt_result INTO DATA(ls_row) INDEX 1.
|
||||
cl_abap_unit_assert=>assert_equals( act = ls_row-species exp = 'COD' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD best_species_wins.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = mo_cut->best_species( VALUE #(
|
||||
( boat_id = 'B1' species = 'COD' weight_kg = 10 )
|
||||
( boat_id = 'B2' species = 'TUNA' weight_kg = 40 ) ) )
|
||||
exp = 'TUNA' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD best_species_tie.
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = mo_cut->best_species( VALUE #(
|
||||
( boat_id = 'B1' species = 'TUNA' weight_kg = 30 )
|
||||
( boat_id = 'B2' species = 'COD' weight_kg = 30 ) ) )
|
||||
exp = 'COD' ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user