lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [10/50] [abbrv] lucenenet git commit: Added missing tests to Core.Util.TestPriorityQueue + marked most existing tests with the LuceneNetSpecific attribute.
Date Sun, 23 Oct 2016 13:01:56 GMT
Added missing tests to Core.Util.TestPriorityQueue + marked most existing tests with the LuceneNetSpecific
attribute.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/bff01618
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/bff01618
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/bff01618

Branch: refs/heads/master
Commit: bff016186333e0e1d19ff9b27d0f0b54b5e147ac
Parents: 335c1a8
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Oct 16 06:00:36 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Oct 20 18:20:52 2016 +0700

----------------------------------------------------------------------
 .../core/Util/TestPriorityQueue.cs              | 178 +++++++++++++------
 1 file changed, 120 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bff01618/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs b/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
index ed059c9..eb4275a 100644
--- a/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestPriorityQueue.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using Lucene.Net.Attributes;
 using NUnit.Framework;
 using System;
-using NUnit.Framework.Constraints;
+using System.Collections.Generic;
 
 namespace Lucene.Net.Util
 {
@@ -50,6 +50,108 @@ namespace Lucene.Net.Util
             }
         }
 
+        public void TestPQ()
+        {
+            TestPQ(AtLeast(10000), Random());
+        }
+
+        public static void TestPQ(int count, Random gen)
+        {
+            PriorityQueue<int?> pq = new IntegerQueue(count);
+            int sum = 0, sum2 = 0;
+
+            for (int i = 0; i < count; i++)
+            {
+                int next = gen.Next();
+                sum += next;
+                pq.Add(next);
+            }
+
+            //      Date end = new Date();
+
+            //      System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
+            //      System.out.println(" microseconds/put");
+
+            //      start = new Date();
+
+            int last = int.MinValue;
+            for (int i = 0; i < count; i++)
+            {
+                var next = pq.Pop();
+                assertTrue(next.Value >= last);
+                last = next.Value;
+                sum2 += last;
+            }
+
+            assertEquals(sum, sum2);
+            //      end = new Date();
+
+            //      System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
+            //      System.out.println(" microseconds/pop");
+        }
+
+        [Test]
+        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());
+        }
+
+        [Test]
+        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());
+        }
+
+        [Test]
+        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());
+        }
+
+
+        #region LUCENENET SPECIFIC TESTS
+
         private class IntegerQueueWithSentinel : IntegerQueue
         {
             public IntegerQueueWithSentinel(int count, bool prepopulate)
@@ -109,7 +211,7 @@ namespace Lucene.Net.Util
         } 
 
         [Ignore] // Increase heap size to run this test
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestMaxSizeBounds()
         {
             // Minimum size is 0
@@ -146,7 +248,7 @@ namespace Lucene.Net.Util
             }
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestPrepopulation()
         {
             int maxSize = 10;
@@ -168,7 +270,7 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Size(), expectedSize);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestAdd()
         {
             int maxSize = 10;
@@ -198,7 +300,7 @@ namespace Lucene.Net.Util
             AddAndTest(pq, -111111, -111111, 5);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestDuplicates()
         {
             // Tests that the queue doesn't absorb elements with duplicate keys
@@ -219,7 +321,7 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Size(), 7);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestPop()
         {
             int maxSize = 10;
@@ -277,7 +379,7 @@ namespace Lucene.Net.Util
             pq.Pop();
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestUpdateTop()
         {
             // Mostly to reflect the usage of UpdateTop
@@ -306,7 +408,7 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Top().Field, 1);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestOverflow()
         {
             // Tests adding elements to full queues
@@ -343,7 +445,7 @@ namespace Lucene.Net.Util
             }
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestResize()
         {
             // Initialize a resizable queue
@@ -377,7 +479,7 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Size(), 18);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestIntegrityAfterResize()
         {
             // Tests that after a resize, the queue keeps working fine
@@ -412,19 +514,9 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Top(), -2);
         }
 
-        [Test]
-        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());
-        }
+        
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestInsertWithOverflowDoesNotOverflow()
         {
             // Tests that InsertWithOverflow does not cause overflow
@@ -440,38 +532,6 @@ namespace Lucene.Net.Util
             Assert.AreEqual((int?)3, pq.Top());
         }
 
-        [Test]
-        public virtual void TestInsertWithOverflowDiscardsRight()
-        {
-            // 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());
-
-            pq.Pop();
-            Assert.AreEqual((int?)3, pq.Top());
-            pq.Pop();
-            Assert.AreEqual((int?)5, pq.Top());
-            pq.Pop();
-            Assert.AreEqual((int?)7, pq.Top());
-        }
-
         private static void AddElements<T>(PriorityQueue<T> pq, T[] elements)
         {
             int size = (int)elements.size();
@@ -542,7 +602,7 @@ namespace Lucene.Net.Util
             System.Console.WriteLine("Average time per pop: {0} ticks", total.Ticks / size);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public static void TestPersistence()
         {
             // Tests that a big number of elements are added and popped (in the correct order)
@@ -564,7 +624,7 @@ namespace Lucene.Net.Util
             PopAndTestElements(pq, elements);
         }
 
-        [Test, Timeout(0)]
+        [Test, LuceneNetSpecific]
         public static void TestStress()
         {
             int atLeast = 1000000;
@@ -613,7 +673,7 @@ namespace Lucene.Net.Util
             Assert.AreEqual(pq.Size(), 0);
         }
 
-        [Test, Explicit]
+        [Test, Explicit, LuceneNetSpecific]
         public static void Benchmarks()
         {
             AssumeTrue("Turn VERBOSE on or otherwise you won't see the results.", VERBOSE);
@@ -646,5 +706,7 @@ namespace Lucene.Net.Util
             TimedAddAndPop<int?>(pq, elements);
             pq.Clear();
         }
+
+        #endregion
     }
 }
\ No newline at end of file


Mime
View raw message