Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
70 lines
2.2 KiB
ABAP
70 lines
2.2 KiB
ABAP
CLASS {{p}}t14_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS reason_for
|
|
IMPORTING
|
|
iv_grain_type TYPE string
|
|
iv_weight_kg TYPE decfloat34
|
|
iv_moisture_pct TYPE decfloat34
|
|
iv_supplier TYPE string
|
|
RETURNING VALUE(rv_reason) TYPE string.
|
|
METHODS valid_delivery FOR TESTING.
|
|
METHODS weight_rule FOR TESTING.
|
|
METHODS grain_rules FOR TESTING.
|
|
METHODS drying_cost FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t14_test IMPLEMENTATION.
|
|
METHOD reason_for.
|
|
rv_reason = ``.
|
|
TRY.
|
|
CALL FUNCTION '{{P}}GRAIN_CHECK'
|
|
EXPORTING
|
|
iv_grain_type = iv_grain_type
|
|
iv_weight_kg = iv_weight_kg
|
|
iv_moisture_pct = iv_moisture_pct
|
|
iv_supplier = iv_supplier.
|
|
CATCH {{p}}cx_grain INTO DATA(lo_ex).
|
|
rv_reason = lo_ex->mv_reason.
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD valid_delivery.
|
|
cl_abap_unit_assert=>assert_initial(
|
|
act = reason_for( iv_grain_type = 'RYE' iv_weight_kg = 500 iv_moisture_pct = '13.0' iv_supplier = 'S9' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD weight_rule.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 'WEIGHT'
|
|
act = reason_for( iv_grain_type = 'WHEAT' iv_weight_kg = 0 iv_moisture_pct = '12.0' iv_supplier = 'S1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD grain_rules.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 'GRAIN_TYPE'
|
|
act = reason_for( iv_grain_type = 'MAIZE' iv_weight_kg = 10 iv_moisture_pct = '12.0' iv_supplier = 'S1' ) ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 'MOISTURE'
|
|
act = reason_for( iv_grain_type = 'RYE' iv_weight_kg = 10 iv_moisture_pct = '15.5' iv_supplier = 'S1' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD drying_cost.
|
|
DATA lv_cost TYPE decfloat34.
|
|
TRY.
|
|
CALL FUNCTION '{{P}}GRAIN_CHECK'
|
|
EXPORTING
|
|
iv_grain_type = 'BARLEY'
|
|
iv_weight_kg = 200
|
|
iv_moisture_pct = '14.0'
|
|
iv_supplier = 'S1'
|
|
IMPORTING
|
|
ev_drying_cost = lv_cost.
|
|
CATCH {{p}}cx_grain.
|
|
cl_abap_unit_assert=>fail( msg = 'no exception expected' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '300' ) act = lv_cost ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|