sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1448676 - in /sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis: test/TestUtilities.java util/collection/RangeSetTest.java
Date Thu, 21 Feb 2013 15:14:35 GMT
Author: desruisseaux
Date: Thu Feb 21 15:14:35 2013
New Revision: 1448676

URL: http://svn.apache.org/r1448676
Log:
More tests.

Modified:
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java?rev=1448676&r1=1448675&r2=1448676&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java Thu
Feb 21 15:14:35 2013
@@ -20,6 +20,7 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.Iterator;
+import java.util.Random;
 import java.util.concurrent.Callable;
 import java.io.PrintWriter;
 import java.lang.reflect.UndeclaredThrowableException;
@@ -116,6 +117,24 @@ public final strictfp class TestUtilitie
     }
 
     /**
+     * Returns a new random number generator with a random seed. This method logs the seed
value
+     * to the {@link TestCase#out} stream, in order to allow reproducing a test in case of
failure.
+     *
+     * @param  testMethod The name of the method which need a random number generator.
+     * @return A new random number generator initialized with a random seed.
+     */
+    public static Random createRandomNumberGenerator(final String testMethod) {
+        final long seed = Math.round(Math.random() * (1L << 48));
+        final PrintWriter out = TestCase.out;
+        out.print("Random number generator for ");
+        out.print(testMethod);
+        out.print(" created with seed ");
+        out.print(seed);
+        out.println('.');
+        return new Random(seed);
+    }
+
+    /**
      * Parses the date for the given string using the {@code "yyyy-MM-dd HH:mm:ss"} pattern
      * in UTC timezone.
      *

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java?rev=1448676&r1=1448675&r2=1448676&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
Thu Feb 21 15:14:35 2013
@@ -18,12 +18,17 @@ package org.apache.sis.util.collection;
 
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Comparator;
 import java.util.Random;
+import java.util.Arrays;
+import java.util.Collections;
+import java.io.PrintWriter;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.NumberRange;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.Performance;
+import org.apache.sis.test.TestUtilities;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
@@ -171,6 +176,26 @@ public final strictfp class RangeSetTest
     }
 
     /**
+     * Tests {@link RangeSet#comparator()}.
+     */
+    @Test
+    public void testComparator() {
+        final Comparator<Range<Integer>> comparator = RangeSet.create(Integer.class,
true, false).comparator();
+        @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
+        final Range<Integer>[] sorted = new Range[] {
+            NumberRange.create(-20, true, -10, false),
+            NumberRange.create( -5, true,  25, false),
+            NumberRange.create( 28, true,  35, false),
+            NumberRange.create( 40, true,  50, false),
+            NumberRange.create( 60, true,  70, false)
+        };
+        final Range<Integer>[] ranges = sorted.clone();
+        Collections.shuffle(Arrays.asList(ranges));
+        Arrays.sort(ranges, comparator);
+        assertArrayEquals(sorted, ranges);
+    }
+
+    /**
      * Tests the {@link RangeSet#indexOfRange(Comparable)} method.
      */
     @Test
@@ -226,7 +251,8 @@ public final strictfp class RangeSetTest
      */
     @Performance
     public void stress() throws InterruptedException {
-        final Random r = new Random(5638743);
+        final PrintWriter out = TestCase.out;
+        final Random r = TestUtilities.createRandomNumberGenerator("RangeSetTest.stress()");
         for (int p=0; p<10; p++) {
             final long start = System.nanoTime();
             final RangeSet<Integer> set = RangeSet.create(Integer.class, true, false);
@@ -239,7 +265,9 @@ public final strictfp class RangeSetTest
                     set.remove(lower, upper);
                 }
             }
-            out.println((System.nanoTime() - start) / 1E9 + "  " + set.size());
+            out.print((System.nanoTime() - start) / 1E9);
+            out.print(" seconds for a size of ");
+            out.println(set.size());
             Thread.sleep(1000);
         }
     }



Mime
View raw message