From sis-commits-return-524-apmail-incubator-sis-commits-archive=incubator.apache.org@incubator.apache.org Thu Sep 20 11:12:24 2012 Return-Path: X-Original-To: apmail-incubator-sis-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-sis-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0DF29DF42 for ; Thu, 20 Sep 2012 11:12:24 +0000 (UTC) Received: (qmail 10691 invoked by uid 500); 20 Sep 2012 11:12:23 -0000 Delivered-To: apmail-incubator-sis-commits-archive@incubator.apache.org Received: (qmail 10654 invoked by uid 500); 20 Sep 2012 11:12:23 -0000 Mailing-List: contact sis-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@incubator.apache.org Delivered-To: mailing list sis-commits@incubator.apache.org Received: (qmail 10633 invoked by uid 99); 20 Sep 2012 11:12:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 11:12:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 11:12:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8310823889D7; Thu, 20 Sep 2012 11:11:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1387972 - in /incubator/sis/trunk/sis-utility/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/sis/ java/org/apache/sis/util/ java/org/apache/sis/util/logging/ Date: Thu, 20 Sep 2012 11:11:37 -0000 To: sis-commits@incubator.apache.org From: desruisseaux@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120920111137.8310823889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: desruisseaux Date: Thu Sep 20 11:11:36 2012 New Revision: 1387972 URL: http://svn.apache.org/viewvc?rev=1387972&view=rev Log: Added a few JUnit test classes. Added: incubator/sis/trunk/sis-utility/src/test/ incubator/sis/trunk/sis-utility/src/test/java/ incubator/sis/trunk/sis-utility/src/test/java/org/ incubator/sis/trunk/sis-utility/src/test/java/org/apache/ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java (with props) incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java (with props) incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java (with props) Added: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java URL: http://svn.apache.org/viewvc/incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java?rev=1387972&view=auto ============================================================================== --- incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java (added) +++ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java Thu Sep 20 11:11:36 2012 @@ -0,0 +1,68 @@ +/* + * 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; + +import org.junit.*; +import static org.junit.Assert.*; + + +/** + * Tests the {@link Arrays} utility methods. + * + * @author Martin Desruisseaux (Geomatys) + * @author Johann Sorel (Geomatys) + * @since 0.3 (derived from geotk-3.04) + * @version 0.3 + * @module + */ +public final strictfp class ArraysTest { + /** + * Tests {@link Arrays#removeDuplicated(Object[])}. + */ + @Test + public void testRemoveDuplicated() { + final Integer[] array = new Integer[] {2, 8, 4, 8, 1, 2, 8}; + assertArrayEquals(new Integer[] {2, 8, 4, 1}, + Arrays.resize(array, Arrays.removeDuplicated(array))); + } + + /** + * Tests {@link Arrays#reverse(int[])}. + * The test uses an array of even length, then an array of odd length. + */ + @Test + public void testReverse() { + int[] array = new int[] {2, 4, 8, 10}; + Arrays.reverse(array); + assertArrayEquals(new int[] {10, 8, 4, 2}, array); + + array = new int[] {2, 4, 8, 10, 11}; + Arrays.reverse(array); + assertArrayEquals(new int[] {11, 10, 8, 4, 2}, array); + } + + /** + * Tests {@link Arrays#unionSorted(int[], int[])}. + */ + @Test + public void testUnionSorted() { + final int[] array1 = new int[] {2, 4, 6, 9, 12}; + final int[] array2 = new int[] {1, 2, 3, 12, 13, 18, 22}; + final int[] union = Arrays.unionSorted(array1, array2); + assertArrayEquals(new int[] {1, 2, 3, 4, 6, 9, 12, 13, 18, 22}, union); + } +} Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ArraysTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java URL: http://svn.apache.org/viewvc/incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1387972&view=auto ============================================================================== --- incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java (added) +++ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java Thu Sep 20 11:11:36 2012 @@ -0,0 +1,263 @@ +/* + * 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; + +import org.junit.*; +import static org.junit.Assert.*; +import static org.apache.sis.util.CharSequences.*; + + +/** + * Tests {@link CharSequences} methods. + * + * @author Martin Desruisseaux (Geomatys) + * @author Johann Sorel (Geomatys) + * @since 0.3 (derived from geotk-3.00) + * @version 0.3 + * @module + */ +public final strictfp class CharSequencesTest { + /** + * Tests {@link CharSequences#spaces(int)}. + */ + @Test + public void testSpaces() { + assertEquals("", spaces(0)); + assertEquals(" ", spaces(1)); + assertEquals(" ", spaces(8)); + } + + /** + * Tests {@link CharSequences#count(String, String)} and its variants. + */ + @Test + public void testCount() { + assertEquals(0, count("An ordinary sentence.", '-')); + assertEquals(4, count("- this one has -dashs--", '-')); + assertEquals(2, count("An ordinary sentence.", "en")); + } + + /** + * Tests {@link CharSequences#split(String, char)}. + */ + @Test + public void testSplit() { + assertArrayEquals(new String[] {"lundi", "mardi", "mercredi"}, + CharSequences.split("lundi , mardi,mercredi ", ',')); + } + + /** + * Tests {@link CharSequences#parseFloats(String, char)}. + */ + @Test + public void testFloats() { + assertArrayEquals(new float[] {5, 1.5f, Float.NaN, -8}, + CharSequences.parseFloats("5 , 1.5,, -8 ", ','), 0f); + } + + /** + * Tests the {@link CharSequences#indexOf(CharSequence, CharSequence, int)} method. + * We test four time with different kind of character sequences. + */ + @Test + public void testIndexOf() { + for (int i=0; i<3; i++) { + CharSequence string = "An ordinary sentence."; + switch (i) { + case 0: /* Test directly on the String instance. */ break; + case 1: string = new StringBuilder ((String) string); break; + case 2: string = new StringBuffer ((String) string); break; +// TODO case 3: string = new SimpleInternationalString((String) string); break; + default: throw new AssertionError(i); + } + assertEquals(-1, indexOf(string, "dummy", 0)); + assertEquals( 0, indexOf(string, "An", 0)); + assertEquals(-1, indexOf(string, "An", 1)); + assertEquals(12, indexOf(string, "sentence.", 0)); + assertEquals(-1, indexOf(string, "sentence;", 0)); + } + } + + /** + * Tests the {@link CharSequences#replace(StringBuilder, String, String)} method. + */ + @Test + public void testReplace() { + final StringBuilder buffer = new StringBuilder("One two three two one"); + replace(buffer, "two", "zero"); + assertEquals("One zero three zero one", buffer.toString()); + replace(buffer, "zero", "ten"); + assertEquals("One ten three ten one", buffer.toString()); + } + + /** + * Tests the {@link CharSequences#replace(StringBuilder, int, int, char[])} method. + */ + @Test + public void testReplaceChars() { + final StringBuilder buffer = new StringBuilder("ABCD1234EFGH"); + replace(buffer, 4, 8, new char[] {'5','6','7','8'}); + assertEquals("ABCD5678EFGH", buffer.toString()); + replace(buffer, 4, 6, new char[] {'1','2','3','4'}); + assertEquals("ABCD123478EFGH", buffer.toString()); + replace(buffer, 8, 10, new char[] {'a','b','c','d'}); + assertEquals("ABCD1234abcdEFGH", buffer.toString()); + } + + /** + * Tests the {@link CharSequences#remove(StringBuilder, String)} method. + */ + @Test + public void testRemove() { + final StringBuilder buffer = new StringBuilder("EPSG.6.7"); + remove(buffer, "."); + assertEquals("EPSG67", buffer.toString()); + } + + /** + * Tests the {@link CharSequences#trim(String)} method. + */ + @Test + public void testTrim() { + assertEquals("A text.", trim(" A text. ")); + } + + /** + * Tests the {@link CharSequences#trimFractionalPart(String)} method. + */ + @Test + public void testTrimFractionalPart() { + assertEquals("4", trimFractionalPart("4")); + assertEquals("4", trimFractionalPart("4.")); + assertEquals("4", trimFractionalPart("4.0")); + assertEquals("4", trimFractionalPart("4.00")); + assertEquals("4.10", trimFractionalPart("4.10")); + } + + /** + * Tests the {@link CharSequences#token(CharSequence, int)} method. + */ + @Test + public void testToken() { + assertEquals("Id4", token("..Id4 56B..", 2)); + assertEquals("56", token("..Id4 56B..", 6)); + } + + /** + * Tests the {@link CharSequences#toASCII(CharSequence)} method. + */ + @Test + public void testToASCII() { + final String metre = "metre"; + assertSame (metre, toASCII(metre)); + assertEquals(metre, toASCII("mètre").toString()); + } + + /** + * Tests the {@link CharSequences#camelCaseToWords(CharSequence, boolean)} method. + */ + @Test + public void testCamelCaseToWords() { + final CharSequence convert = camelCaseToWords("PixelInterleavedSampleModel", true); + assertEquals("Pixel interleaved sample model", convert.toString()); + } + + /** + * Tests the {@link CharSequences#getLinesFromMultilines(String)} method. + */ + @Test + public void testGetLinesFromMultilines() { + final String[] splitted = getLinesFromMultilines("\nOne\r\nTwo\rThree\rFour\nFive\n\rSix\n"); + assertArrayEquals(new String[] { + "", + "One", + "Two", + "Three", + "Four", + "Five", + "", + "Six", + "" + }, splitted); + } + + /** + * Tests the {@link CharSequences#camelCaseToAcronym(String)} method. + */ + @Test + public void testCamelCaseToAcronym() { + assertEquals("OGC", camelCaseToAcronym("OGC")); + assertEquals("OGC", camelCaseToAcronym("Open Geospatial Consortium")); + assertEquals("E", camelCaseToAcronym("East")); + assertEquals("NE", camelCaseToAcronym("North-East")); + assertEquals("NE", camelCaseToAcronym("NORTH_EAST")); + assertEquals("NE", camelCaseToAcronym("northEast")); + } + + /** + * Tests the {@link CharSequences#isAcronymForWords(CharSequence, CharSequence)} method. + */ + @Test + public void testIsAcronymForWords() { + /* + * Following should be accepted as acronyms... + */ + assertTrue(isAcronymForWords("OGC", "Open Geospatial Consortium")); + assertTrue(isAcronymForWords("O.G.C.", "Open Geospatial Consortium")); + assertTrue(isAcronymForWords("OpGeoCon", "Open Geospatial Consortium")); + assertTrue(isAcronymForWords("Open Geospatial Consortium", "Open Geospatial Consortium")); + assertTrue(isAcronymForWords("ogc", "Open Geospatial Consortium")); + /* + * Following should be rejected... + */ + assertFalse(isAcronymForWords("ORC", "Open Geospatial Consortium")); + assertFalse(isAcronymForWords("O.C.G.", "Open Geospatial Consortium")); + assertFalse(isAcronymForWords("OGC2", "Open Geospatial Consortium")); + assertFalse(isAcronymForWords("OG", "Open Geospatial Consortium")); + assertFalse(isAcronymForWords("GC", "Open Geospatial Consortium")); + /* + * Following are mapping of EPSG table names from MS-Access to ANSI SQL. + * All those items must be recognized as acroynms - this is requred by DirectEpsgFactory. + */ + assertTrue(isAcronymForWords("alias", "[Alias]")); + assertTrue(isAcronymForWords("area", "[Area]")); + assertTrue(isAcronymForWords("coordinateaxis", "[Coordinate Axis]")); + assertTrue(isAcronymForWords("coordinateaxisname", "[Coordinate Axis Name]")); + assertTrue(isAcronymForWords("coordoperation", "[Coordinate_Operation]")); + assertTrue(isAcronymForWords("coordoperationmethod", "[Coordinate_Operation Method]")); + assertTrue(isAcronymForWords("coordoperationparam", "[Coordinate_Operation Parameter]")); + assertTrue(isAcronymForWords("coordoperationparamusage", "[Coordinate_Operation Parameter Usage]")); + assertTrue(isAcronymForWords("coordoperationparamvalue", "[Coordinate_Operation Parameter Value]")); + assertTrue(isAcronymForWords("coordoperationpath", "[Coordinate_Operation Path]")); + assertTrue(isAcronymForWords("coordinatereferencesystem", "[Coordinate Reference System]")); + assertTrue(isAcronymForWords("coordinatesystem", "[Coordinate System]")); + assertTrue(isAcronymForWords("datum", "[Datum]")); + assertTrue(isAcronymForWords("ellipsoid", "[Ellipsoid]")); + assertTrue(isAcronymForWords("namingsystem", "[Naming System]")); + assertTrue(isAcronymForWords("primemeridian", "[Prime Meridian]")); + assertTrue(isAcronymForWords("supersession", "[Supersession]")); + assertTrue(isAcronymForWords("unitofmeasure", "[Unit of Measure]")); + assertTrue(isAcronymForWords("versionhistory", "[Version History]")); + assertTrue(isAcronymForWords("change", "[Change]")); + assertTrue(isAcronymForWords("deprecation", "[Deprecation]")); + /* + * It is important the the following is not recognized as an acronym, + * otherwise it leads to a confusion in DirectEpsgFactory. + */ + assertFalse(isAcronymForWords("coordoperation", "[Coordinate_Operation Method]")); + } +} Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java URL: http://svn.apache.org/viewvc/incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java?rev=1387972&view=auto ============================================================================== --- incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java (added) +++ incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java Thu Sep 20 11:11:36 2012 @@ -0,0 +1,86 @@ +/* + * 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.logging; + +import java.util.concurrent.TimeUnit; + +import org.junit.*; +import static org.junit.Assert.*; +import static org.apache.sis.util.logging.PerformanceLevel.*; + + +/** + * Tests the {@link PerformanceLevel} class. + * + * @author Martin Desruisseaux (Geomatys) + * @since 0.3 (derived from geotk-3.16) + * @version 0.3 + * @module + */ +public final strictfp class PerformanceLevelTest { + /** + * Ensures that the duration are conform to the documentation. + */ + @Test + public void testGetMinDuration() { + assertEquals(0, PERFORMANCE.getMinDuration(TimeUnit.NANOSECONDS)); + assertEquals(100, SLOW .getMinDuration(TimeUnit.MILLISECONDS)); + assertEquals(1, SLOWER .getMinDuration(TimeUnit.SECONDS)); + assertEquals(5, SLOWEST .getMinDuration(TimeUnit.SECONDS)); + } + + /** + * Tests modifying the configuration. + */ + @Test + public void testSetMinDuration() { + try { + SLOW.setMinDuration(2, TimeUnit.SECONDS); + assertEquals(0, PERFORMANCE.getMinDuration(TimeUnit.SECONDS)); + assertEquals(2, SLOW .getMinDuration(TimeUnit.SECONDS)); + assertEquals(2, SLOWER .getMinDuration(TimeUnit.SECONDS)); + assertEquals(5, SLOWEST .getMinDuration(TimeUnit.SECONDS)); + + SLOWEST.setMinDuration(1, TimeUnit.SECONDS); + assertEquals(0, PERFORMANCE.getMinDuration(TimeUnit.SECONDS)); + assertEquals(1, SLOW .getMinDuration(TimeUnit.SECONDS)); + assertEquals(1, SLOWER .getMinDuration(TimeUnit.SECONDS)); + assertEquals(1, SLOWEST .getMinDuration(TimeUnit.SECONDS)); + + PERFORMANCE.setMinDuration(6, TimeUnit.SECONDS); + assertEquals(0, PERFORMANCE.getMinDuration(TimeUnit.SECONDS)); + assertEquals(6, SLOW .getMinDuration(TimeUnit.SECONDS)); + assertEquals(6, SLOWER .getMinDuration(TimeUnit.SECONDS)); + assertEquals(6, SLOWEST .getMinDuration(TimeUnit.SECONDS)); + } finally { + SLOW .setMinDuration(100, TimeUnit.MILLISECONDS); + SLOWER .setMinDuration(1, TimeUnit.SECONDS); + SLOWEST.setMinDuration(5, TimeUnit.SECONDS); + } + } + + /** + * Tests the {@link PerformanceLevel#forDuration(long, TimeUnit)} method. + */ + @Test + public void testForDuration() { + assertSame(SLOW, forDuration(500, TimeUnit.MILLISECONDS)); + assertSame(SLOWER, forDuration(2, TimeUnit.SECONDS)); + assertSame(SLOWEST, forDuration(6, TimeUnit.SECONDS)); + assertSame(PERFORMANCE, forDuration(50, TimeUnit.MILLISECONDS)); + } +} Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/logging/PerformanceLevelTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain