Source Code Cross Referenced for StorelessUnivariateStatisticAbstractTest.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » stat » descriptive » 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 » Science » Apache commons math 1.1 » org.apache.commons.math.stat.descriptive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.math.stat.descriptive;
017:
018:        import org.apache.commons.math.TestUtils;
019:        import org.apache.commons.math.stat.descriptive.moment.SecondMoment;
020:
021:        /**
022:         * Test cases for {@link StorelessUnivariateStatistic} classes.
023:         * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
024:         */
025:        public abstract class StorelessUnivariateStatisticAbstractTest extends
026:                UnivariateStatisticAbstractTest {
027:
028:            public StorelessUnivariateStatisticAbstractTest(String name) {
029:                super (name);
030:            }
031:
032:            /** Small sample arrays */
033:            protected double[][] smallSamples = { {}, { 1 }, { 1, 2 },
034:                    { 1, 2, 3 }, { 1, 2, 3, 4 } };
035:
036:            /** Return a new instance of the statistic */
037:            public abstract UnivariateStatistic getUnivariateStatistic();
038:
039:            /**Expected value for  the testArray defined in UnivariateStatisticAbstractTest */
040:            public abstract double expectedValue();
041:
042:            /** Verify that calling increment() in a loop over testArray results in correct state */
043:            public void testIncrementation() throws Exception {
044:
045:                StorelessUnivariateStatistic statistic = (StorelessUnivariateStatistic) getUnivariateStatistic();
046:
047:                statistic.clear();
048:
049:                for (int i = 0; i < testArray.length; i++) {
050:                    statistic.increment(testArray[i]);
051:                }
052:
053:                assertEquals(expectedValue(), statistic.getResult(),
054:                        getTolerance());
055:                assertEquals(testArray.length, statistic.getN());
056:
057:                statistic.clear();
058:
059:                assertTrue(Double.isNaN(statistic.getResult()));
060:                assertEquals(0, statistic.getN());
061:
062:            }
063:
064:            public void testSerialization() throws Exception {
065:
066:                StorelessUnivariateStatistic statistic = (StorelessUnivariateStatistic) getUnivariateStatistic();
067:
068:                TestUtils.checkSerializedEquality(statistic);
069:
070:                statistic.clear();
071:
072:                for (int i = 0; i < testArray.length; i++) {
073:                    statistic.increment(testArray[i]);
074:                    if (i % 5 == 0)
075:                        statistic = (StorelessUnivariateStatistic) TestUtils
076:                                .serializeAndRecover(statistic);
077:                }
078:
079:                TestUtils.checkSerializedEquality(statistic);
080:
081:                assertEquals(expectedValue(), statistic.getResult(),
082:                        getTolerance());
083:
084:                statistic.clear();
085:
086:                assertTrue(Double.isNaN(statistic.getResult()));
087:
088:            }
089:
090:            public void testEqualsAndHashCode() {
091:                StorelessUnivariateStatistic statistic = (StorelessUnivariateStatistic) getUnivariateStatistic();
092:                StorelessUnivariateStatistic statistic2 = null;
093:
094:                assertTrue("non-null, compared to null", !statistic
095:                        .equals(statistic2));
096:                assertTrue("reflexive, non-null", statistic.equals(statistic));
097:
098:                int emptyHash = statistic.hashCode();
099:                statistic2 = (StorelessUnivariateStatistic) getUnivariateStatistic();
100:                assertTrue("empty stats should be equal", statistic
101:                        .equals(statistic2));
102:                assertEquals("empty stats should have the same hashcode",
103:                        emptyHash, statistic2.hashCode());
104:
105:                statistic.increment(1d);
106:                assertTrue("reflexive, non-empty", statistic.equals(statistic));
107:                assertTrue("non-empty, compared to empty", !statistic
108:                        .equals(statistic2));
109:                assertTrue("non-empty, compared to empty", !statistic2
110:                        .equals(statistic));
111:                assertTrue(
112:                        "non-empty stat should have different hashcode from empty stat",
113:                        statistic.hashCode() != emptyHash);
114:
115:                statistic2.increment(1d);
116:                assertTrue("stats with same data should be equal", statistic
117:                        .equals(statistic2));
118:                assertEquals(
119:                        "stats with same data should have the same hashcode",
120:                        statistic.hashCode(), statistic2.hashCode());
121:
122:                statistic.increment(Double.POSITIVE_INFINITY);
123:                assertTrue("stats with different n's should not be equal",
124:                        !statistic2.equals(statistic));
125:                assertTrue(
126:                        "stats with different n's should have different hashcodes",
127:                        statistic.hashCode() != statistic2.hashCode());
128:
129:                statistic2.increment(Double.POSITIVE_INFINITY);
130:                assertTrue("stats with same data should be equal", statistic
131:                        .equals(statistic2));
132:                assertEquals(
133:                        "stats with same data should have the same hashcode",
134:                        statistic.hashCode(), statistic2.hashCode());
135:
136:                statistic.clear();
137:                statistic2.clear();
138:                assertTrue("cleared stats should be equal", statistic
139:                        .equals(statistic2));
140:                assertEquals(
141:                        "cleared stats should have thashcode of empty stat",
142:                        emptyHash, statistic2.hashCode());
143:                assertEquals(
144:                        "cleared stats should have thashcode of empty stat",
145:                        emptyHash, statistic.hashCode());
146:
147:            }
148:
149:            public void testMomentSmallSamples() {
150:                UnivariateStatistic stat = getUnivariateStatistic();
151:                if (stat instanceof  SecondMoment) {
152:                    SecondMoment moment = (SecondMoment) getUnivariateStatistic();
153:                    assertTrue(Double.isNaN(moment.getResult()));
154:                    moment.increment(1d);
155:                    assertEquals(0d, moment.getResult(), 0);
156:                }
157:            }
158:
159:            /** 
160:             * Make sure that evaluate(double[]) and inrementAll(double[]), 
161:             * getResult() give same results.
162:             */
163:            public void testConsistency() {
164:                StorelessUnivariateStatistic stat = (StorelessUnivariateStatistic) getUnivariateStatistic();
165:                stat.incrementAll(testArray);
166:                assertEquals(stat.getResult(), stat.evaluate(testArray),
167:                        getTolerance());
168:                for (int i = 0; i < smallSamples.length; i++) {
169:                    stat.clear();
170:                    for (int j = 0; j < smallSamples[i].length; j++) {
171:                        stat.increment(smallSamples[i][j]);
172:                    }
173:                    TestUtils.assertEquals(stat.getResult(), stat
174:                            .evaluate(smallSamples[i]), getTolerance());
175:                }
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.