File tree Expand file tree Collapse file tree
Bearded.Utilities.Tests/Collections Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Linq ;
44using Bearded . Utilities . Collections ;
5+ using Bearded . Utilities . Linq ;
6+ using FluentAssertions ;
7+ using FsCheck . Xunit ;
58using Xunit ;
69
710namespace Bearded . Utilities . Tests . Collections
@@ -74,5 +77,35 @@ public void TestIncreasePriority()
7477 q . Enqueue ( 2 , "item" ) ;
7578 Assert . Throws < InvalidOperationException > ( ( ) => q . DecreasePriority ( "item" , 4 ) ) ;
7679 }
80+
81+ [ Property ]
82+ public void TestEnumerationContainsCorrectItems ( int seed , byte itemsToEnumerate , byte otherItems )
83+ {
84+ var random = new System . Random ( seed ) ;
85+ var totalItems = itemsToEnumerate + otherItems ;
86+ var q = new PriorityQueue < double , int > ( ) ;
87+ var items = Enumerable
88+ . Range ( 0 , totalItems )
89+ . Select ( i => KeyValuePair . Create ( random . NextDouble ( ) , i ) )
90+ . Shuffled ( ) ;
91+ foreach ( var ( priority , value ) in items )
92+ {
93+ q . Enqueue ( priority , value ) ;
94+ }
95+ for ( var i = 0 ; i < otherItems ; i ++ )
96+ {
97+ q . Dequeue ( ) ;
98+ }
99+
100+ // ReSharper disable once RedundantCast to make sure we're not using a ToList() that we may add to the queue
101+ var enumerated = ( ( IEnumerable < KeyValuePair < double , int > > ) q ) . ToList ( ) ;
102+
103+ enumerated . Should ( ) . HaveCount ( itemsToEnumerate ) . And . BeSubsetOf ( items ) ;
104+ while ( q . Count > 0 )
105+ {
106+ var dequeued = q . Dequeue ( ) ;
107+ enumerated . Should ( ) . Contain ( dequeued ) ;
108+ }
109+ }
77110 }
78- }
111+ }
You can’t perform that action at this time.
0 commit comments