public static void TestResize() { // Initialize a resizable queue PriorityQueue <int?> pq = new IntegerQueue(); pq.Add(3); pq.Add(-2); pq.Add(1); pq.Add(-10); Assert.AreEqual(pq.Size(), 4); pq.Add(7); pq.Add(5); pq.Add(10); pq.Add(1); Assert.AreEqual(pq.Size(), 8); pq.Add(10); pq.Add(1); pq.Add(5); Assert.AreEqual(pq.Size(), 11); pq.Add(12); pq.Add(13); pq.Add(14); pq.Add(15); pq.Add(16); Assert.AreEqual(pq.Size(), 16); pq.Add(-17); pq.Add(-18); Assert.AreEqual(pq.Size(), 18); }
public virtual void TestClear() { PriorityQueue <int?> pq = new IntegerQueue(3); pq.Add(2); pq.Add(3); pq.Add(1); Assert.AreEqual(3, pq.Size()); pq.Clear(); Assert.AreEqual(0, pq.Size()); }
public virtual void TestClear() { PriorityQueue pq = new IntegerQueue(3); pq.Put((System.Object) 2); pq.Put((System.Object) 3); pq.Put((System.Object) 1); Assert.AreEqual(3, pq.Size()); pq.Clear(); Assert.AreEqual(0, pq.Size()); }
public virtual void TestInsertWithOverflow() { // Tests that InsertWithOverflow discards the correct value, // and the resulting PQ preserves its structure int size = 4; PriorityQueue <int?> pq = new IntegerQueue(size); int?i1 = 2; int?i2 = 3; int?i3 = 1; int?i4 = 5; int?i5 = 7; int?i6 = 1; Assert.IsNull(pq.InsertWithOverflow(i1)); Assert.IsNull(pq.InsertWithOverflow(i2)); Assert.IsNull(pq.InsertWithOverflow(i3)); Assert.IsNull(pq.InsertWithOverflow(i4)); Assert.IsTrue(pq.InsertWithOverflow(i5) == i3); // i3 should have been dropped Assert.IsTrue(pq.InsertWithOverflow(i6) == i6); // i6 should not have been inserted Assert.AreEqual(size, pq.Size()); Assert.AreEqual((int?)2, pq.Top()); // LUCENENET SPECIFIC pq.Pop(); Assert.AreEqual((int?)3, pq.Top()); pq.Pop(); Assert.AreEqual((int?)5, pq.Top()); pq.Pop(); Assert.AreEqual((int?)7, pq.Top()); }
public static void TestDuplicates() { // Tests that the queue doesn't absorb elements with duplicate keys int maxSize = 10; PriorityQueue <int?> pq = new IntegerQueue(maxSize); pq.Add(3); pq.Add(3); Assert.AreEqual(pq.Size(), 2); pq.Add(3); Assert.AreEqual(pq.Size(), 3); pq.Add(17); pq.Add(17); pq.Add(17); pq.Add(17); Assert.AreEqual(pq.Size(), 7); }
public void TestFixedSize() { PriorityQueue <int?> pq = new IntegerQueue(3); pq.InsertWithOverflow(2); pq.InsertWithOverflow(3); pq.InsertWithOverflow(1); pq.InsertWithOverflow(5); pq.InsertWithOverflow(7); pq.InsertWithOverflow(1); assertEquals(3, pq.Size()); assertEquals((int?)3, pq.Top()); }
public virtual void TestFixedSize() { PriorityQueue pq = new IntegerQueue(3); pq.Insert((System.Object) 2); pq.Insert((System.Object) 3); pq.Insert((System.Object) 1); pq.Insert((System.Object) 5); pq.Insert((System.Object) 7); pq.Insert((System.Object) 1); Assert.AreEqual(3, pq.Size()); Assert.AreEqual(3, ((System.Int32)pq.Top())); }
public virtual void TestFixedSize() { PriorityQueue <int?> pq = new IntegerQueue(3); pq.InsertWithOverflow(2); pq.InsertWithOverflow(3); pq.InsertWithOverflow(1); pq.InsertWithOverflow(5); pq.InsertWithOverflow(7); pq.InsertWithOverflow(1); Assert.AreEqual(3, pq.Size()); Assert.AreEqual(3, pq.Top()); }
public static void TestPrepopulation() { int maxSize = 10; // Populates the internal array PriorityQueue <int?> pq = new IntegerQueueWithSentinel(maxSize, true); Assert.AreEqual(pq.Top(), int.MaxValue); Assert.AreEqual(pq.Size(), 10); // Does not populate it pq = new IntegerQueue(maxSize, false); Assert.AreEqual(pq.Top(), default(int?)); Assert.AreEqual(pq.Size(), 0); }
public virtual void TestInsertWithOverflowDoesNotOverflow() { // Tests that InsertWithOverflow does not cause overflow PriorityQueue <int?> pq = new IntegerQueue(3); pq.InsertWithOverflow(2); pq.InsertWithOverflow(3); pq.InsertWithOverflow(1); pq.InsertWithOverflow(5); pq.InsertWithOverflow(7); pq.InsertWithOverflow(1); Assert.AreEqual(3, pq.Size()); Assert.AreEqual((int?)3, pq.Top()); }
public static void TestPop() { int maxSize = 10; PriorityQueue <int?> pq = new IntegerQueue(maxSize); // Add one element and pop it pq.Add(7); pq.Pop(); Assert.AreEqual(pq.Size(), 0); // Add a bunch of elements, pop them all pq.Add(1); pq.Add(20); pq.Add(1); pq.Add(15); pq.Add(4); pq.Add(12); pq.Add(1000); pq.Add(-3); pq.Pop(); Assert.AreEqual(pq.Size(), 7); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); Assert.AreEqual(pq.Size(), 0); // Interleaved adds and pops pq.Add(1); pq.Add(20); pq.Pop(); Assert.AreEqual(pq.Size(), 1); pq.Add(1); pq.Add(15); pq.Add(4); pq.Pop(); pq.Pop(); Assert.AreEqual(pq.Size(), 2); pq.Add(12); pq.Add(1000); pq.Add(-3); pq.Pop(); pq.Pop(); Assert.AreEqual(pq.Size(), 3); // Pop an empty PQ pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); pq.Pop(); }
public virtual void TestInsertWithOverflow() { int size = 4; PriorityQueue <int?> pq = new IntegerQueue(size); int?i1 = 2; int?i2 = 3; int?i3 = 1; int?i4 = 5; int?i5 = 7; int?i6 = 1; Assert.IsNull(pq.InsertWithOverflow(i1)); Assert.IsNull(pq.InsertWithOverflow(i2)); Assert.IsNull(pq.InsertWithOverflow(i3)); Assert.IsNull(pq.InsertWithOverflow(i4)); Assert.IsTrue(pq.InsertWithOverflow(i5) == i3); // i3 should have been dropped Assert.IsTrue(pq.InsertWithOverflow(i6) == i6); // i6 should not have been inserted Assert.AreEqual(size, pq.Size()); Assert.AreEqual((int?)2, pq.Top()); }
public virtual void TestInsertWithOverflow() { int size = 4; PriorityQueue pq = new IntegerQueue(size); System.Int32 i1 = 2; System.Int32 i2 = 3; System.Int32 i3 = 1; System.Int32 i4 = 5; System.Int32 i5 = 7; System.Int32 i6 = 1; Assert.IsNull(pq.InsertWithOverflow(i1)); Assert.IsNull(pq.InsertWithOverflow(i2)); Assert.IsNull(pq.InsertWithOverflow(i3)); Assert.IsNull(pq.InsertWithOverflow(i4)); Assert.IsTrue((int)pq.InsertWithOverflow(i5) == i3); // i3 should have been dropped Assert.IsTrue((int)pq.InsertWithOverflow(i6) == i6); // i6 should not have been inserted Assert.AreEqual(size, pq.Size()); Assert.AreEqual(2, ((System.Int32)pq.Top())); }
public static void TestStress() { int atLeast = 1000000; int maxSize = AtLeast(atLeast); PriorityQueue <int?> pq = new IntegerQueue(maxSize); // Add a lot of elements for (int i = 0; i < maxSize; i++) { pq.Add(Random().Next()); } // Pop some of them while (pq.Size() > atLeast / 2) { pq.Pop(); } // Add some more while (pq.Size() < (atLeast * 3) / 4) { pq.Add(Random().Next()); } PopAndTestElements(pq); Assert.AreEqual(pq.Size(), 0); // We fill it again for (int i = 0; 2 * i < maxSize; i++) { pq.Add(Random().Next()); } Assert.AreEqual(pq.Size(), (maxSize + 1) / 2); pq.Clear(); Assert.AreEqual(pq.Size(), 0); // One last time for (int i = 0; 2 * i < maxSize; i++) { pq.Add(Random().Next()); } PopAndTestElements(pq); Assert.AreEqual(pq.Size(), 0); }
public virtual void TestInsertWithOverflow() { int size = 4; PriorityQueue pq = new IntegerQueue(size); System.Int32 i1 = 2; System.Int32 i2 = 3; System.Int32 i3 = 1; System.Int32 i4 = 5; System.Int32 i5 = 7; System.Int32 i6 = 1; Assert.IsNull(pq.InsertWithOverflow((System.Object) i1)); Assert.IsNull(pq.InsertWithOverflow((System.Object) i2)); Assert.IsNull(pq.InsertWithOverflow((System.Object) i3)); Assert.IsNull(pq.InsertWithOverflow((System.Object) i4)); Assert.IsTrue((int)pq.InsertWithOverflow((System.Object)i5) == i3); // i3 should have been dropped Assert.IsTrue((int)pq.InsertWithOverflow((System.Object)i6) == i6); // i6 should not have been inserted Assert.AreEqual(size, pq.Size()); Assert.AreEqual(2, ((System.Int32) pq.Top())); }
public virtual void TestFixedSize() { PriorityQueue pq = new IntegerQueue(3); pq.Insert((System.Object) 2); pq.Insert((System.Object) 3); pq.Insert((System.Object) 1); pq.Insert((System.Object) 5); pq.Insert((System.Object) 7); pq.Insert((System.Object) 1); Assert.AreEqual(3, pq.Size()); Assert.AreEqual(3, ((System.Int32) pq.Top())); }