@@ -338,7 +338,11 @@ fn validate_secondary_flows(
338338mod tests {
339339 use super :: * ;
340340 use crate :: commodity:: Commodity ;
341- use crate :: fixture:: { assert_error, process, sed_commodity, svd_commodity} ;
341+ use crate :: fixture:: {
342+ assert_error, assert_validate_fails_with_simple, assert_validate_ok_simple, process,
343+ sed_commodity, svd_commodity,
344+ } ;
345+ use crate :: patch:: FilePatch ;
342346 use crate :: process:: { FlowType , Process , ProcessFlow , ProcessMap } ;
343347 use crate :: units:: { FlowPerActivity , MoneyPerFlow } ;
344348 use indexmap:: IndexMap ;
@@ -518,4 +522,53 @@ mod tests {
518522 validate_flows_and_update_primary_output ( & mut processes, & flows_map, & milestone_years)
519523 . unwrap ( ) ;
520524 }
525+
526+ #[ test]
527+ fn flows_different_direction_different_years ( ) {
528+ let patch = FilePatch :: new ( "process_flows.csv" )
529+ . with_deletion ( "GASPRC,GASPRD,all,all,-1.05,fixed," )
530+ . with_addition ( "GASPRC,GASPRD,all,2020;2030,-1.05,fixed," )
531+ . with_addition ( "GASPRC,GASPRD,all,2040,1.05,fixed," ) ;
532+ assert_validate_fails_with_simple ! (
533+ vec![ patch] ,
534+ "Flow of commodity GASPRD in region GBR for process GASPRC behaves as input or output in different years."
535+ ) ;
536+ }
537+
538+ #[ test]
539+ fn missing_flow ( ) {
540+ let patch = FilePatch :: new ( "process_flows.csv" )
541+ . with_deletion ( "GASPRC,GASPRD,all,all,-1.05,fixed," )
542+ . with_addition ( "GASPRC,GASPRD,all,2020;2030,-1.05,fixed," ) ;
543+ assert_validate_fails_with_simple ! (
544+ vec![ patch] ,
545+ "Flow of commodity GASPRD in region GBR for process GASPRC does not cover all milestone years within the process range of activity."
546+ ) ;
547+ }
548+
549+ #[ test]
550+ fn coeff_zero ( ) {
551+ let patch = FilePatch :: new ( "process_flows.csv" )
552+ . with_deletion ( "GASPRC,GASPRD,all,all,-1.05,fixed," )
553+ . with_addition ( "GASPRC,GASPRD,all,2020;2030,-1.05,fixed," )
554+ . with_addition ( "GASPRC,GASPRD,all,2040,0,fixed," ) ;
555+ assert_validate_ok_simple ! ( vec![ patch] ) ;
556+ }
557+
558+ #[ test]
559+ fn flows_not_needed_before_time_horizon ( ) {
560+ // NB: Time horizon starts at 2020 for simple example
561+ //
562+ // Flows are only needed for milestone years. Check that users can omit them for
563+ // non-milestone years.
564+ let patches = vec ! [
565+ FilePatch :: new( "processes.csv" )
566+ . with_deletion( "GASDRV,Dry gas extraction,all,GASPRD,2020,2040,1.0" )
567+ . with_addition( "GASDRV,Dry gas extraction,all,GASPRD,1980,2040,1.0" ) ,
568+ FilePatch :: new( "process_flows.csv" )
569+ . with_deletion( "GASPRC,GASPRD,all,all,-1.05,fixed," )
570+ . with_addition( "GASPRC,GASPRD,all,2020;2030;2040,-1.05,fixed," ) ,
571+ ] ;
572+ assert_validate_ok_simple ! ( patches) ;
573+ }
521574}
0 commit comments