Source Code Cross Referenced for CategoryTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » coverage » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.coverage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2002, Institut de Recherche pour le Développement
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.coverage;
018:
019:        // J2SE dependencies
020:        import java.util.Random;
021:
022:        // JUnit dependencies
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:
027:        // OpenGIS dependencies
028:        import org.opengis.referencing.operation.MathTransform1D;
029:        import org.opengis.referencing.operation.TransformException;
030:
031:        /**
032:         * Tests the {@link Category} implementation.
033:         *
034:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/CategoryTest.java $
035:         * @version $Id: CategoryTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
036:         * @author Martin Desruisseaux
037:         */
038:        public class CategoryTest extends TestCase {
039:            /**
040:             * Run the suite from the command line.
041:             */
042:            public static void main(String[] args) {
043:                org.geotools.util.logging.Logging.GEOTOOLS
044:                        .forceMonolineConsoleOutput();
045:                junit.textui.TestRunner.run(suite());
046:            }
047:
048:            /**
049:             * Returns the test suite.
050:             */
051:            public static Test suite() {
052:                return new TestSuite(CategoryTest.class);
053:            }
054:
055:            /**
056:             * Random number generator for this test.
057:             */
058:            private static final Random random = new Random(
059:                    9119969932919929834L);
060:
061:            /**
062:             * Constructs a test case with the given name.
063:             */
064:            public CategoryTest(final String name) {
065:                super (name);
066:            }
067:
068:            /**
069:             * Check if a {@link Comparable} is a number identical to the supplied integer value.
070:             */
071:            private static void assertEquals(String message, Comparable number,
072:                    int expected) {
073:                assertTrue("Integer.class", number instanceof  Integer);
074:                assertEquals(message, expected, ((Number) number).intValue());
075:            }
076:
077:            /**
078:             * Check if a {@link Comparable} is a number identical to the supplied float value.
079:             */
080:            private static void assertEquals(String message, Comparable number,
081:                    double expected, double EPS) {
082:                assertTrue("Double.class", number instanceof  Double);
083:                final double actual = ((Number) number).doubleValue();
084:                if (Double.isNaN(expected)) {
085:                    assertEquals(message, toHexString(expected),
086:                            toHexString(actual));
087:                } else {
088:                    assertEquals(message, expected, actual, EPS);
089:                }
090:            }
091:
092:            /**
093:             * Returns the specified value as an hexadecimal string. Usefull
094:             * for comparing NaN values.
095:             */
096:            private static String toHexString(final double value) {
097:                return Integer.toHexString(Float
098:                        .floatToRawIntBits((float) value));
099:            }
100:
101:            /**
102:             * Make sure that qualitative category produce the expected result.
103:             */
104:            public void testQualitativeCategory() throws TransformException {
105:                for (int pass = 0; pass < 100; pass++) {
106:                    final int sample = random.nextInt(64);
107:                    final Category category1 = new Category("Auto", null,
108:                            sample);
109:                    final Category category2 = new Category(
110:                            category1.getName(), category1.getColors(),
111:                            category1.getRange(), category1
112:                                    .getSampleToGeophysics());
113:
114:                    assertEquals("<init>", category1, category2);
115:                    assertEquals("lower", category1.geophysics(false)
116:                            .getRange().getMinValue(), sample);
117:                    assertEquals("upper", category1.geophysics(false)
118:                            .getRange().getMaxValue(), sample);
119:
120:                    assertNull("geophysics(false)", category1.geophysics(false)
121:                            .getSampleToGeophysics());
122:                    assertNull("geophysics(true)", category1.geophysics(true)
123:                            .getSampleToGeophysics());
124:                    for (int i = 0; i < 200; i++) {
125:                        final double x = 100 * random.nextDouble();
126:                        final double y1 = category1.transform.transform(x);
127:                        final double y2 = category2.transform.transform(x);
128:                        assertTrue("toGeophysics(1)", Double.isNaN(y1));
129:                        assertTrue("toGeophysics(2)", Double.isNaN(y2));
130:                        assertEquals("NaN", Double.doubleToRawLongBits(y1),
131:                                Double.doubleToRawLongBits(y2));
132:                        assertEquals("toSample(1)", sample,
133:                                category1.inverse.transform.transform(y1), 0);
134:                        assertEquals("toSample(2)", sample,
135:                                category2.inverse.transform.transform(y2), 0);
136:                    }
137:                }
138:            }
139:
140:            /**
141:             * Make sure that linear category produce the expected result.
142:             * This test check also if the default {@link MathTransform1D}
143:             * for a linear relation is right.
144:             */
145:            public void testLinearCategory() throws TransformException {
146:                final double EPS = 1E-9;
147:                for (int pass = 0; pass < 100; pass++) {
148:                    final int lower = random.nextInt(64);
149:                    final int upper = random.nextInt(128) + lower + 1;
150:                    final double scale = 10 * random.nextDouble() + 0.1; // Must be positive for this test.
151:                    final double offset = 10 * random.nextDouble() - 5.0;
152:                    final Category category = new Category("Auto", null, lower,
153:                            upper, scale, offset);
154:
155:                    assertEquals("lower", category.geophysics(false).getRange()
156:                            .getMinValue(), lower);
157:                    assertEquals("upper", category.geophysics(false).getRange()
158:                            .getMaxValue(), upper);
159:                    assertEquals("minimum", category.geophysics(true)
160:                            .getRange().getMinValue(), lower * scale + offset,
161:                            EPS);
162:                    assertEquals("maximum", category.geophysics(true)
163:                            .getRange().getMaxValue(), upper * scale + offset,
164:                            EPS);
165:
166:                    for (int i = 0; i < 200; i++) {
167:                        final double x = 100 * random.nextDouble();
168:                        final double y = x * scale + offset;
169:                        assertEquals("toGeophysics", y, category.transform
170:                                .transform(x), EPS);
171:                        assertEquals("toSample", x, category.inverse.transform
172:                                .transform(y), EPS);
173:                    }
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.