Stage 2 summary at 50 accepted trajectories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
23
tasks_gen/train/G1079/generation.json
Normal file
23
tasks_gen/train/G1079/generation.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"id": "G1079",
|
||||
"pool": "train",
|
||||
"object_type": "CLAS",
|
||||
"category": "H",
|
||||
"attempts": [
|
||||
{
|
||||
"stage": "bundle",
|
||||
"errors": [
|
||||
"reference/soil_evaluator.clas.abap line 87: syntax error for release v758 (abaplint): Statement does not exist in the configured ABAP version(or a parser error), \"5\""
|
||||
],
|
||||
"by_check": {
|
||||
"abaplint": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"stage": "validate",
|
||||
"oracle": 100,
|
||||
"null": 30
|
||||
}
|
||||
],
|
||||
"accepted": true
|
||||
}
|
||||
106
tasks_gen/train/G1079/reference/soil_evaluator.clas.abap
Normal file
106
tasks_gen/train/G1079/reference/soil_evaluator.clas.abap
Normal file
@@ -0,0 +1,106 @@
|
||||
CLASS {{p}}soil_evaluator DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
PUBLIC SECTION.
|
||||
TYPES:
|
||||
ty_ph TYPE p LENGTH 3 DECIMALS 1,
|
||||
ty_nutrient TYPE i,
|
||||
ty_status TYPE c LENGTH 1,
|
||||
ty_grade TYPE c LENGTH 1,
|
||||
BEGIN OF ty_sample,
|
||||
ph TYPE ty_ph,
|
||||
nutrient TYPE ty_nutrient,
|
||||
END OF ty_sample,
|
||||
tt_sample TYPE STANDARD TABLE OF ty_sample WITH EMPTY KEY,
|
||||
BEGIN OF ty_result,
|
||||
status TYPE ty_status,
|
||||
avg_ph TYPE ty_ph,
|
||||
avg_nutrient TYPE ty_nutrient,
|
||||
grade TYPE ty_grade,
|
||||
END OF ty_result.
|
||||
CONSTANTS:
|
||||
c_status_ok TYPE ty_status VALUE 'O',
|
||||
c_status_error TYPE ty_status VALUE 'E',
|
||||
c_grade_a TYPE ty_grade VALUE 'A',
|
||||
c_grade_b TYPE ty_grade VALUE 'B',
|
||||
c_grade_c TYPE ty_grade VALUE 'C'.
|
||||
METHODS evaluate
|
||||
IMPORTING it_samples TYPE tt_sample
|
||||
RETURNING VALUE(rs_result) TYPE ty_result.
|
||||
PRIVATE SECTION.
|
||||
CONSTANTS:
|
||||
c_ph_min TYPE ty_ph VALUE '0.0',
|
||||
c_ph_max TYPE ty_ph VALUE '14.0',
|
||||
c_ph_a_min TYPE ty_ph VALUE '6.0',
|
||||
c_ph_a_max TYPE ty_ph VALUE '7.5',
|
||||
c_ph_b_min TYPE ty_ph VALUE '5.0',
|
||||
c_ph_b_max TYPE ty_ph VALUE '8.0',
|
||||
c_nutr_a_min TYPE ty_nutrient VALUE 50,
|
||||
c_nutr_b_min TYPE ty_nutrient VALUE 30.
|
||||
METHODS has_invalid_ph
|
||||
IMPORTING it_samples TYPE tt_sample
|
||||
RETURNING VALUE(rv_invalid) TYPE abap_bool.
|
||||
METHODS average_ph
|
||||
IMPORTING it_samples TYPE tt_sample
|
||||
RETURNING VALUE(rv_avg) TYPE ty_ph.
|
||||
METHODS average_nutrient
|
||||
IMPORTING it_samples TYPE tt_sample
|
||||
RETURNING VALUE(rv_avg) TYPE ty_nutrient.
|
||||
METHODS determine_grade
|
||||
IMPORTING iv_avg_ph TYPE ty_ph
|
||||
iv_avg_nutrient TYPE ty_nutrient
|
||||
RETURNING VALUE(rv_grade) TYPE ty_grade.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS {{p}}soil_evaluator IMPLEMENTATION.
|
||||
METHOD evaluate.
|
||||
IF it_samples IS INITIAL.
|
||||
rs_result-status = c_status_error.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
IF has_invalid_ph( it_samples ) = abap_true.
|
||||
rs_result-status = c_status_error.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
rs_result-avg_ph = average_ph( it_samples ).
|
||||
rs_result-avg_nutrient = average_nutrient( it_samples ).
|
||||
rs_result-grade = determine_grade( iv_avg_ph = rs_result-avg_ph
|
||||
iv_avg_nutrient = rs_result-avg_nutrient ).
|
||||
rs_result-status = c_status_ok.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD has_invalid_ph.
|
||||
LOOP AT it_samples INTO DATA(ls_sample).
|
||||
IF ls_sample-ph < c_ph_min OR ls_sample-ph > c_ph_max.
|
||||
rv_invalid = abap_true.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD average_ph.
|
||||
DATA lv_sum TYPE p LENGTH 9 DECIMALS 1.
|
||||
LOOP AT it_samples INTO DATA(ls_sample).
|
||||
lv_sum = lv_sum + ls_sample-ph.
|
||||
ENDLOOP.
|
||||
rv_avg = lv_sum / lines( it_samples ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD average_nutrient.
|
||||
DATA lv_sum TYPE i.
|
||||
LOOP AT it_samples INTO DATA(ls_sample).
|
||||
lv_sum = lv_sum + ls_sample-nutrient.
|
||||
ENDLOOP.
|
||||
rv_avg = lv_sum / lines( it_samples ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD determine_grade.
|
||||
IF iv_avg_ph >= c_ph_a_min AND iv_avg_ph <= c_ph_a_max
|
||||
AND iv_avg_nutrient >= c_nutr_a_min.
|
||||
rv_grade = c_grade_a.
|
||||
ELSEIF iv_avg_ph >= c_ph_b_min AND iv_avg_ph <= c_ph_b_max
|
||||
AND iv_avg_nutrient >= c_nutr_b_min.
|
||||
rv_grade = c_grade_b.
|
||||
ELSE.
|
||||
rv_grade = c_grade_c.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,60 @@
|
||||
CLASS ltc_soil_evaluator DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
DATA mo_cut TYPE REF TO {{p}}soil_evaluator.
|
||||
METHODS setup.
|
||||
METHODS valid_samples_grade_a FOR TESTING.
|
||||
METHODS valid_samples_grade_b FOR TESTING.
|
||||
METHODS valid_samples_grade_c FOR TESTING.
|
||||
METHODS invalid_ph FOR TESTING.
|
||||
METHODS empty_table FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltc_soil_evaluator IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}soil_evaluator( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD valid_samples_grade_a.
|
||||
DATA(lt_samples) = VALUE {{p}}soil_evaluator=>tt_sample(
|
||||
( ph = '6.5' nutrient = 60 )
|
||||
( ph = '7.0' nutrient = 55 ) ).
|
||||
DATA(ls_result) = mo_cut->evaluate( lt_samples ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_status_ok act = ls_result-status ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = '6.8' act = ls_result-avg_ph ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 58 act = ls_result-avg_nutrient ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_grade_a act = ls_result-grade ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD valid_samples_grade_b.
|
||||
DATA(lt_samples) = VALUE {{p}}soil_evaluator=>tt_sample(
|
||||
( ph = '5.5' nutrient = 35 )
|
||||
( ph = '6.0' nutrient = 40 ) ).
|
||||
DATA(ls_result) = mo_cut->evaluate( lt_samples ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_status_ok act = ls_result-status ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_grade_b act = ls_result-grade ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD valid_samples_grade_c.
|
||||
DATA(lt_samples) = VALUE {{p}}soil_evaluator=>tt_sample(
|
||||
( ph = '4.0' nutrient = 10 ) ).
|
||||
DATA(ls_result) = mo_cut->evaluate( lt_samples ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_status_ok act = ls_result-status ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_grade_c act = ls_result-grade ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD invalid_ph.
|
||||
DATA(lt_samples) = VALUE {{p}}soil_evaluator=>tt_sample(
|
||||
( ph = '15.0' nutrient = 50 ) ).
|
||||
DATA(ls_result) = mo_cut->evaluate( lt_samples ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_status_error act = ls_result-status ).
|
||||
cl_abap_unit_assert=>assert_initial( act = ls_result-avg_ph ).
|
||||
cl_abap_unit_assert=>assert_initial( act = ls_result-avg_nutrient ).
|
||||
cl_abap_unit_assert=>assert_initial( act = ls_result-grade ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD empty_table.
|
||||
DATA(lt_samples) = VALUE {{p}}soil_evaluator=>tt_sample( ).
|
||||
DATA(ls_result) = mo_cut->evaluate( lt_samples ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}soil_evaluator=>c_status_error act = ls_result-status ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
50
tasks_gen/train/G1079/spec.md
Normal file
50
tasks_gen/train/G1079/spec.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# 1. Goal
|
||||
Evaluate soil samples from farms. A laboratory program calls the evaluation before it gives a fertilizer recommendation. The program needs the average pH, the average nutrient value, and a grade for each delivery of samples.
|
||||
|
||||
# 2. Open questions
|
||||
None.
|
||||
|
||||
# 3. Context
|
||||
- The class {{P}}SOIL_EVALUATOR is new. It is in package $TMP.
|
||||
- The laboratory program collects the samples of one delivery in a table.
|
||||
- Each sample has a pH value and a nutrient value.
|
||||
|
||||
# 4. Contract
|
||||
- Create the class {{P}}SOIL_EVALUATOR in package $TMP.
|
||||
- The class is public, final, and has a public constructor without parameters.
|
||||
- Define these public types:
|
||||
- TY_PH: type P, length 3, decimals 1.
|
||||
- TY_NUTRIENT: type I.
|
||||
- TY_STATUS: type C, length 1.
|
||||
- TY_GRADE: type C, length 1.
|
||||
- TY_SAMPLE: a structure with PH (type TY_PH) and NUTRIENT (type TY_NUTRIENT).
|
||||
- TT_SAMPLE: a standard table of TY_SAMPLE with empty key.
|
||||
- TY_RESULT: a structure with STATUS (type TY_STATUS), AVG_PH (type TY_PH), AVG_NUTRIENT (type TY_NUTRIENT), and GRADE (type TY_GRADE).
|
||||
- Define these public constants:
|
||||
- C_STATUS_OK TYPE TY_STATUS VALUE 'O'.
|
||||
- C_STATUS_ERROR TYPE TY_STATUS VALUE 'E'.
|
||||
- C_GRADE_A TYPE TY_GRADE VALUE 'A'.
|
||||
- C_GRADE_B TYPE TY_GRADE VALUE 'B'.
|
||||
- C_GRADE_C TYPE TY_GRADE VALUE 'C'.
|
||||
- Define this public method:
|
||||
- EVALUATE IMPORTING it_samples TYPE tt_sample RETURNING VALUE(rs_result) TYPE ty_result.
|
||||
- Do not add other public methods.
|
||||
|
||||
# 5. Business rules
|
||||
Apply the rules in this sequence.
|
||||
1. If any sample has a pH less than 0 or greater than 14, set STATUS = C_STATUS_ERROR. Leave the other fields of the result initial. Return the result.
|
||||
2. Calculate the average pH and the average nutrient of all samples. Round the average pH to one decimal place. Round the average nutrient to the nearest integer.
|
||||
3. Determine the grade:
|
||||
- If the average pH is between 6.0 and 7.5 inclusive and the average nutrient is 50 or more, set GRADE = C_GRADE_A.
|
||||
- Else if the average pH is between 5.0 and 8.0 inclusive and the average nutrient is 30 or more, set GRADE = C_GRADE_B.
|
||||
- Else set GRADE = C_GRADE_C.
|
||||
4. Set STATUS = C_STATUS_OK.
|
||||
|
||||
# 6. Constraints
|
||||
- Release target: 8.16.
|
||||
- Coding standards: Clean ABAP. Method length below 40 statements. No global variables. No comment that restates the code.
|
||||
- Out of scope: do not change other objects.
|
||||
|
||||
# 7. Acceptance
|
||||
- The class is active and has no syntax error.
|
||||
- Write your own ABAP Unit tests for the class.
|
||||
55
tasks_gen/train/G1079/task.json
Normal file
55
tasks_gen/train/G1079/task.json
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"id": "G1079",
|
||||
"category": "H",
|
||||
"object_type": "CLAS",
|
||||
"difficulty": 2,
|
||||
"release_target": "v816",
|
||||
"expected_outcome": "stop",
|
||||
"expected_gap": {
|
||||
"description": "The business rules do not state what the class returns when the input table is empty.",
|
||||
"keywords": [
|
||||
[
|
||||
"empty",
|
||||
"table"
|
||||
],
|
||||
[
|
||||
"empty",
|
||||
"input"
|
||||
],
|
||||
[
|
||||
"missing",
|
||||
"rule"
|
||||
],
|
||||
[
|
||||
"undefined",
|
||||
"empty"
|
||||
]
|
||||
]
|
||||
},
|
||||
"budget": {
|
||||
"max_tool_calls": 60,
|
||||
"max_activations": 15
|
||||
},
|
||||
"seed": [],
|
||||
"contract": [
|
||||
{
|
||||
"type": "CLAS",
|
||||
"name": "{{P}}SOIL_EVALUATOR"
|
||||
}
|
||||
],
|
||||
"out_of_scope": [],
|
||||
"hidden_tests": [],
|
||||
"reference": [
|
||||
{
|
||||
"type": "CLAS",
|
||||
"name": "{{P}}SOIL_EVALUATOR",
|
||||
"file": "reference/soil_evaluator.clas.abap",
|
||||
"description": "Soil evaluator",
|
||||
"testclasses_file": "reference/soil_evaluator.testclasses.abap"
|
||||
}
|
||||
],
|
||||
"craft_checks": [
|
||||
"method_length",
|
||||
"db_operation_in_loop"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user