banshee r3930 - in trunk/banshee: . tests/Hyena



Author: abock
Date: Mon May 19 18:20:18 2008
New Revision: 3930
URL: http://svn.gnome.org/viewvc/banshee?rev=3930&view=rev

Log:
2008-05-19  Aaron Bockover  <abock gnome org>

    * tests/Hyena/RangeCollectionTests.cs: Use a SortedInsert method instead
    of Add*N + Sort for the reference collection so it's a little faster;
    reduce the iterations to 75k to appease Gabe



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/tests/Hyena/RangeCollectionTests.cs

Modified: trunk/banshee/tests/Hyena/RangeCollectionTests.cs
==============================================================================
--- trunk/banshee/tests/Hyena/RangeCollectionTests.cs	(original)
+++ trunk/banshee/tests/Hyena/RangeCollectionTests.cs	Mon May 19 18:20:18 2008
@@ -367,6 +367,19 @@
         Assert.AreEqual (13, range[8]);
     }
     
+    private static void SortedInsert<T> (List<T> list, T value) 
+        where T : IComparable
+    {
+        if (list.Count == 0 || list[list.Count - 1].CompareTo (value) < 0) {
+            list.Add (value);
+        } else if (list[0].CompareTo (value) > 0) {
+            list.Insert (0, value);
+        } else {
+            int index = list.BinarySearch (value);
+            list.Insert (index < 0 ? ~index : index, value);
+        }
+    }
+
     [Test]
     public void TestStressForGoodIndexes ()
     {
@@ -374,14 +387,12 @@
         RangeCollection ranges = new RangeCollection ();
         List<int> indexes = new List<int> ();
         
-        for (int i = 0, n = 250000; i < n; i++) {
+        for (int i = 0, n = 75000; i < n; i++) {
             int value = random.Next (n);
             if (ranges.Add (value)) {
-                indexes.Add (value);
+                SortedInsert (indexes, value);
             }
-        }
-        
-        indexes.Sort ();
+        } 
         
         Assert.AreEqual (indexes.Count, ranges.Count);
         for (int i = 0; i < indexes.Count; i++) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]