Stage 2 summary at 50 accepted trajectories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
87
tasks_gen/train/G1077/reference/water_bill.clas.abap
Normal file
87
tasks_gen/train/G1077/reference/water_bill.clas.abap
Normal file
@@ -0,0 +1,87 @@
|
||||
CLASS {{p}}water_bill DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||
PUBLIC SECTION.
|
||||
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
|
||||
|
||||
METHODS constructor.
|
||||
|
||||
METHODS calculate
|
||||
IMPORTING iv_consumption TYPE i
|
||||
iv_days TYPE i
|
||||
RETURNING VALUE(rv_amount) TYPE ty_amount.
|
||||
|
||||
PRIVATE SECTION.
|
||||
DATA mo_tariff TYPE REF TO {{p}}water_tariff.
|
||||
|
||||
METHODS consumption_charge
|
||||
IMPORTING iv_consumption TYPE i
|
||||
RETURNING VALUE(rv_charge) TYPE ty_amount.
|
||||
|
||||
METHODS sewage_charge
|
||||
IMPORTING iv_consumption_charge TYPE ty_amount
|
||||
RETURNING VALUE(rv_charge) TYPE ty_amount.
|
||||
|
||||
METHODS standing_charge
|
||||
IMPORTING iv_days TYPE i
|
||||
RETURNING VALUE(rv_charge) TYPE ty_amount.
|
||||
|
||||
METHODS tier_charge
|
||||
IMPORTING iv_from TYPE i
|
||||
iv_to TYPE i
|
||||
iv_price TYPE {{p}}water_tariff=>ty_price
|
||||
RETURNING VALUE(rv_charge) TYPE ty_amount.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}water_bill IMPLEMENTATION.
|
||||
METHOD constructor.
|
||||
mo_tariff = NEW {{p}}water_tariff( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD calculate.
|
||||
DATA(lv_consumption_charge) = consumption_charge( iv_consumption ).
|
||||
DATA lv_net TYPE ty_amount.
|
||||
lv_net = lv_consumption_charge
|
||||
+ sewage_charge( lv_consumption_charge )
|
||||
+ standing_charge( iv_days ).
|
||||
DATA(lv_minimum) = mo_tariff->get_minimum_charge( ).
|
||||
IF lv_net < lv_minimum.
|
||||
rv_amount = lv_minimum.
|
||||
ELSE.
|
||||
rv_amount = lv_net.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD consumption_charge.
|
||||
DATA(lt_tiers) = mo_tariff->get_tiers( ).
|
||||
DATA lv_from TYPE i.
|
||||
LOOP AT lt_tiers INTO DATA(ls_tier).
|
||||
DATA(lv_to) = COND i( WHEN ls_tier-limit_cbm = 0 OR ls_tier-limit_cbm > iv_consumption
|
||||
THEN iv_consumption
|
||||
ELSE ls_tier-limit_cbm ).
|
||||
rv_charge = rv_charge + tier_charge( iv_from = lv_from
|
||||
iv_to = lv_to
|
||||
iv_price = ls_tier-price_cbm ).
|
||||
lv_from = lv_to.
|
||||
IF lv_from >= iv_consumption.
|
||||
EXIT.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sewage_charge.
|
||||
DATA lv_product TYPE p LENGTH 16 DECIMALS 4.
|
||||
lv_product = iv_consumption_charge * mo_tariff->get_sewage_percent( ).
|
||||
rv_charge = lv_product / 100.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD standing_charge.
|
||||
rv_charge = iv_days * mo_tariff->get_standing_charge( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD tier_charge.
|
||||
DATA(lv_units) = iv_to - iv_from.
|
||||
IF lv_units > 0.
|
||||
rv_charge = lv_units * iv_price.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
51
tasks_gen/train/G1077/reference/water_bill.testclasses.abap
Normal file
51
tasks_gen/train/G1077/reference/water_bill.testclasses.abap
Normal file
@@ -0,0 +1,51 @@
|
||||
CLASS ltc_water_bill DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
|
||||
|
||||
DATA mo_cut TYPE REF TO {{p}}water_bill.
|
||||
|
||||
METHODS setup.
|
||||
METHODS assert_bill
|
||||
IMPORTING iv_consumption TYPE i
|
||||
iv_days TYPE i
|
||||
iv_expected TYPE ty_amount.
|
||||
|
||||
METHODS first_tier_only FOR TESTING.
|
||||
METHODS third_tier FOR TESTING.
|
||||
METHODS minimum_charge FOR TESTING.
|
||||
METHODS standing_charge_only FOR TESTING.
|
||||
METHODS sewage_is_rounded FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltc_water_bill IMPLEMENTATION.
|
||||
METHOD setup.
|
||||
mo_cut = NEW {{p}}water_bill( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD assert_bill.
|
||||
DATA(lv_actual) = CONV ty_amount( mo_cut->calculate( iv_consumption = iv_consumption
|
||||
iv_days = iv_days ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = iv_expected act = lv_actual ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD first_tier_only.
|
||||
assert_bill( iv_consumption = 20 iv_days = 1 iv_expected = '68.91' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD third_tier.
|
||||
assert_bill( iv_consumption = 60 iv_days = 1 iv_expected = '264.51' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD minimum_charge.
|
||||
assert_bill( iv_consumption = 4 iv_days = 30 iv_expected = '35.00' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD standing_charge_only.
|
||||
assert_bill( iv_consumption = 0 iv_days = 100 iv_expected = '45.00' ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sewage_is_rounded.
|
||||
assert_bill( iv_consumption = 22 iv_days = 1 iv_expected = '78.04' ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user