From c43bfd47c8329b8cec05921db99f73f1defd7255 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Thu, 27 Nov 2008 18:56:08 +0000 Subject: [PATCH] Increased test coverage for all collection classes up to the priority queue to 100%; SetParent() is no longer 'protected internal' as internal is sufficient in this case (.NET 'protected internal' is less restrictive than 'protected' or 'internal' alone); parenting collection now unsets parent for items that are being replaced; priority queue version check for enumerators (to protected against modification of the collection) now only happens in debug mode git-svn-id: file:///srv/devel/repo-conversion/nusu@94 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support.csproj | 12 ++ Source/Collections/ItemEventArgs.Test.cs | 57 ++++++ .../Collections/ObservableCollection.Test.cs | 43 ++++ Source/Collections/PairPriorityQueue.Test.cs | 75 ++++++- Source/Collections/Parentable.Test.cs | 102 ++++++++++ Source/Collections/Parentable.cs | 2 +- .../Collections/ParentingCollection.Test.cs | 191 ++++++++++++++++++ Source/Collections/ParentingCollection.cs | 1 + Source/Collections/PriorityItemPair.Test.cs | 101 +++++++++ Source/Collections/PriorityQueue.Test.cs | 54 +++++ Source/Collections/PriorityQueue.cs | 43 ++-- 11 files changed, 663 insertions(+), 18 deletions(-) create mode 100644 Source/Collections/ItemEventArgs.Test.cs create mode 100644 Source/Collections/Parentable.Test.cs create mode 100644 Source/Collections/ParentingCollection.Test.cs create mode 100644 Source/Collections/PriorityItemPair.Test.cs diff --git a/Nuclex.Support.csproj b/Nuclex.Support.csproj index dbaaf46..7df9c25 100644 --- a/Nuclex.Support.csproj +++ b/Nuclex.Support.csproj @@ -48,6 +48,9 @@ + + ItemEventArgs.cs + ObservableCollection.cs @@ -57,8 +60,17 @@ PairPriorityQueue.cs + + Parentable.cs + + + ParentingCollection.cs + + + PriorityItemPair.cs + PriorityQueue.cs diff --git a/Source/Collections/ItemEventArgs.Test.cs b/Source/Collections/ItemEventArgs.Test.cs new file mode 100644 index 0000000..8c209bb --- /dev/null +++ b/Source/Collections/ItemEventArgs.Test.cs @@ -0,0 +1,57 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2008 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + +using System; +using System.Collections.Generic; + +#if UNITTEST + +using NUnit.Framework; +using NMock2; + +namespace Nuclex.Support.Collections { + + /// Unit Test for the item event argument container + [TestFixture] + public class ItemEventArgsTest { + + /// + /// Tests whether an integer argument can be stored in the argument container + /// + [Test] + public void TestIntegerArgument() { + ItemEventArgs test = new ItemEventArgs(12345); + Assert.AreEqual(12345, test.Item); + } + + /// + /// Tests whether a string argument can be stored in the argument container + /// + [Test] + public void TestStringArgument() { + ItemEventArgs test = new ItemEventArgs("hello world"); + Assert.AreEqual("hello world", test.Item); + } + + } + +} // namespace Nuclex.Support.Collections + +#endif // UNITTEST diff --git a/Source/Collections/ObservableCollection.Test.cs b/Source/Collections/ObservableCollection.Test.cs index 17ca953..b55903d 100644 --- a/Source/Collections/ObservableCollection.Test.cs +++ b/Source/Collections/ObservableCollection.Test.cs @@ -118,6 +118,49 @@ namespace Nuclex.Support.Collections { this.mockery.VerifyAllExpectationsHaveBeenMet(); } + /// Tests whether items in the collection can be replaced + [Test] + public void TestItemReplacement() { + Expect.Exactly(3).On(this.mockedSubscriber). + Method("ItemAdded"). + WithAnyArguments(); + + this.observedCollection.Add(1); + this.observedCollection.Add(2); + this.observedCollection.Add(3); + + Expect.Once.On(this.mockedSubscriber). + Method("ItemRemoved"). + WithAnyArguments(); + + Expect.Once.On(this.mockedSubscriber). + Method("ItemAdded"). + WithAnyArguments(); + + // Replace the middle item with something else + this.observedCollection[1] = 4; + + Assert.AreEqual( + 1, + this.observedCollection.IndexOf(4) + ); + + this.mockery.VerifyAllExpectationsHaveBeenMet(); + } + + /// Tests whether the ItemRemoved event is fired + [Test] + public void TestListConstructor() { + int[] integers = new int[] { 12, 34, 56, 78 }; + + ObservableCollection testCollection = new ObservableCollection(integers); + + CollectionAssert.AreEqual( + integers, + testCollection + ); + } + /// Mock object factory private Mockery mockery; /// The mocked observable collection subscriber diff --git a/Source/Collections/PairPriorityQueue.Test.cs b/Source/Collections/PairPriorityQueue.Test.cs index 69c5d4d..a416676 100644 --- a/Source/Collections/PairPriorityQueue.Test.cs +++ b/Source/Collections/PairPriorityQueue.Test.cs @@ -34,8 +34,7 @@ namespace Nuclex.Support.Collections { /// Tests to ensure the count property is properly updated [Test] public void TestCount() { - PairPriorityQueue testQueue = - new PairPriorityQueue(); + PairPriorityQueue testQueue = new PairPriorityQueue(); Assert.AreEqual(0, testQueue.Count); testQueue.Enqueue(12.34f, "a"); @@ -53,8 +52,7 @@ namespace Nuclex.Support.Collections { /// Tests to ensure that the priority collection actually sorts items [Test] public void TestOrdering() { - PairPriorityQueue testQueue = - new PairPriorityQueue(); + PairPriorityQueue testQueue = new PairPriorityQueue(); testQueue.Enqueue(1.0f, "a"); testQueue.Enqueue(9.0f, "i"); @@ -77,6 +75,75 @@ namespace Nuclex.Support.Collections { Assert.AreEqual("a", testQueue.Dequeue().Item); } + /// Tests to ensure that the priority collection's Peek() method works + [Test] + public void TestPeek() { + PairPriorityQueue testQueue = new PairPriorityQueue(); + + testQueue.Enqueue(1.0f, "a"); + testQueue.Enqueue(2.0f, "b"); + testQueue.Enqueue(0.0f, "c"); + + Assert.AreEqual("b", testQueue.Peek().Item); + } + + /// Tests whether the priority collection can copy itself into an array + [Test] + public void TestCopyTo() { + PairPriorityQueue testQueue = new PairPriorityQueue(); + + testQueue.Enqueue(1.0f, "a"); + testQueue.Enqueue(9.0f, "i"); + testQueue.Enqueue(2.0f, "b"); + testQueue.Enqueue(8.0f, "h"); + testQueue.Enqueue(3.0f, "c"); + testQueue.Enqueue(7.0f, "g"); + testQueue.Enqueue(4.0f, "d"); + testQueue.Enqueue(6.0f, "f"); + testQueue.Enqueue(5.0f, "e"); + + PriorityItemPair[] itemArray = new PriorityItemPair[9]; + testQueue.CopyTo(itemArray, 0); + + CollectionAssert.AreEquivalent(testQueue, itemArray); + } + + /// + /// Tests whether the priority collection provides a synchronization root + /// + [Test] + public void TestSyncRoot() { + PairPriorityQueue testQueue = new PairPriorityQueue(); + + // If IsSynchronized returns true, SyncRoot is allowed to be null + if(!testQueue.IsSynchronized) { + lock(testQueue.SyncRoot) { + testQueue.Clear(); + } + } + } + + /// + /// Tests whether the priority collection provides a working type-safe enumerator + /// + [Test] + public void TestEnumerator() { + PairPriorityQueue testQueue = new PairPriorityQueue(); + + testQueue.Enqueue(1.0f, "a"); + testQueue.Enqueue(2.0f, "b"); + testQueue.Enqueue(0.0f, "c"); + + List> testList = + new List>(); + + foreach(PriorityItemPair entry in testQueue) { + testList.Add(entry); + } + + CollectionAssert.AreEquivalent(testQueue, testList); + } + } } // namespace Nuclex.Support.Collections diff --git a/Source/Collections/Parentable.Test.cs b/Source/Collections/Parentable.Test.cs new file mode 100644 index 0000000..0d63910 --- /dev/null +++ b/Source/Collections/Parentable.Test.cs @@ -0,0 +1,102 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2008 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + +using System; +using System.Collections.Generic; + +#if UNITTEST + +using NUnit.Framework; +using NMock2; + +namespace Nuclex.Support.Collections { + + /// Unit Test for the Parentable class + [TestFixture] + public class ParentableTest { + + #region class TestParentable + + /// Parentable object that can be the child of an int + private class TestParentable : Parentable { + + /// Initializes a new instance of the parentable test class + public TestParentable() { } + + /// The parent object that owns this instance + public int GetParent() { + return base.Parent; + } + + /// Invoked whenever the instance's owner changes + /// + /// When items are parented for the first time, the oldParent argument will + /// be null. Also, if the element is removed from the collection, the + /// current parent will be null. + /// + /// Previous owner of the instance + protected override void OnParentChanged(int oldParent) { + this.parentChangedCalled = true; + + base.OnParentChanged(oldParent); // to satisfy NCover :-/ + } + + /// Whether the OnParentChanged method has been called + public bool ParentChangedCalled { + get { return this.parentChangedCalled; } + } + + /// Whether the OnParentChanged method has been called + private bool parentChangedCalled; + + } + + #endregion // class TestParentable + + /// + /// Tests whether a parent can be assigned and then retrieved from + /// the parentable object + /// + [Test] + public void TestParentAssignment() { + TestParentable testParentable = new TestParentable(); + + testParentable.SetParent(12345); + Assert.AreEqual(12345, testParentable.GetParent()); + } + + /// + /// Tests whether a parent can be assigned and then retrieved from + /// the parentable object + /// + [Test] + public void TestParentChangedNotification() { + TestParentable testParentable = new TestParentable(); + + testParentable.SetParent(12345); + + Assert.IsTrue(testParentable.ParentChangedCalled); + } + + } + +} // namespace Nuclex.Support.Collections + +#endif // UNITTEST diff --git a/Source/Collections/Parentable.cs b/Source/Collections/Parentable.cs index ecee738..62fd91a 100644 --- a/Source/Collections/Parentable.cs +++ b/Source/Collections/Parentable.cs @@ -42,7 +42,7 @@ namespace Nuclex.Support.Collections { protected virtual void OnParentChanged(ParentType oldParent) { } /// Assigns a new parent to this instance - protected internal void SetParent(ParentType parent) { + internal void SetParent(ParentType parent) { ParentType oldParent = this.parent; this.parent = parent; diff --git a/Source/Collections/ParentingCollection.Test.cs b/Source/Collections/ParentingCollection.Test.cs new file mode 100644 index 0000000..eee0f97 --- /dev/null +++ b/Source/Collections/ParentingCollection.Test.cs @@ -0,0 +1,191 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2008 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + +using System; +using System.Collections.Generic; + +#if UNITTEST + +using NUnit.Framework; +using NMock2; + +namespace Nuclex.Support.Collections { + + /// Unit Test for the Parenting Collection class + [TestFixture] + public class ParentingCollectionTest { + + #region class TestParentable + + /// Parentable object that can be the child of an int + private class TestParentable : Parentable, IDisposable { + + /// Initializes a new instance of the parentable test class + public TestParentable() { } + + /// The parent object that owns this instance + public int GetParent() { + return base.Parent; + } + + /// Immediately releases all resources owned by the item + public void Dispose() { + this.disposeCalled = true; + } + + /// Whether Dispose() has been called on this item + public bool DisposeCalled { + get { return this.disposeCalled; } + } + + /// Whether Dispose() has been called on this item + private bool disposeCalled; + + } + + #endregion // class TestParentable + + #region class TestParentingCollection + + /// Parentable object that can be the child of an int + private class TestParentingCollection : ParentingCollection { + + /// Changes the parent of the collection + /// New parent to assign to the collection + public void SetParent(int parent) { + base.Reparent(parent); + } + + /// Disposes all items contained in the collection + public new void DisposeItems() { + base.DisposeItems(); + } + + } + + #endregion // class TestParentingCollection + + /// + /// Tests whether the parenting collection propagates its parent to an item that + /// is added to the collection after the collection's aprent is already assigned + /// + [Test] + public void TestPropagatePreassignedParent() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable = new TestParentable(); + + testCollection.SetParent(54321); + testCollection.Add(testParentable); + + Assert.AreEqual(54321, testParentable.GetParent()); + } + + /// + /// Tests whether the parenting collection propagates a new parent to all items + /// contained in it when its parent is changed + /// + [Test] + public void TestPropagateParentChange() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable = new TestParentable(); + + testCollection.Add(testParentable); + testCollection.SetParent(54321); + + Assert.AreEqual(54321, testParentable.GetParent()); + } + + /// + /// Tests whether the parenting collection propagates its parent to an item that + /// is added to the collection after the collection's aprent is already assigned + /// + [Test] + public void TestPropagateParentOnReplace() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable1 = new TestParentable(); + TestParentable testParentable2 = new TestParentable(); + + testCollection.SetParent(54321); + testCollection.Add(testParentable1); + testCollection[0] = testParentable2; + + Assert.AreEqual(0, testParentable1.GetParent()); + Assert.AreEqual(54321, testParentable2.GetParent()); + } + + /// + /// Tests whether the parenting collection unsets the parent when an item is removed + /// from the collection + /// + [Test] + public void TestUnsetParentOnRemoveItem() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable = new TestParentable(); + + testCollection.Add(testParentable); + testCollection.SetParent(54321); + + Assert.AreEqual(54321, testParentable.GetParent()); + + testCollection.RemoveAt(0); + + Assert.AreEqual(0, testParentable.GetParent()); + } + + /// + /// Tests whether the parenting collection unsets the parent when all item are + /// removed from the collection by clearing it + /// + [Test] + public void TestUnsetParentOnClear() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable = new TestParentable(); + + testCollection.Add(testParentable); + testCollection.SetParent(54321); + + Assert.AreEqual(54321, testParentable.GetParent()); + + testCollection.Clear(); + + Assert.AreEqual(0, testParentable.GetParent()); + } + + /// + /// Tests whether the parenting collection calls Dispose() on all contained items + /// that implement IDisposable when its DisposeItems() method is called + /// + [Test] + public void TestDisposeItems() { + TestParentingCollection testCollection = new TestParentingCollection(); + TestParentable testParentable = new TestParentable(); + + testCollection.Add(testParentable); + + testCollection.DisposeItems(); + + Assert.IsTrue(testParentable.DisposeCalled); + } + + } + +} // namespace Nuclex.Support.Collections + +#endif // UNITTEST diff --git a/Source/Collections/ParentingCollection.cs b/Source/Collections/ParentingCollection.cs index e981fdb..d3b40c8 100644 --- a/Source/Collections/ParentingCollection.cs +++ b/Source/Collections/ParentingCollection.cs @@ -73,6 +73,7 @@ namespace Nuclex.Support.Collections { /// Index of the element that was assigned /// New item protected override void SetItem(int index, ItemType item) { + base[index].SetParent(default(ParentType)); base.SetItem(index, item); item.SetParent(this.parent); } diff --git a/Source/Collections/PriorityItemPair.Test.cs b/Source/Collections/PriorityItemPair.Test.cs new file mode 100644 index 0000000..ce244e9 --- /dev/null +++ b/Source/Collections/PriorityItemPair.Test.cs @@ -0,0 +1,101 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2008 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + +using System; +using System.Collections.Generic; + +#if UNITTEST + +using NUnit.Framework; +using NMock2; + +namespace Nuclex.Support.Collections { + + /// Unit Test for the Priority/Item pair class + [TestFixture] + public class PriorityItemPairTest { + + #region class ToStringNullReturner + + /// Test class in which ToString() can return null + private class ToStringNullReturner { + + /// + /// Returns a System.String that represents the current System.Object + /// + /// A System.String that represents the current System.Object + public override string ToString() { return null; } + + } + + #endregion // class ToStringNullReturner + + /// Tests whether the pair's default constructor works + [Test] + public void TestDefaultConstructor() { + new PriorityItemPair(); + } + + /// Tests whether the priority can be retrieved from the pair + [Test] + public void TestPriorityRetrieval() { + PriorityItemPair testPair = new PriorityItemPair( + 12345, "hello world" + ); + + Assert.AreEqual(12345, testPair.Priority); + } + + /// Tests whether the item can be retrieved from the pair + [Test] + public void TestItemRetrieval() { + PriorityItemPair testPair = new PriorityItemPair( + 12345, "hello world" + ); + + Assert.AreEqual("hello world", testPair.Item); + } + + /// Tests whether the ToString() methods works with valid strings + [Test] + public void TestToStringWithValidStrings() { + PriorityItemPair testPair = new PriorityItemPair( + "hello", "world" + ); + + Assert.AreEqual("[hello, world]", testPair.ToString()); + } + + /// Tests whether the ToString() methods works with null strings + [Test] + public void TestToStringWithNullStrings() { + PriorityItemPair testPair = + new PriorityItemPair( + new ToStringNullReturner(), new ToStringNullReturner() + ); + + Assert.AreEqual("[, ]", testPair.ToString()); + } + + } + +} // namespace Nuclex.Support.Collections + +#endif // UNITTEST diff --git a/Source/Collections/PriorityQueue.Test.cs b/Source/Collections/PriorityQueue.Test.cs index 02374bf..c33dc6e 100644 --- a/Source/Collections/PriorityQueue.Test.cs +++ b/Source/Collections/PriorityQueue.Test.cs @@ -31,6 +31,8 @@ namespace Nuclex.Support.Collections { [TestFixture] public class PriorityQueueTest { + #region class FloatComparer + /// Comparer for two floating point values private class FloatComparer : IComparer { @@ -47,6 +49,8 @@ namespace Nuclex.Support.Collections { } + #endregion // class FloatComparer + /// Tests to ensure the count property is properly updated [Test] public void TestCount() { @@ -91,6 +95,56 @@ namespace Nuclex.Support.Collections { Assert.AreEqual(1.0f, testQueue.Dequeue()); } +#if DEBUG + /// + /// Tests whether the priority queue's enumerators are invalidated when the queue's + /// contents are modified + /// + [Test, ExpectedException(typeof(InvalidOperationException))] + public void TestEnumeratorInvalidationOnModify() { + PriorityQueue testQueue = new PriorityQueue(); + IEnumerator testQueueEnumerator = testQueue.GetEnumerator(); + + testQueue.Enqueue(123); + + testQueueEnumerator.MoveNext(); + } +#endif + + /// + /// Verifies that an exception is thrown when Peek() is called on an empty queue + /// + [Test, ExpectedException(typeof(InvalidOperationException))] + public void TestPeekEmptyQueue() { + PriorityQueue testQueue = new PriorityQueue(); + testQueue.Peek(); + } + + /// + /// Verifies that an exception is thrown when Dequeue() is called on an empty queue + /// + [Test, ExpectedException(typeof(InvalidOperationException))] + public void TestDequeueEmptyQueue() { + PriorityQueue testQueue = new PriorityQueue(); + testQueue.Dequeue(); + } + + /// + /// Verifies that the priority queue can handle large amounts of data + /// + [Test] + public void TestLargeQueue() { + PriorityQueue testQueue = new PriorityQueue(); + List testList = new List(); + + for(int index = 0; index < 1000; ++index) { + testQueue.Enqueue(index * 2); + testList.Add(index * 2); + } + + CollectionAssert.AreEquivalent(testList, testQueue); + } + } } // namespace Nuclex.Support.Collections diff --git a/Source/Collections/PriorityQueue.cs b/Source/Collections/PriorityQueue.cs index 1cb46f0..2cd1f31 100644 --- a/Source/Collections/PriorityQueue.cs +++ b/Source/Collections/PriorityQueue.cs @@ -41,27 +41,32 @@ namespace Nuclex.Support.Collections { /// Resets the enumerator to its initial state public void Reset() { - index = -1; - version = priorityQueue.version; + this.index = -1; +#if DEBUG + this.expectedVersion = priorityQueue.version; +#endif } /// The current item being enumerated ItemType IEnumerator.Current { get { +#if DEBUG checkVersion(); - return priorityQueue.heap[index]; +#endif + return this.priorityQueue.heap[index]; } } /// Moves to the next item in the priority queue /// True if a next item was found, false if the end has been reached public bool MoveNext() { +#if DEBUG checkVersion(); - - if(index + 1 == priorityQueue.count) +#endif + if(this.index + 1 == this.priorityQueue.count) return false; - ++index; + ++this.index; return true; } @@ -69,17 +74,21 @@ namespace Nuclex.Support.Collections { /// Releases all resources used by the enumerator public void Dispose() { } +#if DEBUG /// Ensures that the priority queue has not changed private void checkVersion() { - if(version != priorityQueue.version) + if(this.expectedVersion != this.priorityQueue.version) throw new InvalidOperationException("Priority queue has been modified"); } +#endif /// The current item being enumerated object IEnumerator.Current { get { +#if DEBUG checkVersion(); - return priorityQueue.heap[index]; +#endif + return this.priorityQueue.heap[index]; } } @@ -87,8 +96,10 @@ namespace Nuclex.Support.Collections { private int index; /// The priority queue whose items this instance enumerates private PriorityQueue priorityQueue; +#if DEBUG /// Expected version of the priority queue - private int version; + private int expectedVersion; +#endif } @@ -128,9 +139,9 @@ namespace Nuclex.Support.Collections { ItemType result = this.heap[0]; --this.count; trickleDown(0, this.heap[this.count]); - +#if DEBUG ++this.version; - +#endif return result; } @@ -142,13 +153,17 @@ namespace Nuclex.Support.Collections { ++this.count; bubbleUp(this.count - 1, item); +#if DEBUG ++this.version; +#endif } /// Removes all items from the priority queue public void Clear() { this.count = 0; +#if DEBUG ++this.version; +#endif } @@ -258,10 +273,12 @@ namespace Nuclex.Support.Collections { private int count; /// Available space in the priority queue private int capacity; - /// Incremented whenever the priority queue is modified - private int version; /// Tree containing the items in the priority queue private ItemType[] heap; +#if DEBUG + /// Incremented whenever the priority queue is modified + private int version; +#endif }