@@ -828,3 +828,94 @@ move_index_oob!(test_move_index_out_of_bounds_0_10, 0, 10);
828
828
move_index_oob ! ( test_move_index_out_of_bounds_0_max, 0 , usize :: MAX ) ;
829
829
move_index_oob ! ( test_move_index_out_of_bounds_10_0, 10 , 0 ) ;
830
830
move_index_oob ! ( test_move_index_out_of_bounds_max_0, usize :: MAX , 0 ) ;
831
+
832
+ #[ test]
833
+ fn disjoint_mut_empty_map ( ) {
834
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
835
+ assert ! ( map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) . is_none( ) ) ;
836
+ }
837
+
838
+ #[ test]
839
+ fn disjoint_mut_empty_param ( ) {
840
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
841
+ map. insert ( 1 , 10 ) ;
842
+ assert ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) . is_some( ) ) ;
843
+ }
844
+
845
+ #[ test]
846
+ fn disjoint_mut_single_fail ( ) {
847
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
848
+ map. insert ( 1 , 10 ) ;
849
+ assert ! ( map. get_disjoint_mut( [ & 0 ] ) . is_none( ) ) ;
850
+ }
851
+
852
+ #[ test]
853
+ fn disjoint_mut_single_success ( ) {
854
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
855
+ map. insert ( 1 , 10 ) ;
856
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , Some ( [ & mut 10 ] ) ) ;
857
+ }
858
+
859
+ #[ test]
860
+ fn disjoint_mut_multi_success ( ) {
861
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
862
+ map. insert ( 1 , 100 ) ;
863
+ map. insert ( 2 , 200 ) ;
864
+ map. insert ( 3 , 300 ) ;
865
+ map. insert ( 4 , 400 ) ;
866
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 2 ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
867
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 3 ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
868
+ assert_eq ! (
869
+ map. get_disjoint_mut( [ & 3 , & 1 , & 4 , & 2 ] ) ,
870
+ Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
871
+ ) ;
872
+ }
873
+
874
+ #[ test]
875
+ fn disjoint_mut_multi_success_unsized_key ( ) {
876
+ let mut map: IndexMap < & ' static str , u32 > = IndexMap :: default ( ) ;
877
+ map. insert ( "1" , 100 ) ;
878
+ map. insert ( "2" , 200 ) ;
879
+ map. insert ( "3" , 300 ) ;
880
+ map. insert ( "4" , 400 ) ;
881
+ assert_eq ! ( map. get_disjoint_mut( [ "1" , "2" ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
882
+ assert_eq ! ( map. get_disjoint_mut( [ "1" , "3" ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
883
+ assert_eq ! (
884
+ map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
885
+ Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
886
+ ) ;
887
+ }
888
+
889
+ #[ test]
890
+ fn disjoint_mut_multi_fail_missing ( ) {
891
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
892
+ map. insert ( 1 , 10 ) ;
893
+ map. insert ( 1123 , 100 ) ;
894
+ map. insert ( 321 , 20 ) ;
895
+ map. insert ( 1337 , 30 ) ;
896
+ assert_eq ! ( map. get_disjoint_mut( [ & 121 , & 1123 ] ) , None ) ;
897
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1337 , & 56 ] ) , None ) ;
898
+ assert_eq ! ( map. get_disjoint_mut( [ & 1337 , & 123 , & 321 , & 1 , & 1123 ] ) , None ) ;
899
+ }
900
+
901
+ #[ test]
902
+ fn disjoint_mut_multi_fail_duplicate ( ) {
903
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
904
+ map. insert ( 1 , 10 ) ;
905
+ map. insert ( 1123 , 100 ) ;
906
+ map. insert ( 321 , 20 ) ;
907
+ map. insert ( 1337 , 30 ) ;
908
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1 ] ) , None ) ;
909
+ assert_eq ! (
910
+ map. get_disjoint_mut( [ & 1337 , & 123 , & 321 , & 1337 , & 1 , & 1123 ] ) ,
911
+ None
912
+ ) ;
913
+ }
914
+
915
+ #[ test]
916
+ fn many_index_mut_fail_oob ( ) {
917
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
918
+ map. insert ( 1 , 10 ) ;
919
+ map. insert ( 321 , 20 ) ;
920
+ assert_eq ! ( map. get_disjoint_indices_mut( [ 1 , 3 ] ) , None ) ;
921
+ }
0 commit comments