File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,17 @@ public void Push_MoreThanCapacity_False()
3434
3535 Assert . False ( buffer . Push ( 101 ) ) ;
3636
37+ // Check that one random element of the queue was replaced
3738 var vals = buffer . Pop ( ) ;
39+ var replaced = 0 ;
3840 for ( int i = 0 ; i < 100 ; i ++ )
3941 {
40- Assert . Equal ( i , vals [ i ] ) ;
42+ if ( vals [ i ] != i )
43+ {
44+ replaced ++ ;
45+ }
4146 }
47+ Assert . Equal ( 1 , replaced ) ;
4248 }
4349
4450 }
Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ internal class AgentWriterBuffer<T>
88 private readonly Object _lock = new Object ( ) ;
99 private readonly int _maxSize ;
1010 private List < T > _items ;
11+ private Random _random ;
1112
1213 public AgentWriterBuffer ( int maxSize )
1314 {
1415 _maxSize = maxSize ;
1516 _items = new List < T > ( ) ;
17+ _random = new Random ( ) ;
1618 }
1719
1820 public bool Push ( T item )
@@ -24,7 +26,11 @@ public bool Push(T item)
2426 _items . Add ( item ) ;
2527 return true ;
2628 }
27- return false ;
29+ else
30+ {
31+ _items [ _random . Next ( _items . Count ) ] = item ;
32+ return false ;
33+ }
2834 }
2935 }
3036
You can’t perform that action at this time.
0 commit comments