Skip to content

Commit 383e898

Browse files
committed
Add tests for ProcessFlow::get_total_cost
1 parent bfa778e commit 383e898

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

src/process.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,78 @@ mod tests {
313313
})
314314
}
315315

316+
#[fixture]
317+
fn flow_with_cost() -> ProcessFlow {
318+
ProcessFlow {
319+
commodity: Rc::new(Commodity {
320+
id: "test_commodity".into(),
321+
description: "Test commodity".into(),
322+
kind: CommodityType::ServiceDemand,
323+
time_slice_level: TimeSliceLevel::Annual,
324+
levies: CommodityLevyMap::new(),
325+
demand: DemandMap::new(),
326+
}),
327+
coeff: 1.0,
328+
kind: FlowType::Fixed,
329+
cost: 5.0,
330+
is_pac: true,
331+
}
332+
}
333+
334+
#[fixture]
335+
fn flow_with_cost_and_levy(region_id: RegionID, time_slice: TimeSliceID) -> ProcessFlow {
336+
let mut levies = CommodityLevyMap::new();
337+
levies.insert(
338+
(region_id, 2020, time_slice),
339+
CommodityLevy {
340+
balance_type: BalanceType::Net,
341+
value: 10.0,
342+
},
343+
);
344+
345+
ProcessFlow {
346+
commodity: Rc::new(Commodity {
347+
id: "test_commodity".into(),
348+
description: "Test commodity".into(),
349+
kind: CommodityType::ServiceDemand,
350+
time_slice_level: TimeSliceLevel::Annual,
351+
levies,
352+
demand: DemandMap::new(),
353+
}),
354+
coeff: 1.0,
355+
kind: FlowType::Fixed,
356+
cost: 5.0,
357+
is_pac: true,
358+
}
359+
}
360+
361+
#[fixture]
362+
fn flow_with_cost_and_incentive(region_id: RegionID, time_slice: TimeSliceID) -> ProcessFlow {
363+
let mut levies = CommodityLevyMap::new();
364+
levies.insert(
365+
(region_id, 2020, time_slice),
366+
CommodityLevy {
367+
balance_type: BalanceType::Net,
368+
value: -3.0,
369+
},
370+
);
371+
372+
ProcessFlow {
373+
commodity: Rc::new(Commodity {
374+
id: "test_commodity".into(),
375+
description: "Test commodity".into(),
376+
kind: CommodityType::ServiceDemand,
377+
time_slice_level: TimeSliceLevel::Annual,
378+
levies,
379+
demand: DemandMap::new(),
380+
}),
381+
coeff: 1.0,
382+
kind: FlowType::Fixed,
383+
cost: 5.0,
384+
is_pac: true,
385+
}
386+
}
387+
316388
#[rstest]
317389
fn test_get_levy_no_levies(
318390
commodity_no_levies: Rc<Commodity>,
@@ -479,4 +551,66 @@ mod tests {
479551

480552
assert_eq!(flow.get_levy(&region_id, 2020, &time_slice), 0.0);
481553
}
554+
555+
#[rstest]
556+
fn test_get_total_cost_base_cost(
557+
flow_with_cost: ProcessFlow,
558+
region_id: RegionID,
559+
time_slice: TimeSliceID,
560+
) {
561+
assert_eq!(
562+
flow_with_cost.get_total_cost(&region_id, 2020, &time_slice),
563+
5.0
564+
);
565+
}
566+
567+
#[rstest]
568+
fn test_get_total_cost_with_levy(
569+
flow_with_cost_and_levy: ProcessFlow,
570+
region_id: RegionID,
571+
time_slice: TimeSliceID,
572+
) {
573+
assert_eq!(
574+
flow_with_cost_and_levy.get_total_cost(&region_id, 2020, &time_slice),
575+
15.0
576+
);
577+
}
578+
579+
#[rstest]
580+
fn test_get_total_cost_with_incentive(
581+
flow_with_cost_and_incentive: ProcessFlow,
582+
region_id: RegionID,
583+
time_slice: TimeSliceID,
584+
) {
585+
assert_eq!(
586+
flow_with_cost_and_incentive.get_total_cost(&region_id, 2020, &time_slice),
587+
2.0
588+
);
589+
}
590+
591+
#[rstest]
592+
fn test_get_total_cost_negative_coeff(
593+
flow_with_cost: ProcessFlow,
594+
region_id: RegionID,
595+
time_slice: TimeSliceID,
596+
) {
597+
let flow = ProcessFlow {
598+
coeff: -2.0,
599+
..flow_with_cost
600+
};
601+
assert_eq!(flow.get_total_cost(&region_id, 2020, &time_slice), 10.0);
602+
}
603+
604+
#[rstest]
605+
fn test_get_total_cost_zero_coeff(
606+
flow_with_cost: ProcessFlow,
607+
region_id: RegionID,
608+
time_slice: TimeSliceID,
609+
) {
610+
let flow = ProcessFlow {
611+
coeff: 0.0,
612+
..flow_with_cost
613+
};
614+
assert_eq!(flow.get_total_cost(&region_id, 2020, &time_slice), 0.0);
615+
}
482616
}

0 commit comments

Comments
 (0)