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
This commit is contained in:
Markus Ewald 2008-11-27 18:56:08 +00:00
parent cb0355193d
commit c43bfd47c8
11 changed files with 663 additions and 18 deletions

View file

@ -31,6 +31,8 @@ namespace Nuclex.Support.Collections {
[TestFixture]
public class PriorityQueueTest {
#region class FloatComparer
/// <summary>Comparer for two floating point values</summary>
private class FloatComparer : IComparer<float> {
@ -47,6 +49,8 @@ namespace Nuclex.Support.Collections {
}
#endregion // class FloatComparer
/// <summary>Tests to ensure the count property is properly updated</summary>
[Test]
public void TestCount() {
@ -91,6 +95,56 @@ namespace Nuclex.Support.Collections {
Assert.AreEqual(1.0f, testQueue.Dequeue());
}
#if DEBUG
/// <summary>
/// Tests whether the priority queue's enumerators are invalidated when the queue's
/// contents are modified
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
public void TestEnumeratorInvalidationOnModify() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
IEnumerator<int> testQueueEnumerator = testQueue.GetEnumerator();
testQueue.Enqueue(123);
testQueueEnumerator.MoveNext();
}
#endif
/// <summary>
/// Verifies that an exception is thrown when Peek() is called on an empty queue
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
public void TestPeekEmptyQueue() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
testQueue.Peek();
}
/// <summary>
/// Verifies that an exception is thrown when Dequeue() is called on an empty queue
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
public void TestDequeueEmptyQueue() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
testQueue.Dequeue();
}
/// <summary>
/// Verifies that the priority queue can handle large amounts of data
/// </summary>
[Test]
public void TestLargeQueue() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
List<int> testList = new List<int>();
for(int index = 0; index < 1000; ++index) {
testQueue.Enqueue(index * 2);
testList.Add(index * 2);
}
CollectionAssert.AreEquivalent(testList, testQueue);
}
}
} // namespace Nuclex.Support.Collections