@@ -927,28 +927,31 @@ move_index_oob!(test_move_index_out_of_bounds_max_0, usize::MAX, 0);
927927#[ test]
928928fn disjoint_mut_empty_map ( ) {
929929 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
930- assert ! ( map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) . is_none( ) ) ;
930+ assert_eq ! (
931+ map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) ,
932+ [ None , None , None , None ]
933+ ) ;
931934}
932935
933936#[ test]
934937fn disjoint_mut_empty_param ( ) {
935938 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
936939 map. insert ( 1 , 10 ) ;
937- assert ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) . is_some ( ) ) ;
940+ assert_eq ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) , [ ] ) ;
938941}
939942
940943#[ test]
941944fn disjoint_mut_single_fail ( ) {
942945 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
943946 map. insert ( 1 , 10 ) ;
944- assert ! ( map. get_disjoint_mut( [ & 0 ] ) . is_none ( ) ) ;
947+ assert_eq ! ( map. get_disjoint_mut( [ & 0 ] ) , [ None ] ) ;
945948}
946949
947950#[ test]
948951fn disjoint_mut_single_success ( ) {
949952 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
950953 map. insert ( 1 , 10 ) ;
951- assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , Some ( [ & mut 10 ] ) ) ;
954+ assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , [ Some ( & mut 10 ) ] ) ;
952955}
953956
954957#[ test]
@@ -958,11 +961,22 @@ fn disjoint_mut_multi_success() {
958961 map. insert ( 2 , 200 ) ;
959962 map. insert ( 3 , 300 ) ;
960963 map. insert ( 4 , 400 ) ;
961- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 2 ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
962- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 3 ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
964+ assert_eq ! (
965+ map. get_disjoint_mut( [ & 1 , & 2 ] ) ,
966+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
967+ ) ;
968+ assert_eq ! (
969+ map. get_disjoint_mut( [ & 1 , & 3 ] ) ,
970+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
971+ ) ;
963972 assert_eq ! (
964973 map. get_disjoint_mut( [ & 3 , & 1 , & 4 , & 2 ] ) ,
965- Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
974+ [
975+ Some ( & mut 300 ) ,
976+ Some ( & mut 100 ) ,
977+ Some ( & mut 400 ) ,
978+ Some ( & mut 200 )
979+ ]
966980 ) ;
967981}
968982
@@ -973,44 +987,117 @@ fn disjoint_mut_multi_success_unsized_key() {
973987 map. insert ( "2" , 200 ) ;
974988 map. insert ( "3" , 300 ) ;
975989 map. insert ( "4" , 400 ) ;
976- assert_eq ! ( map. get_disjoint_mut( [ "1" , "2" ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
977- assert_eq ! ( map. get_disjoint_mut( [ "1" , "3" ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
990+
991+ assert_eq ! (
992+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
993+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
994+ ) ;
995+ assert_eq ! (
996+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
997+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
998+ ) ;
978999 assert_eq ! (
9791000 map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
980- Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
1001+ [
1002+ Some ( & mut 300 ) ,
1003+ Some ( & mut 100 ) ,
1004+ Some ( & mut 400 ) ,
1005+ Some ( & mut 200 )
1006+ ]
1007+ ) ;
1008+ }
1009+
1010+ #[ test]
1011+ fn disjoint_mut_multi_success_borrow_key ( ) {
1012+ let mut map: RingMap < String , u32 > = RingMap :: default ( ) ;
1013+ map. insert ( "1" . into ( ) , 100 ) ;
1014+ map. insert ( "2" . into ( ) , 200 ) ;
1015+ map. insert ( "3" . into ( ) , 300 ) ;
1016+ map. insert ( "4" . into ( ) , 400 ) ;
1017+
1018+ assert_eq ! (
1019+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
1020+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
1021+ ) ;
1022+ assert_eq ! (
1023+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
1024+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
1025+ ) ;
1026+ assert_eq ! (
1027+ map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
1028+ [
1029+ Some ( & mut 300 ) ,
1030+ Some ( & mut 100 ) ,
1031+ Some ( & mut 400 ) ,
1032+ Some ( & mut 200 )
1033+ ]
9811034 ) ;
9821035}
9831036
9841037#[ test]
9851038fn disjoint_mut_multi_fail_missing ( ) {
1039+ let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
1040+ map. insert ( 1 , 100 ) ;
1041+ map. insert ( 2 , 200 ) ;
1042+ map. insert ( 3 , 300 ) ;
1043+ map. insert ( 4 , 400 ) ;
1044+
1045+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 5 ] ) , [ Some ( & mut 100 ) , None ] ) ;
1046+ assert_eq ! ( map. get_disjoint_mut( [ & 5 , & 6 ] ) , [ None , None ] ) ;
1047+ assert_eq ! (
1048+ map. get_disjoint_mut( [ & 1 , & 5 , & 4 ] ) ,
1049+ [ Some ( & mut 100 ) , None , Some ( & mut 400 ) ]
1050+ ) ;
1051+ }
1052+
1053+ #[ test]
1054+ #[ should_panic]
1055+ fn disjoint_mut_multi_fail_duplicate_panic ( ) {
1056+ let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
1057+ map. insert ( 1 , 100 ) ;
1058+ map. get_disjoint_mut ( [ & 1 , & 2 , & 1 ] ) ;
1059+ }
1060+
1061+ #[ test]
1062+ fn disjoint_indices_mut_fail_oob ( ) {
1063+ let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
1064+ map. insert ( 1 , 10 ) ;
1065+ map. insert ( 321 , 20 ) ;
1066+ assert_eq ! (
1067+ map. get_disjoint_indices_mut( [ 1 , 3 ] ) ,
1068+ Err ( crate :: GetDisjointMutError :: IndexOutOfBounds )
1069+ ) ;
1070+ }
1071+
1072+ #[ test]
1073+ fn disjoint_indices_mut_empty ( ) {
9861074 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
9871075 map. insert ( 1 , 10 ) ;
988- map. insert ( 1123 , 100 ) ;
9891076 map. insert ( 321 , 20 ) ;
990- map. insert ( 1337 , 30 ) ;
991- assert_eq ! ( map. get_disjoint_mut( [ & 121 , & 1123 ] ) , None ) ;
992- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1337 , & 56 ] ) , None ) ;
993- assert_eq ! ( map. get_disjoint_mut( [ & 1337 , & 123 , & 321 , & 1 , & 1123 ] ) , None ) ;
1077+ assert_eq ! ( map. get_disjoint_indices_mut( [ ] ) , Ok ( [ ] ) ) ;
9941078}
9951079
9961080#[ test]
997- fn disjoint_mut_multi_fail_duplicate ( ) {
1081+ fn disjoint_indices_mut_success ( ) {
9981082 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
9991083 map. insert ( 1 , 10 ) ;
1000- map. insert ( 1123 , 100 ) ;
10011084 map. insert ( 321 , 20 ) ;
1002- map. insert ( 1337 , 30 ) ;
1003- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1 ] ) , None ) ;
1085+ assert_eq ! ( map. get_disjoint_indices_mut( [ 0 ] ) , Ok ( [ ( & 1 , & mut 10 ) ] ) ) ;
1086+
1087+ assert_eq ! ( map. get_disjoint_indices_mut( [ 1 ] ) , Ok ( [ ( & 321 , & mut 20 ) ] ) ) ;
10041088 assert_eq ! (
1005- map. get_disjoint_mut ( [ & 1337 , & 123 , & 321 , & 1337 , & 1 , & 1123 ] ) ,
1006- None
1089+ map. get_disjoint_indices_mut ( [ 0 , 1 ] ) ,
1090+ Ok ( [ ( & 1 , & mut 10 ) , ( & 321 , & mut 20 ) ] )
10071091 ) ;
10081092}
10091093
10101094#[ test]
1011- fn many_index_mut_fail_oob ( ) {
1095+ fn disjoint_indices_mut_fail_duplicate ( ) {
10121096 let mut map: RingMap < u32 , u32 > = RingMap :: default ( ) ;
10131097 map. insert ( 1 , 10 ) ;
10141098 map. insert ( 321 , 20 ) ;
1015- assert_eq ! ( map. get_disjoint_indices_mut( [ 1 , 3 ] ) , None ) ;
1099+ assert_eq ! (
1100+ map. get_disjoint_indices_mut( [ 1 , 2 , 1 ] ) ,
1101+ Err ( crate :: GetDisjointMutError :: OverlappingIndices )
1102+ ) ;
10161103}
0 commit comments