Stage 2 summary at 50 accepted trajectories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
110
tasks_gen/train/G1057/reference/air_freight_pricer.clas.abap
Normal file
110
tasks_gen/train/G1057/reference/air_freight_pricer.clas.abap
Normal file
@@ -0,0 +1,110 @@
|
||||
CLASS {{p}}air_freight_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
PUBLIC SECTION.
|
||||
INTERFACES {{p}}if_air_freight.
|
||||
|
||||
PRIVATE SECTION.
|
||||
CONSTANTS:
|
||||
c_volume_divisor TYPE i VALUE 6000,
|
||||
c_max_weight TYPE {{p}}if_air_freight=>ty_weight VALUE '3000',
|
||||
c_dangerous_rate TYPE p LENGTH 5 DECIMALS 4 VALUE '0.4000',
|
||||
c_fuel_rate TYPE p LENGTH 5 DECIMALS 4 VALUE '0.1200',
|
||||
c_security_fee TYPE {{p}}if_air_freight=>ty_amount VALUE '15.00'.
|
||||
|
||||
TYPES ty_rate TYPE p LENGTH 7 DECIMALS 2.
|
||||
|
||||
METHODS check_input
|
||||
IMPORTING iv_weight TYPE {{p}}if_air_freight=>ty_weight
|
||||
iv_volume TYPE {{p}}if_air_freight=>ty_volume
|
||||
iv_category TYPE {{p}}if_air_freight=>ty_category
|
||||
RETURNING VALUE(rv_reason) TYPE {{p}}if_air_freight=>ty_reason.
|
||||
|
||||
METHODS chargeable_weight
|
||||
IMPORTING iv_weight TYPE {{p}}if_air_freight=>ty_weight
|
||||
iv_volume TYPE {{p}}if_air_freight=>ty_volume
|
||||
RETURNING VALUE(rv_weight) TYPE {{p}}if_air_freight=>ty_weight.
|
||||
|
||||
METHODS base_rate
|
||||
IMPORTING iv_weight TYPE {{p}}if_air_freight=>ty_weight
|
||||
RETURNING VALUE(rv_rate) TYPE ty_rate.
|
||||
|
||||
METHODS category_factor
|
||||
IMPORTING iv_category TYPE {{p}}if_air_freight=>ty_category
|
||||
RETURNING VALUE(rv_factor) TYPE ty_rate.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}air_freight_pricer IMPLEMENTATION.
|
||||
METHOD {{p}}if_air_freight~price.
|
||||
rs_result-reason = check_input( iv_weight = iv_weight
|
||||
iv_volume = iv_volume
|
||||
iv_category = iv_category ).
|
||||
IF rs_result-reason <> {{p}}if_air_freight=>c_reason-ok.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
|
||||
rs_result-chargeable_weight = chargeable_weight( iv_weight = iv_weight
|
||||
iv_volume = iv_volume ).
|
||||
IF rs_result-chargeable_weight > c_max_weight.
|
||||
CLEAR rs_result.
|
||||
rs_result-reason = {{p}}if_air_freight=>c_reason-too_heavy.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
|
||||
rs_result-freight = rs_result-chargeable_weight * base_rate( rs_result-chargeable_weight )
|
||||
* category_factor( iv_category ).
|
||||
IF iv_dangerous = abap_true.
|
||||
rs_result-dangerous_fee = rs_result-freight * c_dangerous_rate.
|
||||
ENDIF.
|
||||
rs_result-fuel_fee = ( rs_result-freight + rs_result-dangerous_fee ) * c_fuel_rate.
|
||||
rs_result-security_fee = c_security_fee.
|
||||
rs_result-total_amount = rs_result-freight + rs_result-dangerous_fee
|
||||
+ rs_result-fuel_fee + rs_result-security_fee.
|
||||
rs_result-reason = {{p}}if_air_freight=>c_reason-ok.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD check_input.
|
||||
IF iv_weight <= 0.
|
||||
rv_reason = {{p}}if_air_freight=>c_reason-bad_weight.
|
||||
ELSEIF iv_volume <= 0.
|
||||
rv_reason = {{p}}if_air_freight=>c_reason-bad_volume.
|
||||
ELSEIF iv_category <> {{p}}if_air_freight=>c_category-general
|
||||
AND iv_category <> {{p}}if_air_freight=>c_category-perishable
|
||||
AND iv_category <> {{p}}if_air_freight=>c_category-valuable.
|
||||
rv_reason = {{p}}if_air_freight=>c_reason-bad_category.
|
||||
ELSE.
|
||||
rv_reason = {{p}}if_air_freight=>c_reason-ok.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD chargeable_weight.
|
||||
DATA lv_volumetric TYPE {{p}}if_air_freight=>ty_weight.
|
||||
DATA lv_gross TYPE {{p}}if_air_freight=>ty_weight.
|
||||
|
||||
lv_volumetric = iv_volume / c_volume_divisor.
|
||||
lv_gross = nmax( val1 = iv_weight val2 = lv_volumetric ).
|
||||
rv_weight = ceil( lv_gross ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD base_rate.
|
||||
IF iv_weight <= 45.
|
||||
rv_rate = '9.00'.
|
||||
ELSEIF iv_weight <= 100.
|
||||
rv_rate = '7.20'.
|
||||
ELSEIF iv_weight <= 500.
|
||||
rv_rate = '5.60'.
|
||||
ELSE.
|
||||
rv_rate = '4.30'.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD category_factor.
|
||||
CASE iv_category.
|
||||
WHEN {{p}}if_air_freight=>c_category-perishable.
|
||||
rv_factor = '1.25'.
|
||||
WHEN {{p}}if_air_freight=>c_category-valuable.
|
||||
rv_factor = '1.50'.
|
||||
WHEN OTHERS.
|
||||
rv_factor = '1.00'.
|
||||
ENDCASE.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,118 @@
|
||||
CLASS ltc_air_freight_pricer DEFINITION FINAL FOR TESTING
|
||||
DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_expected TYPE c LENGTH 20.
|
||||
|
||||
DATA mo_cut TYPE REF TO {{p}}if_air_freight.
|
||||
|
||||
METHODS setup.
|
||||
METHODS assert_weight
|
||||
IMPORTING iv_expected TYPE ty_expected
|
||||
iv_actual TYPE {{p}}if_air_freight=>ty_weight.
|
||||
METHODS assert_amount
|
||||
IMPORTING iv_expected TYPE ty_expected
|
||||
iv_actual TYPE {{p}}if_air_freight=>ty_amount.
|
||||
|
||||
METHODS general_shipment_is_priced FOR TESTING.
|
||||
METHODS volumetric_weight_wins FOR TESTING.
|
||||
METHODS dangerous_goods_surcharge FOR TESTING.
|
||||
METHODS zero_weight_is_rejected FOR TESTING.
|
||||
METHODS bad_category_is_rejected FOR TESTING.
|
||||
METHODS too_heavy_is_rejected FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltc_air_freight_pricer IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}air_freight_pricer( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD assert_weight.
|
||||
DATA lv_expected TYPE {{p}}if_air_freight=>ty_weight.
|
||||
lv_expected = iv_expected.
|
||||
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = iv_actual ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD assert_amount.
|
||||
DATA lv_expected TYPE {{p}}if_air_freight=>ty_amount.
|
||||
lv_expected = iv_expected.
|
||||
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = iv_actual ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD general_shipment_is_priced.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '12.000'
|
||||
iv_volume = '48000.000'
|
||||
iv_category = {{p}}if_air_freight=>c_category-general
|
||||
iv_dangerous = abap_false ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-ok
|
||||
act = ls_result-reason ).
|
||||
assert_weight( iv_expected = '12.000' iv_actual = ls_result-chargeable_weight ).
|
||||
assert_amount( iv_expected = '135.96' iv_actual = ls_result-total_amount ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD volumetric_weight_wins.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '5.000'
|
||||
iv_volume = '120000.000'
|
||||
iv_category = {{p}}if_air_freight=>c_category-general
|
||||
iv_dangerous = abap_false ).
|
||||
|
||||
assert_weight( iv_expected = '20.000' iv_actual = ls_result-chargeable_weight ).
|
||||
assert_amount( iv_expected = '216.60' iv_actual = ls_result-total_amount ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD dangerous_goods_surcharge.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '10.000'
|
||||
iv_volume = '600.000'
|
||||
iv_category = {{p}}if_air_freight=>c_category-valuable
|
||||
iv_dangerous = abap_true ).
|
||||
|
||||
assert_amount( iv_expected = '54.00' iv_actual = ls_result-dangerous_fee ).
|
||||
assert_amount( iv_expected = '226.68' iv_actual = ls_result-total_amount ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD zero_weight_is_rejected.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '0.000'
|
||||
iv_volume = '600.000'
|
||||
iv_category = {{p}}if_air_freight=>c_category-general
|
||||
iv_dangerous = abap_false ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-bad_weight
|
||||
act = ls_result-reason ).
|
||||
assert_amount( iv_expected = '0.00' iv_actual = ls_result-total_amount ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD bad_category_is_rejected.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '10.000'
|
||||
iv_volume = '600.000'
|
||||
iv_category = 'EXPRESS'
|
||||
iv_dangerous = abap_false ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-bad_category
|
||||
act = ls_result-reason ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD too_heavy_is_rejected.
|
||||
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
||||
|
||||
ls_result = mo_cut->price( iv_weight = '3000.500'
|
||||
iv_volume = '600.000'
|
||||
iv_category = {{p}}if_air_freight=>c_category-general
|
||||
iv_dangerous = abap_false ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-too_heavy
|
||||
act = ls_result-reason ).
|
||||
assert_amount( iv_expected = '0.00' iv_actual = ls_result-total_amount ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user