@@ -826,6 +826,8 @@ public void RemoveRange()
826
826
{
827
827
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => s_empty . RemoveRange ( 0 , 0 ) ) ;
828
828
Assert . Throws < NullReferenceException > ( ( ) => s_emptyDefault . RemoveRange ( 0 , 0 ) ) ;
829
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => s_emptyDefault . RemoveRange ( - 1 , 0 ) ) ;
830
+ Assert . Throws < NullReferenceException > ( ( ) => s_emptyDefault . RemoveRange ( 0 , - 1 ) ) ;
829
831
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => s_oneElement . RemoveRange ( 1 , 0 ) ) ;
830
832
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => s_empty . RemoveRange ( - 1 , 0 ) ) ;
831
833
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => s_oneElement . RemoveRange ( 0 , 2 ) ) ;
@@ -913,6 +915,35 @@ public void RemoveRangeEnumerableTest()
913
915
Assert . Equal ( new [ ] { 1 , 3 } , listWithDuplicates . RemoveRange ( new [ ] { 2 , 2 , 2 } ) ) ;
914
916
}
915
917
918
+ [ Fact ]
919
+ public void RemoveRangeImmutableArrayTest ( )
920
+ {
921
+ var list = ImmutableArray . Create ( 1 , 2 , 3 ) ;
922
+
923
+ ImmutableArray < int > removed2 = list . RemoveRange ( ImmutableArray . Create ( 2 ) ) ;
924
+ Assert . Equal ( 2 , removed2 . Length ) ;
925
+ Assert . Equal ( new [ ] { 1 , 3 } , removed2 ) ;
926
+
927
+ ImmutableArray < int > removed13 = list . RemoveRange ( ImmutableArray . Create ( 1 , 3 , 5 ) ) ;
928
+ Assert . Equal ( 1 , removed13 . Length ) ;
929
+ Assert . Equal ( new [ ] { 2 } , removed13 ) ;
930
+
931
+ Assert . Equal ( new [ ] { 1 , 3 , 6 , 8 , 9 } , ImmutableArray . CreateRange ( Enumerable . Range ( 1 , 10 ) ) . RemoveRange ( ImmutableArray . Create ( 2 , 4 , 5 , 7 , 10 ) ) ) ;
932
+ Assert . Equal ( new [ ] { 3 , 6 , 8 , 9 } , ImmutableArray . CreateRange ( Enumerable . Range ( 1 , 10 ) ) . RemoveRange ( ImmutableArray . Create ( 1 , 2 , 4 , 5 , 7 , 10 ) ) ) ;
933
+
934
+ Assert . Equal ( list , list . RemoveRange ( ImmutableArray . Create ( 5 ) ) ) ;
935
+ Assert . Equal ( ImmutableArray . Create < int > ( ) , ImmutableArray . Create < int > ( ) . RemoveRange ( ImmutableArray . Create ( 1 ) ) ) ;
936
+
937
+ var listWithDuplicates = ImmutableArray . Create ( 1 , 2 , 2 , 3 ) ;
938
+ Assert . Equal ( new [ ] { 1 , 2 , 3 } , listWithDuplicates . RemoveRange ( ImmutableArray . Create ( 2 ) ) ) ;
939
+ Assert . Equal ( new [ ] { 1 , 3 } , listWithDuplicates . RemoveRange ( ImmutableArray . Create ( 2 , 2 ) ) ) ;
940
+ Assert . Equal ( new [ ] { 1 , 3 } , listWithDuplicates . RemoveRange ( ImmutableArray . Create ( 2 , 2 , 2 ) ) ) ;
941
+
942
+ Assert . Equal ( new [ ] { 2 , 3 } , list . RemoveRange ( ImmutableArray . Create ( 42 ) , EverythingEqual < int > . Default ) ) ;
943
+ Assert . Equal ( new [ ] { 3 } , list . RemoveRange ( ImmutableArray . Create ( 42 , 42 ) , EverythingEqual < int > . Default ) ) ;
944
+ Assert . Equal ( new int [ 0 ] , list . RemoveRange ( ImmutableArray . Create ( 42 , 42 , 42 ) , EverythingEqual < int > . Default ) ) ;
945
+ }
946
+
916
947
[ Fact ]
917
948
public void Replace ( )
918
949
{
0 commit comments