From commits-return-6913-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Mon Dec 14 21:09:28 2015 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8079C18729 for ; Mon, 14 Dec 2015 21:09:28 +0000 (UTC) Received: (qmail 97019 invoked by uid 500); 14 Dec 2015 21:09:28 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 96986 invoked by uid 500); 14 Dec 2015 21:09:28 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 96977 invoked by uid 99); 14 Dec 2015 21:09:28 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2015 21:09:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E94FFC0D15 for ; Mon, 14 Dec 2015 21:09:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.246 X-Spam-Level: * X-Spam-Status: No, score=1.246 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id SYvwqFFWtBtS for ; Mon, 14 Dec 2015 21:09:26 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 3109E20753 for ; Mon, 14 Dec 2015 21:09:25 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 20CBBE05E3 for ; Mon, 14 Dec 2015 21:09:24 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id AE59F3A081E for ; Mon, 14 Dec 2015 21:09:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1720014 [2/2] - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ sis-utility/src/main/java/org/apache/sis/util/c... Date: Mon, 14 Dec 2015 21:09:23 -0000 To: commits@sis.apache.org From: desruisseaux@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151214210923.AE59F3A081E@svn01-us-west.apache.org> Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1720014&r1=1720013&r2=1720014&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] Mon Dec 14 21:09:23 2015 @@ -26,7 +26,7 @@ import org.junit.BeforeClass; * * @author Martin Desruisseaux (Geomatys) * @since 0.3 - * @version 0.6 + * @version 0.7 * @module */ @Suite.SuiteClasses({ @@ -68,6 +68,7 @@ import org.junit.BeforeClass; // Collections. org.apache.sis.internal.util.CheckedArrayListTest.class, org.apache.sis.internal.system.ReferenceQueueConsumerTest.class, + org.apache.sis.util.collection.IntegerListTest.class, org.apache.sis.util.collection.WeakHashSetTest.class, org.apache.sis.util.collection.WeakValueHashMapTest.class, org.apache.sis.util.collection.CacheTest.class, Added: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java?rev=1720014&view=auto ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java (added) +++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java [UTF-8] Mon Dec 14 21:09:23 2015 @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.util.collection; + +import java.util.List; +import java.util.ArrayList; +import java.util.Set; +import java.util.HashSet; +import java.util.Collections; +import java.util.Random; +import org.apache.sis.test.TestCase; +import org.apache.sis.test.TestUtilities; +import org.junit.Test; + +import static java.lang.StrictMath.*; +import static org.apache.sis.test.Assert.*; + + +/** + * Tests {@link IntegerList} implementations. + * + * @author Martin Desruisseaux (Geomatys) + * @since 0.7 + * @version 0.7 + * @module + */ +public final strictfp class IntegerListTest extends TestCase { + /** + * The list of integers. + */ + private IntegerList list; + + /** + * Writes values and read them again for making sure they are the expected ones. + * + * @param maximalValue The maximal value allowed. + */ + private void testReadWrite(final int maximalValue) { + final Random random = TestUtilities.createRandomNumberGenerator(); + final int length = 400; + // Use half the lenght as initial capacity in order to test dynamic resizing. + list = new IntegerList(length / 2, maximalValue); + assertTrue(list.maximalValue() >= maximalValue); + final List copy = new ArrayList<>(length); + for (int i=0; i clone = list.clone(); + assertEquals(copy, clone); + assertEquals(copy.remove(100), clone.remove(100)); + assertEquals(copy, clone); + copy .subList(128, 256).clear(); + clone.subList(128, 256).clear(); + assertEquals(copy, clone); + } + + /** + * Returns the next number from the random number generator. + */ + private static int nextInt(final Random random, final int maximalValue) { + if (maximalValue == Integer.MAX_VALUE) { + return abs(random.nextInt()); + } else { + return random.nextInt(maximalValue + 1); + } + } + + /** + * Tests the fill value using the existing list, which is assumed + * already filled with random values prior this method call. + */ + private void testFill(final int value) { + assertEquals(400, list.size()); + final Set set = new HashSet<>(); + list.fill(value); + set.addAll(list); + assertEquals(Collections.singleton(value), set); + list.fill(0); + set.clear(); + set.addAll(list); + assertEquals(Collections.singleton(0), set); + } + + /** + * Tests with a maximal value of 1. + */ + @Test + public void test1() { + testReadWrite(1); + testFill(1); + } + + /** + * Tests with a maximal value of 2. + */ + @Test + public void test2() { + testReadWrite(2); + testFill(2); + } + + /** + * Tests with a maximal value of 3. + */ + @Test + public void test3() { + testReadWrite(3); + testFill(3); + } + + /** + * Tests with a maximal value of 10. + */ + @Test + public void test10() { + testReadWrite(10); + testFill(10); + } + + /** + * Tests with a maximal value of 100. + */ + @Test + public void test100() { + testReadWrite(100); + assertEquals(400, list.size()); + final int old100 = list.getInt(100); + final int old101 = list.getInt(101); + assertFalse(0 == old100); + assertFalse(0 == old101); + list.resize(101); + assertEquals(old100, list.getInt(100)); + list.resize(200); + assertEquals(200, list.size()); + assertEquals(old100, list.getInt(100)); + assertEquals(0, list.getInt(101)); + for (int i=101; i<200; i++) { + assertEquals(0, list.getInt(i)); + } + list.resize(400); + testFill(100); + } + + /** + * Tests with a maximal value of 100000. + */ + @Test + public void test100000() { + testReadWrite(100000); + testFill(17); + } + + /** + * Tests with a maximal value of {@value Integer#MAX_VALUE}. + */ + @Test + public void testMax() { + testReadWrite(Integer.MAX_VALUE); + testFill(17); + } +} Propchange: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8