@@ -60,6 +60,13 @@ rows[[8]] <- list("usage_ccf"=27.3,
6060 " et_amount" = 4.8 ,
6161 " irrigable_area" = 1300 ,
6262 " hhsize" = 3 )
63+ rows [[9 ]] <- list (" usage_ccf" = 27.3 ,
64+ " meter_size" = ' 5/8"' ,
65+ " cust_class" = " ERROR_CLASS4" ,
66+ " water_type" = " POTABLE" ,
67+ " et_amount" = 4.8 ,
68+ " irrigable_area" = 1300 ,
69+ " hhsize" = 3 )
6370df_test <- do.call(rbind.data.frame , rows [1 : 3 ])
6471
6572yaml_rates <- '
@@ -110,14 +117,14 @@ rate_structure:
110117 tier_starts:
111118 - 0
112119 - indoor
113- - 100 %
114- - 125 %
120+ - 101 %
121+ - 126 %
115122 tier_prices:
116123 - 2.87
117124 - 4.29
118125 - 6.44
119126 - 10.07
120- commodity_charge: Tiered
127+ commodity_charge: Budget
121128 bill: commodity_charge + service_charge
122129 IRRIGATION:
123130 service_charge:
@@ -242,6 +249,15 @@ rate_structure:
242249 - 6.33
243250 commodity_charge: Tiered
244251 bill: commodity_charge + service_charge
252+ ERROR_CLASS4:
253+ tier_starts:
254+ - 0
255+ - 101%
256+ tier_prices:
257+ - 4.07
258+ - 10.03
259+ commodity_charge: Tiered
260+ bill: commodity_charge
245261'
246262test_rates <- yaml.load(yaml_rates )
247263
@@ -253,15 +269,16 @@ calc <- function(df){
253269manual_bill_1 <- 33 + (4.07 * 388 ) + (2 * 10 + 0 * 378 )
254270manual_bill_2 <- 11 + (2.87 * 14 + 4.29 * 6 + 6.44 * 5 + 10.07 * 2.3 ) + (2 * 10 + 0 * 17.3 )
255271
256- manual_budget_3 <- 0.7 * 4.8 * 4500 * 0.62 * (1 / 748 )
257- manual_bill_3 <- 22 + 3.66 * floor( manual_budget_3 ) + 6.33 * (41 - floor( manual_budget_3 ) ) + 1.5 * 41
272+ manual_budget_3 <- round( 0.7 * 4.8 * 4500 * 0.62 * (1 / 748 ) )
273+ manual_bill_3 <- 22 + 3.66 * manual_budget_3 + 6.33 * (41 - manual_budget_3 ) + 1.5 * 41
258274
259- # manual_indoor_8 <- 60*3*30.4*(1/748)
260- # manual_outdoor_8 <- 0.7 * 1300 * 4.8 * 0.62 * (1/748)
261- # manual_budget_8 <- manual_indoor_8 + manual_outdoor_8
262- # manual_bill_8 <- 11 + 2.87*floor(manual_indoor) +
263- # 4.29*floor(manual_outdoor) +
264- # 6.44*floor(1.25*manual_budget_8 - manual_budget_8) + 10.07*(27.3-1.25*manual_budget_8)
275+ manual_indoor_8 <- round(60 * 3 * 30.4 * (1 / 748 ))
276+ manual_outdoor_8 <- round(0.7 * 1300 * 4.8 * 0.62 * (1 / 748 ))
277+ manual_budget_8 <- round(manual_indoor_8 + manual_outdoor_8 )
278+ manual_bill_8 <- 11 + 2.87 * manual_indoor_8 +
279+ 4.29 * manual_outdoor_8 +
280+ 6.44 * (round(1.26 * manual_budget_8 ) - manual_budget_8 ) +
281+ 10.07 * (27.3 - round(1.26 * manual_budget_8 ))
265282
266283manual_bills <- c(manual_bill_1 , manual_bill_2 , manual_bill_3 )
267284
@@ -270,7 +287,7 @@ test_that("Individual bills calculated accurately", {
270287 expect_equal(calc(as.data.frame(rows [[1 ]]))$ bill , manual_bill_1 )
271288 expect_equal(calc(as.data.frame(rows [[2 ]]))$ bill , manual_bill_2 )
272289 expect_equal(calc(as.data.frame(rows [[3 ]]))$ bill , manual_bill_3 )
273- # expect_equal(calc(as.data.frame(rows[[8]]))$bill, manual_bill_8)
290+ expect_equal(calc(as.data.frame(rows [[8 ]]))$ bill , manual_bill_8 )
274291})
275292
276293test_that(" Bills accurate when summed accross customer classes" , {
@@ -289,5 +306,9 @@ test_that("Error thrown when a field is missing", {
289306 expect_error(calc(as.data.frame(rows [[7 ]])), " is not present in the OWRS file for customer class" )
290307})
291308
309+ test_that(" Error thrown when % tiers used in 'Tiered' rate" , {
310+ expect_error(calc(as.data.frame(rows [[9 ]])), " Tiers are formatted for budget-based rates" )
311+ })
312+
292313
293314
0 commit comments