Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
113 lines
4.0 KiB
ABAP
113 lines
4.0 KiB
ABAP
CLASS ltc_cold_chain DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}cold_chain_check.
|
|
|
|
METHODS setup.
|
|
METHODS mean_of
|
|
IMPORTING it_readings TYPE {{p}}cold_chain_check=>tt_readings
|
|
RETURNING VALUE(rv_mean) TYPE i.
|
|
METHODS rule_of
|
|
IMPORTING it_readings TYPE {{p}}cold_chain_check=>tt_readings
|
|
RETURNING VALUE(rv_rule) TYPE string.
|
|
|
|
METHODS valid_log FOR TESTING.
|
|
METHODS empty_log FOR TESTING.
|
|
METHODS late_start FOR TESTING.
|
|
METHODS wrong_order FOR TESTING.
|
|
METHODS short_duration FOR TESTING.
|
|
METHODS long_gap FOR TESTING.
|
|
METHODS too_warm FOR TESTING.
|
|
METHODS too_cold FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_cold_chain IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}cold_chain_check(
|
|
is_config = VALUE #( min_tenths = 20
|
|
max_tenths = 80
|
|
min_duration = 120
|
|
max_gap = 60 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD mean_of.
|
|
TRY.
|
|
rv_mean = mo_cut->check( it_readings ).
|
|
CATCH {{p}}cx_cold_chain INTO DATA(lx_error).
|
|
cl_abap_unit_assert=>fail( |Unexpected exception: { lx_error->mv_rule }| ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD rule_of.
|
|
TRY.
|
|
mo_cut->check( it_readings ).
|
|
cl_abap_unit_assert=>fail( `Exception expected` ).
|
|
CATCH {{p}}cx_cold_chain INTO DATA(lx_error).
|
|
rv_rule = lx_error->mv_rule.
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD valid_log.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 30 temp_tenths = 45 )
|
|
( offset_min = 60 temp_tenths = 50 )
|
|
( offset_min = 120 temp_tenths = 55 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 47 act = mean_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_log.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings( ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'TOO_FEW' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD late_start.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 10 temp_tenths = 40 )
|
|
( offset_min = 30 temp_tenths = 45 )
|
|
( offset_min = 120 temp_tenths = 50 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'NO_START' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD wrong_order.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 60 temp_tenths = 45 )
|
|
( offset_min = 30 temp_tenths = 50 )
|
|
( offset_min = 120 temp_tenths = 55 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'TIME_ORDER' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD short_duration.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 30 temp_tenths = 45 )
|
|
( offset_min = 90 temp_tenths = 50 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'TOO_SHORT' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD long_gap.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 90 temp_tenths = 45 )
|
|
( offset_min = 120 temp_tenths = 50 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'GAP' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD too_warm.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 60 temp_tenths = 85 )
|
|
( offset_min = 120 temp_tenths = 50 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'TOO_HIGH' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD too_cold.
|
|
DATA(lt_readings) = VALUE {{p}}cold_chain_check=>tt_readings(
|
|
( offset_min = 0 temp_tenths = 40 )
|
|
( offset_min = 60 temp_tenths = 15 )
|
|
( offset_min = 120 temp_tenths = 50 ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'TOO_LOW' act = rule_of( lt_readings ) ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|