File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -307,6 +307,9 @@ impl AssetPool {
307307
308308 self . active . clear ( ) ;
309309 self . active . extend ( new_pool) ;
310+
311+ // New pool may not have been sorted, but active needs to be sorted by ID
312+ self . active . sort ( ) ;
310313 }
311314}
312315
@@ -538,4 +541,33 @@ mod tests {
538541 assert_eq ! ( asset_pool. active[ 0 ] . id, Some ( AssetID ( 2 ) ) ) ;
539542 assert_eq ! ( asset_pool. active[ 0 ] . agent_id, "some_other_agent" . into( ) ) ;
540543 }
544+
545+ #[ rstest]
546+ fn test_asset_pool_replace_active_pool_out_of_order (
547+ mut asset_pool : AssetPool ,
548+ process : Process ,
549+ ) {
550+ let new_asset = Asset :: new (
551+ "some_other_agent" . into ( ) ,
552+ process. into ( ) ,
553+ "GBR" . into ( ) ,
554+ 2.0 ,
555+ 2010 ,
556+ )
557+ . unwrap ( ) ;
558+
559+ asset_pool. commission_new ( 2020 ) ;
560+ assert_eq ! ( asset_pool. active. len( ) , 2 ) ;
561+ let mut new_pool: Vec < Rc < Asset > > = asset_pool
562+ . iter ( )
563+ . map ( |asset| asset. clone ( ) . into ( ) )
564+ . collect ( ) ;
565+ new_pool. push ( new_asset. into ( ) ) ;
566+ new_pool. reverse ( ) ;
567+
568+ asset_pool. replace_active_pool ( new_pool) ;
569+ assert_equal ( asset_pool. iter ( ) . map ( |asset| asset. id . unwrap ( ) . 0 ) , 0 ..3 ) ;
570+ assert_eq ! ( asset_pool. active[ 2 ] . id, Some ( AssetID ( 2 ) ) ) ;
571+ assert_eq ! ( asset_pool. active[ 2 ] . agent_id, "some_other_agent" . into( ) ) ;
572+ }
541573}
You can’t perform that action at this time.
0 commit comments