1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using ImportedLinq ;
5
+ using ImportedLinqTest . Helpers ;
6
+ using Xunit ;
7
+
8
+ namespace ImportedLinqTest
9
+ {
10
+ public class BufferTest
11
+ {
12
+ [ Fact ]
13
+ public void ThrowArgumentNullException ( )
14
+ {
15
+ Assert . Throws < ArgumentNullException > ( ( ) => default ( IEnumerable < int > ) . Buffer ( 5 ) ) ;
16
+ Assert . Throws < ArgumentNullException > ( ( ) => default ( IEnumerable < int > ) . Buffer ( 5 , 5 ) ) ;
17
+ Assert . Throws < ArgumentNullException > ( ( ) => default ( IEnumerable < int > ) . Buffer ( 5 , 4 ) ) ;
18
+ Assert . Throws < ArgumentNullException > ( ( ) => default ( IEnumerable < int > ) . Buffer ( 5 , 6 ) ) ;
19
+ }
20
+
21
+ [ Fact ]
22
+ public void ThrowArgumentOutOfRangeException ( )
23
+ {
24
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( 0 ) ) ;
25
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( - 1 ) ) ;
26
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( 0 , 4 ) ) ;
27
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( - 1 , 4 ) ) ;
28
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( 4 , 0 ) ) ;
29
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( 4 , - 1 ) ) ;
30
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => new [ ] { 3 , 1 , 4 , 1 , 5 , 9 , 2 } . Buffer ( 0 , 0 ) ) ;
31
+ }
32
+
33
+ [ Fact ]
34
+ public void BufferImpl0 ( )
35
+ {
36
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 10 ) . Buffer ( 3 ) ;
37
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
38
+ {
39
+ new [ ] { 0 , 1 , 2 } ,
40
+ new [ ] { 3 , 4 , 5 } ,
41
+ new [ ] { 6 , 7 , 8 } ,
42
+ new [ ] { 9 }
43
+ } ;
44
+
45
+ Assert . Equal ( expected , actual ) ;
46
+ }
47
+
48
+ [ Fact ]
49
+ public void BufferImpl1 ( )
50
+ {
51
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 9 ) . Buffer ( 3 ) ;
52
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
53
+ {
54
+ new [ ] { 0 , 1 , 2 } ,
55
+ new [ ] { 3 , 4 , 5 } ,
56
+ new [ ] { 6 , 7 , 8 } ,
57
+ } ;
58
+
59
+ Assert . Equal ( expected , actual ) ;
60
+ }
61
+
62
+ [ Fact ]
63
+ public void BufferImpl2 ( )
64
+ {
65
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 10 ) . Buffer ( 3 , 3 ) ;
66
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
67
+ {
68
+ new [ ] { 0 , 1 , 2 } ,
69
+ new [ ] { 3 , 4 , 5 } ,
70
+ new [ ] { 6 , 7 , 8 } ,
71
+ new [ ] { 9 }
72
+ } ;
73
+
74
+ Assert . Equal ( expected , actual ) ;
75
+ }
76
+
77
+ [ Fact ]
78
+ public void BufferImpl3 ( )
79
+ {
80
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 9 ) . Buffer ( 3 , 3 ) ;
81
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
82
+ {
83
+ new [ ] { 0 , 1 , 2 } ,
84
+ new [ ] { 3 , 4 , 5 } ,
85
+ new [ ] { 6 , 7 , 8 } ,
86
+ } ;
87
+
88
+ Assert . Equal ( expected , actual ) ;
89
+ }
90
+
91
+ [ Fact ]
92
+ public void BufferOverlap ( )
93
+ {
94
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 9 ) . Buffer ( 3 , 2 ) ;
95
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
96
+ {
97
+ new [ ] { 0 , 1 , 2 } ,
98
+ new [ ] { 2 , 3 , 4 } ,
99
+ new [ ] { 4 , 5 , 6 } ,
100
+ new [ ] { 6 , 7 , 8 } ,
101
+ new [ ] { 8 } ,
102
+ } ;
103
+
104
+ Assert . Equal ( expected , actual ) ;
105
+ }
106
+
107
+ [ Fact ]
108
+ public void BufferSkip ( )
109
+ {
110
+ IEnumerable < IReadOnlyList < int > > actual = Enumerable . Range ( 0 , 9 ) . Buffer ( 3 , 4 ) ;
111
+ IEnumerable < IReadOnlyList < int > > expected = new [ ]
112
+ {
113
+ new [ ] { 0 , 1 , 2 } ,
114
+ new [ ] { 4 , 5 , 6 } ,
115
+ new [ ] { 8 } ,
116
+ } ;
117
+
118
+ Assert . Equal ( expected , actual ) ;
119
+ }
120
+
121
+
122
+ [ Fact ]
123
+ public void NotThrowExceptionImpl ( )
124
+ {
125
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 ) . Take ( 2 ) ;
126
+
127
+ foreach ( IReadOnlyList < int > e in actual )
128
+ {
129
+ }
130
+ }
131
+
132
+ [ Fact ]
133
+ public void NotThrowExceptionSkip ( )
134
+ {
135
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 , 1 )
136
+ . Take ( 4 ) ;
137
+
138
+ foreach ( IReadOnlyList < int > e in actual )
139
+ {
140
+ }
141
+ }
142
+
143
+ [ Fact ]
144
+ public void NotThrowExceptionOverlap ( )
145
+ {
146
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 , 3 )
147
+ . Take ( 1 ) ;
148
+
149
+ foreach ( IReadOnlyList < int > e in actual )
150
+ {
151
+ }
152
+ }
153
+
154
+ [ Fact ]
155
+ public void ThrowExceptionImpl ( )
156
+ {
157
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 ) ;
158
+
159
+ Assert . Throws < Exception > ( ( ) =>
160
+ {
161
+ foreach ( IReadOnlyList < int > e in actual )
162
+ {
163
+ }
164
+ } ) ;
165
+ }
166
+
167
+ [ Fact ]
168
+ public void ThrowExceptionSkip ( )
169
+ {
170
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 , 1 ) ;
171
+
172
+ Assert . Throws < Exception > ( ( ) =>
173
+ {
174
+ foreach ( IReadOnlyList < int > e in actual )
175
+ {
176
+ }
177
+ } ) ;
178
+ }
179
+
180
+ [ Fact ]
181
+ public void ThrowExceptionOverlap ( )
182
+ {
183
+ IEnumerable < IReadOnlyList < int > > actual = new ThrowExceptionEnumerable < int > ( 0 , 1 , 2 , 3 , 4 ) . Buffer ( 2 , 3 ) ;
184
+
185
+ Assert . Throws < Exception > ( ( ) =>
186
+ {
187
+ foreach ( IReadOnlyList < int > e in actual )
188
+ {
189
+ }
190
+ } ) ;
191
+ }
192
+ }
193
+ }
0 commit comments