@@ -16,20 +16,6 @@ public class AddFirstTests
16
16
{ new int [ ] { 2 , 3 , 4 , 5 } , 1 , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
17
17
} ;
18
18
19
- public static TheoryData < IEnumerable < int > , IEnumerable < int > , bool , IReadOnlyCollection < int > > CollectionData =>
20
- new TheoryData < IEnumerable < int > , IEnumerable < int > , bool , IReadOnlyCollection < int > >
21
- {
22
- { new int [ ] { } , new int [ ] { } , false , new int [ ] { } } ,
23
- { new int [ ] { } , new int [ ] { 1 } , true , new int [ ] { 1 } } ,
24
- { new int [ ] { } , new int [ ] { 1 , 2 , 3 , 4 , 5 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
25
- { new int [ ] { 1 } , new int [ ] { } , false , new int [ ] { 1 } } ,
26
- { new int [ ] { 2 } , new int [ ] { 1 } , true , new int [ ] { 1 , 2 } } ,
27
- { new int [ ] { 5 } , new int [ ] { 1 , 2 , 3 , 4 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
28
- { new int [ ] { 1 , 2 , 3 , 4 , 5 } , new int [ ] { } , false , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
29
- { new int [ ] { 2 , 3 , 4 , 5 } , new int [ ] { 1 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
30
- { new int [ ] { 3 , 4 , 5 } , new int [ ] { 1 , 2 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
31
- } ;
32
-
33
19
[ Theory ]
34
20
[ MemberData ( nameof ( ItemData ) ) ]
35
21
void AddItem ( IEnumerable < int > collection , int item , IReadOnlyCollection < int > expected )
@@ -48,6 +34,20 @@ void AddItem(IEnumerable<int> collection, int item, IReadOnlyCollection<int> exp
48
34
list . EnumerateReversed ( ) . Should ( ) . Equal ( expected . Reverse ( ) ) ;
49
35
}
50
36
37
+ public static TheoryData < IEnumerable < int > , IEnumerable < int > , bool , IReadOnlyCollection < int > > CollectionData =>
38
+ new TheoryData < IEnumerable < int > , IEnumerable < int > , bool , IReadOnlyCollection < int > >
39
+ {
40
+ { new int [ ] { } , new int [ ] { } , false , new int [ ] { } } ,
41
+ { new int [ ] { } , new int [ ] { 1 } , true , new int [ ] { 1 } } ,
42
+ { new int [ ] { } , new int [ ] { 1 , 2 , 3 , 4 , 5 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
43
+ { new int [ ] { 1 } , new int [ ] { } , false , new int [ ] { 1 } } ,
44
+ { new int [ ] { 2 } , new int [ ] { 1 } , true , new int [ ] { 1 , 2 } } ,
45
+ { new int [ ] { 5 } , new int [ ] { 1 , 2 , 3 , 4 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
46
+ { new int [ ] { 1 , 2 , 3 , 4 , 5 } , new int [ ] { } , false , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
47
+ { new int [ ] { 2 , 3 , 4 , 5 } , new int [ ] { 1 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
48
+ { new int [ ] { 3 , 4 , 5 } , new int [ ] { 1 , 2 } , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
49
+ } ;
50
+
51
51
[ Theory ]
52
52
[ MemberData ( nameof ( CollectionData ) ) ]
53
53
void AddCollection ( IEnumerable < int > collection , IEnumerable < int > items , bool isMutated , IReadOnlyCollection < int > expected )
@@ -68,5 +68,51 @@ void AddCollection(IEnumerable<int> collection, IEnumerable<int> items, bool isM
68
68
list . EnumerateForward ( ) . Should ( ) . Equal ( expected ) ;
69
69
list . EnumerateReversed ( ) . Should ( ) . Equal ( expected . Reverse ( ) ) ;
70
70
}
71
+
72
+ public static TheoryData < IEnumerable < int > , IEnumerable < int > , bool , bool , IReadOnlyCollection < int > > ListData =>
73
+ new TheoryData < IEnumerable < int > , IEnumerable < int > , bool , bool , IReadOnlyCollection < int > >
74
+ {
75
+ { new int [ ] { } , new int [ ] { } , false , false , new int [ ] { } } ,
76
+ { new int [ ] { } , new int [ ] { 1 } , false , true , new int [ ] { 1 } } ,
77
+ { new int [ ] { } , new int [ ] { 1 , 2 , 3 , 4 , 5 } , false , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
78
+ { new int [ ] { 1 } , new int [ ] { } , false , false , new int [ ] { 1 } } ,
79
+ { new int [ ] { 2 } , new int [ ] { 1 } , false , true , new int [ ] { 1 , 2 } } ,
80
+ { new int [ ] { 5 } , new int [ ] { 1 , 2 , 3 , 4 } , false , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
81
+ { new int [ ] { 1 , 2 , 3 , 4 , 5 } , new int [ ] { } , false , false , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
82
+ { new int [ ] { 2 , 3 , 4 , 5 } , new int [ ] { 1 } , false , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
83
+ { new int [ ] { 3 , 4 , 5 } , new int [ ] { 1 , 2 } , false , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
84
+ { new int [ ] { } , new int [ ] { } , true , false , new int [ ] { } } ,
85
+ { new int [ ] { } , new int [ ] { 1 } , true , true , new int [ ] { 1 } } ,
86
+ { new int [ ] { } , new int [ ] { 1 , 2 , 3 , 4 , 5 } , true , true , new int [ ] { 5 , 4 , 3 , 2 , 1 } } ,
87
+ { new int [ ] { 1 } , new int [ ] { } , true , false , new int [ ] { 1 } } ,
88
+ { new int [ ] { 2 } , new int [ ] { 1 } , true , true , new int [ ] { 1 , 2 } } ,
89
+ { new int [ ] { 5 } , new int [ ] { 1 , 2 , 3 , 4 } , true , true , new int [ ] { 4 , 3 , 2 , 1 , 5 } } ,
90
+ { new int [ ] { 1 , 2 , 3 , 4 , 5 } , new int [ ] { } , true , false , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
91
+ { new int [ ] { 2 , 3 , 4 , 5 } , new int [ ] { 1 } , true , true , new int [ ] { 1 , 2 , 3 , 4 , 5 } } ,
92
+ { new int [ ] { 3 , 4 , 5 } , new int [ ] { 1 , 2 } , true , true , new int [ ] { 2 , 1 , 3 , 4 , 5 } } ,
93
+ } ;
94
+
95
+ [ Theory ]
96
+ [ MemberData ( nameof ( ListData ) ) ]
97
+ void AddList ( IEnumerable < int > collection , IEnumerable < int > items , bool reversed , bool isMutated , IReadOnlyCollection < int > expected )
98
+ {
99
+ // Arrange
100
+ var left = new DoubleLinkedList < int > ( collection ) ;
101
+ var version = left . Version ;
102
+ var right = new DoubleLinkedList < int > ( items ) ;
103
+
104
+ // Act
105
+ left . AddFirstFrom ( right , reversed ) ;
106
+
107
+ // Assert
108
+ left . Count . Should ( ) . Be ( expected . Count ) ;
109
+ if ( isMutated )
110
+ left . Version . Should ( ) . NotBe ( version ) ;
111
+ else
112
+ left . Version . Should ( ) . Be ( version ) ;
113
+ left . EnumerateForward ( ) . Should ( ) . Equal ( expected ) ;
114
+ left . EnumerateReversed ( ) . Should ( ) . Equal ( expected . Reverse ( ) ) ;
115
+ right . Count . Should ( ) . Be ( 0 ) ;
116
+ }
71
117
}
72
118
}
0 commit comments