@@ -34,6 +34,51 @@ public void TestWindowIsLazy()
34
34
new BreakingSequence < int > ( ) . Window ( 1 ) ;
35
35
}
36
36
37
+ [ Test ]
38
+ public void WindowModifiedBeforeMoveNextDoesNotAffectNextWindow ( )
39
+ {
40
+ var sequence = Enumerable . Range ( 0 , 3 ) ;
41
+ using var e = sequence . Window ( 2 ) . GetEnumerator ( ) ;
42
+
43
+ e . MoveNext ( ) ;
44
+ var window1 = e . Current ;
45
+ window1 [ 1 ] = - 1 ;
46
+ e . MoveNext ( ) ;
47
+ var window2 = e . Current ;
48
+
49
+ Assert . That ( window2 [ 0 ] , Is . EqualTo ( 1 ) ) ;
50
+ }
51
+
52
+ [ Test ]
53
+ public void WindowModifiedAfterMoveNextDoesNotAffectNextWindow ( )
54
+ {
55
+ var sequence = Enumerable . Range ( 0 , 3 ) ;
56
+ using var e = sequence . Window ( 2 ) . GetEnumerator ( ) ;
57
+
58
+ e . MoveNext ( ) ;
59
+ var window1 = e . Current ;
60
+ e . MoveNext ( ) ;
61
+ window1 [ 1 ] = - 1 ;
62
+ var window2 = e . Current ;
63
+
64
+ Assert . That ( window2 [ 0 ] , Is . EqualTo ( 1 ) ) ;
65
+ }
66
+
67
+ [ Test ]
68
+ public void WindowModifiedDoesNotAffectPreviousWindow ( )
69
+ {
70
+ var sequence = Enumerable . Range ( 0 , 3 ) ;
71
+ using var e = sequence . Window ( 2 ) . GetEnumerator ( ) ;
72
+
73
+ e . MoveNext ( ) ;
74
+ var window1 = e . Current ;
75
+ e . MoveNext ( ) ;
76
+ var window2 = e . Current ;
77
+ window2 [ 0 ] = - 1 ;
78
+
79
+ Assert . That ( window1 [ 1 ] , Is . EqualTo ( 1 ) ) ;
80
+ }
81
+
37
82
/// <summary>
38
83
/// Verify that a negative window size results in an exception
39
84
/// </summary>
@@ -42,7 +87,7 @@ public void TestWindowNegativeWindowSizeException()
42
87
{
43
88
var sequence = Enumerable . Repeat ( 1 , 10 ) ;
44
89
45
- AssertThrowsArgument . OutOfRangeException ( "size" , ( ) =>
90
+ AssertThrowsArgument . OutOfRangeException ( "size" , ( ) =>
46
91
sequence . Window ( - 5 ) ) ;
47
92
}
48
93
0 commit comments