CLASS {{p}}cold_chain_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. DATA mo_cut TYPE REF TO {{p}}cold_chain_check. METHODS setup. METHODS build IMPORTING iv_offsets TYPE string iv_temps TYPE string RETURNING VALUE(rt_readings) TYPE {{p}}cold_chain_check=>tt_readings. 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_returns_mean FOR TESTING. METHODS too_few_readings FOR TESTING. METHODS no_start_at_zero FOR TESTING. METHODS offsets_not_increasing FOR TESTING. METHODS duration_too_short FOR TESTING. METHODS gap_too_large FOR TESTING. METHODS temperature_too_high FOR TESTING. METHODS temperature_too_low FOR TESTING. METHODS structural_error_first FOR TESTING. METHODS negative_mean_truncated FOR TESTING. METHODS exception_text FOR TESTING. ENDCLASS. CLASS {{p}}cold_chain_hidden 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 build. DATA lt_offsets TYPE STANDARD TABLE OF string WITH EMPTY KEY. DATA lt_temps TYPE STANDARD TABLE OF string WITH EMPTY KEY. SPLIT iv_offsets AT `,` INTO TABLE lt_offsets. SPLIT iv_temps AT `,` INTO TABLE lt_temps. DATA(lv_count) = lines( lt_offsets ). DO lv_count TIMES. APPEND VALUE #( offset_min = CONV i( lt_offsets[ sy-index ] ) temp_tenths = CONV i( lt_temps[ sy-index ] ) ) TO rt_readings. ENDDO. 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_returns_mean. cl_abap_unit_assert=>assert_equals( exp = 47 act = mean_of( build( iv_offsets = `0,30,60,120` iv_temps = `40,45,50,55` ) ) ). ENDMETHOD. METHOD too_few_readings. cl_abap_unit_assert=>assert_equals( exp = 'TOO_FEW' act = rule_of( build( iv_offsets = `0` iv_temps = `40` ) ) ). ENDMETHOD. METHOD no_start_at_zero. cl_abap_unit_assert=>assert_equals( exp = 'NO_START' act = rule_of( build( iv_offsets = `10,30,60,120` iv_temps = `40,45,50,55` ) ) ). ENDMETHOD. METHOD offsets_not_increasing. cl_abap_unit_assert=>assert_equals( exp = 'TIME_ORDER' act = rule_of( build( iv_offsets = `0,30,30,120` iv_temps = `40,45,50,55` ) ) ). ENDMETHOD. METHOD duration_too_short. cl_abap_unit_assert=>assert_equals( exp = 'TOO_SHORT' act = rule_of( build( iv_offsets = `0,30,60,90` iv_temps = `40,45,50,55` ) ) ). ENDMETHOD. METHOD gap_too_large. cl_abap_unit_assert=>assert_equals( exp = 'GAP' act = rule_of( build( iv_offsets = `0,90,120` iv_temps = `40,45,50` ) ) ). ENDMETHOD. METHOD temperature_too_high. cl_abap_unit_assert=>assert_equals( exp = 'TOO_HIGH' act = rule_of( build( iv_offsets = `0,30,60,120` iv_temps = `40,45,85,55` ) ) ). ENDMETHOD. METHOD temperature_too_low. cl_abap_unit_assert=>assert_equals( exp = 'TOO_LOW' act = rule_of( build( iv_offsets = `0,30,60,120` iv_temps = `40,45,15,55` ) ) ). ENDMETHOD. METHOD structural_error_first. cl_abap_unit_assert=>assert_equals( exp = 'NO_START' act = rule_of( build( iv_offsets = `10,30,60,90` iv_temps = `40,45,85,55` ) ) ). ENDMETHOD. METHOD negative_mean_truncated. DATA(lo_cut) = NEW {{p}}cold_chain_check( is_config = VALUE #( min_tenths = -250 max_tenths = -150 min_duration = 60 max_gap = 60 ) ). DATA lv_mean TYPE i. TRY. lv_mean = lo_cut->check( build( iv_offsets = `0,60` iv_temps = `-200,-211` ) ). CATCH {{p}}cx_cold_chain INTO DATA(lx_error). cl_abap_unit_assert=>fail( |Unexpected exception: { lx_error->mv_rule }| ). ENDTRY. cl_abap_unit_assert=>assert_equals( exp = -205 act = lv_mean ). ENDMETHOD. METHOD exception_text. TRY. mo_cut->check( build( iv_offsets = `` iv_temps = `` ) ). cl_abap_unit_assert=>fail( `Exception expected` ). CATCH {{p}}cx_cold_chain INTO DATA(lx_error). cl_abap_unit_assert=>assert_equals( exp = `Cold chain check failed: TOO_FEW` act = lx_error->get_text( ) ). ENDTRY. ENDMETHOD. ENDCLASS.