Source Code Cross Referenced for MixedListUnivariateImplTest.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 java.util.ArrayList;
019:        import java.util.List;
020:
021:        import org.apache.commons.math.util.NumberTransformer;
022:        import org.apache.commons.math.util.TransformerMap;
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * Test cases for the {@link Univariate} class.
029:         *
030:         * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
031:         */
032:
033:        public final class MixedListUnivariateImplTest extends TestCase {
034:            private double one = 1;
035:            private float two = 2;
036:            private int three = 3;
037:
038:            private double mean = 2;
039:            private double sumSq = 18;
040:            private double sum = 8;
041:            private double var = 0.666666666666666666667;
042:            private double std = Math.sqrt(var);
043:            private double n = 4;
044:            private double min = 1;
045:            private double max = 3;
046:            private double skewness = 0;
047:            private double kurtosis = 0.5;
048:            private double tolerance = 10E-15;
049:
050:            private TransformerMap transformers = new TransformerMap();
051:
052:            public MixedListUnivariateImplTest(String name) {
053:                super (name);
054:                transformers = new TransformerMap();
055:
056:                transformers.putTransformer(Foo.class, new NumberTransformer() {
057:                    public double transform(Object o) {
058:                        return Double.parseDouble(((Foo) o).heresFoo());
059:                    }
060:                });
061:
062:                transformers.putTransformer(Bar.class, new NumberTransformer() {
063:                    public double transform(Object o) {
064:                        return Double.parseDouble(((Bar) o).heresBar());
065:                    }
066:
067:                });
068:
069:            }
070:
071:            public void setUp() {
072:            }
073:
074:            public static Test suite() {
075:                TestSuite suite = new TestSuite(
076:                        MixedListUnivariateImplTest.class);
077:                suite.setName("Mixed List Tests");
078:                return suite;
079:            }
080:
081:            /** test stats */
082:            public void testStats() {
083:                List externalList = new ArrayList();
084:
085:                DescriptiveStatistics u = new ListUnivariateImpl(externalList,
086:                        transformers);
087:
088:                assertEquals("total count", 0, u.getN(), tolerance);
089:                u.addValue(one);
090:                u.addValue(two);
091:                u.addValue(two);
092:                u.addValue(three);
093:                assertEquals("N", n, u.getN(), tolerance);
094:                assertEquals("sum", sum, u.getSum(), tolerance);
095:                assertEquals("sumsq", sumSq, u.getSumsq(), tolerance);
096:                assertEquals("var", var, u.getVariance(), tolerance);
097:                assertEquals("std", std, u.getStandardDeviation(), tolerance);
098:                assertEquals("mean", mean, u.getMean(), tolerance);
099:                assertEquals("min", min, u.getMin(), tolerance);
100:                assertEquals("max", max, u.getMax(), tolerance);
101:                u.clear();
102:                assertEquals("total count", 0, u.getN(), tolerance);
103:            }
104:
105:            public void testN0andN1Conditions() throws Exception {
106:                List list = new ArrayList();
107:
108:                DescriptiveStatistics u = new ListUnivariateImpl(
109:                        new ArrayList(), transformers);
110:
111:                assertTrue("Mean of n = 0 set should be NaN", Double.isNaN(u
112:                        .getMean()));
113:                assertTrue("Standard Deviation of n = 0 set should be NaN",
114:                        Double.isNaN(u.getStandardDeviation()));
115:                assertTrue("Variance of n = 0 set should be NaN", Double
116:                        .isNaN(u.getVariance()));
117:
118:                u.addValue(one);
119:
120:                assertTrue(
121:                        "Mean of n = 1 set should be value of single item n1, instead it is "
122:                                + u.getMean(), u.getMean() == one);
123:
124:                assertTrue(
125:                        "StdDev of n = 1 set should be zero, instead it is: "
126:                                + u.getStandardDeviation(), u
127:                                .getStandardDeviation() == 0);
128:                assertTrue("Variance of n = 1 set should be zero", u
129:                        .getVariance() == 0);
130:            }
131:
132:            public void testSkewAndKurtosis() {
133:                ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList(),
134:                        transformers);
135:
136:                u.addObject("12.5");
137:                u.addObject(new Integer(12));
138:                u.addObject("11.8");
139:                u.addObject("14.2");
140:                u.addObject(new Foo());
141:                u.addObject("14.5");
142:                u.addObject(new Long(21));
143:                u.addObject("8.2");
144:                u.addObject("10.3");
145:                u.addObject("11.3");
146:                u.addObject(new Float(14.1));
147:                u.addObject("9.9");
148:                u.addObject("12.2");
149:                u.addObject(new Bar());
150:                u.addObject("12.1");
151:                u.addObject("11");
152:                u.addObject(new Double(19.8));
153:                u.addObject("11");
154:                u.addObject("10");
155:                u.addObject("8.8");
156:                u.addObject("9");
157:                u.addObject("12.3");
158:
159:                assertEquals("mean", 12.40455, u.getMean(), 0.0001);
160:                assertEquals("variance", 10.00236, u.getVariance(), 0.0001);
161:                assertEquals("skewness", 1.437424, u.getSkewness(), 0.0001);
162:                assertEquals("kurtosis", 2.37719, u.getKurtosis(), 0.0001);
163:            }
164:
165:            public void testProductAndGeometricMean() throws Exception {
166:                ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList(),
167:                        transformers);
168:                u.setWindowSize(10);
169:
170:                u.addValue(1.0);
171:                u.addValue(2.0);
172:                u.addValue(3.0);
173:                u.addValue(4.0);
174:
175:                assertEquals("Geometric mean not expected", 2.213364, u
176:                        .getGeometricMean(), 0.00001);
177:
178:                // Now test rolling - StorelessDescriptiveStatistics should discount the contribution
179:                // of a discarded element
180:                for (int i = 0; i < 10; i++) {
181:                    u.addValue(i + 2);
182:                }
183:                // Values should be (2,3,4,5,6,7,8,9,10,11)
184:                assertEquals("Geometric mean not expected", 5.755931, u
185:                        .getGeometricMean(), 0.00001);
186:
187:            }
188:
189:            public final class Foo {
190:                public String heresFoo() {
191:                    return "14.9";
192:                }
193:            }
194:
195:            public final class Bar {
196:                public String heresBar() {
197:                    return "12.0";
198:                }
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.