@@ -207,14 +207,52 @@ func TestSurface_SetSurface(t *testing.T) {
207207}
208208
209209func TestSurface_LinesIterator (t * testing.T ) {
210- // temporary test
211- surface := pi .NewSurface [int ](2 , 2 )
212- for range surface .LinesIterator (pi.IntArea {W : 2 , H : 2 }) {
213- }
210+ surface := pi .NewSurface [rune ](4 , 3 )
211+ surface .SetAll (
212+ 'a' , 'b' , 'c' , 'd' ,
213+ 'e' , 'f' , 'g' , 'h' ,
214+ 'i' , 'j' , 'k' , 'l' ,
215+ )
216+
217+ t .Run ("iterate over area" , func (t * testing.T ) {
218+ area := pi.IntArea {X : 1 , Y : 1 , W : 2 , H : 2 }
219+ expectedPos := []pi.Position {
220+ {1 , 1 },
221+ {1 , 2 },
222+ }
223+ expectedLines := [][]rune {
224+ {'f' , 'g' },
225+ {'j' , 'k' },
226+ }
227+
228+ var i int
229+ for pos , line := range surface .LinesIterator (area ) {
230+ require .Less (t , i , len (expectedPos ))
231+ assert .Equal (t , expectedPos [i ], pos )
232+ assert .Equal (t , expectedLines [i ], line )
233+ i ++
234+ }
235+ assert .Equal (t , len (expectedPos ), i )
236+ })
237+
238+ t .Run ("modifies underlying data" , func (t * testing.T ) {
239+ area := pi.IntArea {X : 1 , Y : 1 , W : 2 , H : 1 }
240+ for _ , line := range surface .LinesIterator (area ) {
241+ line [0 ] = 'z'
242+ }
243+ assert .Equal (t , 'z' , surface .Get (1 , 1 ))
244+ })
245+
246+ t .Run ("panic on area outside surface" , func (t * testing.T ) {
247+ area := pi.IntArea {X : - 1 , Y : 0 , W : 2 , H : 1 }
248+ require .Panics (t , func () {
249+ for range surface .LinesIterator (area ) {
250+ }
251+ })
252+ })
214253}
215254
216255func BenchmarkSurface_LinesIterator (b * testing.B ) {
217- // temporary test
218256 surface := pi .NewSurface [int ](2 , 2 )
219257 area := pi.IntArea {W : 2 , H : 2 }
220258 b .ResetTimer ()
0 commit comments