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 TestIntegrityAfterResize() { // Tests that after a resize, the queue keeps working fine PriorityQueue <int?> pq = new IntegerQueue(); pq.Add(3); pq.Add(-2); pq.Add(1); pq.Add(7); pq.Add(5); pq.Add(10); pq.Add(1); pq.Add(-10); pq.Add(-100); Assert.AreEqual(pq.Top(), -100); pq.Add(-1000); Assert.AreEqual(pq.Top(), -1000); pq.Pop(); pq.Pop(); pq.Pop(); Assert.AreEqual(pq.Top(), -2); pq.Add(0); Assert.AreEqual(pq.Top(), -2); for (int i = 0; i < 100; i++) { pq.Add(5); } Assert.AreEqual(pq.Top(), -2); }
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 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 <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 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 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 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())); }