示例#1
0
        public void Compound__Random_Ops__VerifiesReturnTrue()
        {
            var heap = THeap< CTrackingElement >.Create( CTrackingElement.Compare_Elements );
            var elements = new List< CTrackingElement >();

            for ( int i = 0; i < 10; i++ )
            {
                Random rng = new Random( i );

                for ( int j = 0; j < 50; j++ )
                {
                    CTrackingElement element = new CTrackingElement( rng.Next() % 10000 );
                    elements.Add( element );
                    heap.Add( element );

                    Assert.IsTrue( heap.Verify_Index_Tracking() );
                    Assert.IsTrue( heap.Verify_Heap() );
                }

                for ( int j = 0; j < 20; j++ )
                {
                    int random_op = rng.Next() % 3;
                    switch ( random_op )
                    {
                        case 0:
                            heap.Pop();
                            break;

                        case 1:
                            int remove_index = rng.Next() % elements.Count;
                            heap.Remove( elements[ remove_index ] );
                            break;
                    }

                    Assert.IsTrue( heap.Verify_Index_Tracking() );
                    Assert.IsTrue( heap.Verify_Heap() );
                }
            }
        }
示例#2
0
        public void Remove__Sequence__VerifyIndexTrue()
        {
            var heap = THeap< CTrackingElement >.Create( CTrackingElement.Compare_Elements );
            List< CTrackingElement > elements = new List< CTrackingElement >();

            for ( int i = 100; i > 0; i-- )
            {
                CTrackingElement element = new CTrackingElement( i );
                elements.Add( element );
                heap.Add( element );
            }

            for ( int i = 0; i < elements.Count; i++ )
            {
                heap.Remove( elements[ i ] );
                Assert.IsTrue( heap.Verify_Index_Tracking() );
            }
        }
示例#3
0
 public static int Compare_Elements( CTrackingElement element1, CTrackingElement element2 )
 {
     return element1.Value.CompareTo( element2.Value );
 }
示例#4
0
        public void Remove__InvalidElement2__ThrowsCorruptedHeapRemoveException()
        {
            var heap = THeap< CTrackingElement >.Create( CTrackingElement.Compare_Elements );

            heap.Add( new CTrackingElement( 1 ) );
            heap.Add( new CTrackingElement( 2 ) );

            CTrackingElement element = new CTrackingElement( 5 );
            element.Set_Heap_Index( 1 );

            heap.Remove( element );
        }