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


001:        /*
002:         * Copyright 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.distribution;
017:
018:        import junit.framework.TestCase;
019:
020:        /**
021:         * Abstract base class for {@link IntegerDistribution} tests.
022:         * <p>
023:         * To create a concrete test class for an integer distribution implementation,
024:         *  implement makeDistribution() to return a distribution instance to use in 
025:         *  tests and each of the test data generation methods below.  In each case, the
026:         *  test points and test values arrays returned represent parallel arrays of 
027:         *  inputs and expected values for the distribution returned by makeDistribution().
028:         *  <p>
029:         *  makeDensityTestPoints() -- arguments used to test probability density calculation
030:         *  makeDensityTestValues() -- expected probability densities
031:         *  makeCumulativeTestPoints() -- arguments used to test cumulative probabilities
032:         *  makeCumulativeTestValues() -- expected cumulative probabilites
033:         *  makeInverseCumulativeTestPoints() -- arguments used to test inverse cdf evaluation
034:         *  makeInverseCumulativeTestValues() -- expected inverse cdf values
035:         * <p>
036:         *  To implement additional test cases with different distribution instances and test data,
037:         *  use the setXxx methods for the instance data in test cases and call the verifyXxx methods
038:         *  to verify results. 
039:         * 
040:         * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
041:         */
042:        public abstract class IntegerDistributionAbstractTest extends TestCase {
043:
044:            //-------------------- Private test instance data -------------------------
045:            /** Discrete distribution instance used to perform tests */
046:            private IntegerDistribution distribution;
047:
048:            /** Tolerance used in comparing expected and returned values */
049:            private double tolerance = 1E-4;
050:
051:            /** Arguments used to test probability density calculations */
052:            private int[] densityTestPoints;
053:
054:            /** Values used to test probability density calculations */
055:            private double[] densityTestValues;
056:
057:            /** Arguments used to test cumulative probability density calculations */
058:            private int[] cumulativeTestPoints;
059:
060:            /** Values used to test cumulative probability density calculations */
061:            private double[] cumulativeTestValues;
062:
063:            /** Arguments used to test inverse cumulative probability density calculations */
064:            private double[] inverseCumulativeTestPoints;
065:
066:            /** Values used to test inverse cumulative probability density calculations */
067:            private int[] inverseCumulativeTestValues;
068:
069:            //-------------------------------------------------------------------------
070:
071:            /**
072:             * Constructor for IntegerDistributionAbstractTest.
073:             * @param name
074:             */
075:            public IntegerDistributionAbstractTest(String name) {
076:                super (name);
077:            }
078:
079:            //-------------------- Abstract methods -----------------------------------
080:
081:            /** Creates the default discrete distribution instance to use in tests. */
082:            public abstract IntegerDistribution makeDistribution();
083:
084:            /** Creates the default probability density test input values */
085:            public abstract int[] makeDensityTestPoints();
086:
087:            /** Creates the default probability density test expected values */
088:            public abstract double[] makeDensityTestValues();
089:
090:            /** Creates the default cumulative probability density test input values */
091:            public abstract int[] makeCumulativeTestPoints();
092:
093:            /** Creates the default cumulative probability density test expected values */
094:            public abstract double[] makeCumulativeTestValues();
095:
096:            /** Creates the default inverse cumulative probability test input values */
097:            public abstract double[] makeInverseCumulativeTestPoints();
098:
099:            /** Creates the default inverse cumulative probability density test expected values */
100:            public abstract int[] makeInverseCumulativeTestValues();
101:
102:            //-------------------- Setup / tear down ----------------------------------
103:
104:            /**
105:             * Setup sets all test instance data to default values 
106:             */
107:            protected void setUp() throws Exception {
108:                super .setUp();
109:                distribution = makeDistribution();
110:                densityTestPoints = makeDensityTestPoints();
111:                densityTestValues = makeDensityTestValues();
112:                cumulativeTestPoints = makeCumulativeTestPoints();
113:                cumulativeTestValues = makeCumulativeTestValues();
114:                inverseCumulativeTestPoints = makeInverseCumulativeTestPoints();
115:                inverseCumulativeTestValues = makeInverseCumulativeTestValues();
116:            }
117:
118:            /**
119:             * Cleans up test instance data
120:             */
121:            protected void tearDown() throws Exception {
122:                super .tearDown();
123:                distribution = null;
124:                densityTestPoints = null;
125:                densityTestValues = null;
126:                cumulativeTestPoints = null;
127:                cumulativeTestValues = null;
128:                inverseCumulativeTestPoints = null;
129:                inverseCumulativeTestValues = null;
130:            }
131:
132:            //-------------------- Verification methods -------------------------------
133:
134:            /**
135:             * Verifies that probability density calculations match exptected values
136:             * using current test instance data
137:             */
138:            protected void verifyDensities() throws Exception {
139:                for (int i = 0; i < densityTestPoints.length; i++) {
140:                    assertEquals("Incorrect density value returned for "
141:                            + densityTestPoints[i], densityTestValues[i],
142:                            distribution.probability(densityTestPoints[i]),
143:                            tolerance);
144:                }
145:            }
146:
147:            /**
148:             * Verifies that cumulative probability density calculations match exptected values
149:             * using current test instance data
150:             */
151:            protected void verifyCumulativeProbabilities() throws Exception {
152:                for (int i = 0; i < cumulativeTestPoints.length; i++) {
153:                    assertEquals(
154:                            "Incorrect cumulative probability value returned for "
155:                                    + cumulativeTestPoints[i],
156:                            cumulativeTestValues[i],
157:                            distribution
158:                                    .cumulativeProbability(cumulativeTestPoints[i]),
159:                            tolerance);
160:                }
161:            }
162:
163:            /**
164:             * Verifies that inverse cumulative probability density calculations match exptected values
165:             * using current test instance data
166:             */
167:            protected void verifyInverseCumulativeProbabilities()
168:                    throws Exception {
169:                for (int i = 0; i < inverseCumulativeTestPoints.length; i++) {
170:                    assertEquals(
171:                            "Incorrect inverse cumulative probability value returned for "
172:                                    + inverseCumulativeTestPoints[i],
173:                            inverseCumulativeTestValues[i],
174:                            distribution
175:                                    .inverseCumulativeProbability(inverseCumulativeTestPoints[i]));
176:                }
177:            }
178:
179:            //------------------------ Default test cases -----------------------------
180:
181:            /**
182:             * Verifies that probability density calculations match exptected values
183:             * using default test instance data
184:             */
185:            public void testDensities() throws Exception {
186:                verifyDensities();
187:            }
188:
189:            /**
190:             * Verifies that cumulative probability density calculations match exptected values
191:             * using default test instance data
192:             */
193:            public void testCumulativeProbabilities() throws Exception {
194:                verifyCumulativeProbabilities();
195:            }
196:
197:            /**
198:             * Verifies that inverse cumulative probability density calculations match exptected values
199:             * using default test instance data
200:             */
201:            public void testInverseCumulativeProbabilities() throws Exception {
202:                verifyInverseCumulativeProbabilities();
203:            }
204:
205:            /**
206:             * Verifies that illegal arguments are correctly handled
207:             */
208:            public void testIllegalArguments() throws Exception {
209:                try {
210:                    distribution.cumulativeProbability(1, 0);
211:                    fail("Expecting IllegalArgumentException for bad cumulativeProbability interval");
212:                } catch (IllegalArgumentException ex) {
213:                    // expected
214:                }
215:                try {
216:                    distribution.inverseCumulativeProbability(-1);
217:                    fail("Expecting IllegalArgumentException for p = -1");
218:                } catch (IllegalArgumentException ex) {
219:                    // expected
220:                }
221:                try {
222:                    distribution.inverseCumulativeProbability(2);
223:                    fail("Expecting IllegalArgumentException for p = 2");
224:                } catch (IllegalArgumentException ex) {
225:                    // expected
226:                }
227:            }
228:
229:            //------------------ Getters / Setters for test instance data -----------
230:            /**
231:             * @return Returns the cumulativeTestPoints.
232:             */
233:            protected int[] getCumulativeTestPoints() {
234:                return cumulativeTestPoints;
235:            }
236:
237:            /**
238:             * @param cumulativeTestPoints The cumulativeTestPoints to set.
239:             */
240:            protected void setCumulativeTestPoints(int[] cumulativeTestPoints) {
241:                this .cumulativeTestPoints = cumulativeTestPoints;
242:            }
243:
244:            /**
245:             * @return Returns the cumulativeTestValues.
246:             */
247:            protected double[] getCumulativeTestValues() {
248:                return cumulativeTestValues;
249:            }
250:
251:            /**
252:             * @param cumulativeTestValues The cumulativeTestValues to set.
253:             */
254:            protected void setCumulativeTestValues(double[] cumulativeTestValues) {
255:                this .cumulativeTestValues = cumulativeTestValues;
256:            }
257:
258:            /**
259:             * @return Returns the densityTestPoints.
260:             */
261:            protected int[] getDensityTestPoints() {
262:                return densityTestPoints;
263:            }
264:
265:            /**
266:             * @param densityTestPoints The densityTestPoints to set.
267:             */
268:            protected void setDensityTestPoints(int[] densityTestPoints) {
269:                this .densityTestPoints = densityTestPoints;
270:            }
271:
272:            /**
273:             * @return Returns the densityTestValues.
274:             */
275:            protected double[] getDensityTestValues() {
276:                return densityTestValues;
277:            }
278:
279:            /**
280:             * @param densityTestValues The densityTestValues to set.
281:             */
282:            protected void setDensityTestValues(double[] densityTestValues) {
283:                this .densityTestValues = densityTestValues;
284:            }
285:
286:            /**
287:             * @return Returns the distribution.
288:             */
289:            protected IntegerDistribution getDistribution() {
290:                return distribution;
291:            }
292:
293:            /**
294:             * @param distribution The distribution to set.
295:             */
296:            protected void setDistribution(IntegerDistribution distribution) {
297:                this .distribution = distribution;
298:            }
299:
300:            /**
301:             * @return Returns the inverseCumulativeTestPoints.
302:             */
303:            protected double[] getInverseCumulativeTestPoints() {
304:                return inverseCumulativeTestPoints;
305:            }
306:
307:            /**
308:             * @param inverseCumulativeTestPoints The inverseCumulativeTestPoints to set.
309:             */
310:            protected void setInverseCumulativeTestPoints(
311:                    double[] inverseCumulativeTestPoints) {
312:                this .inverseCumulativeTestPoints = inverseCumulativeTestPoints;
313:            }
314:
315:            /**
316:             * @return Returns the inverseCumulativeTestValues.
317:             */
318:            protected int[] getInverseCumulativeTestValues() {
319:                return inverseCumulativeTestValues;
320:            }
321:
322:            /**
323:             * @param inverseCumulativeTestValues The inverseCumulativeTestValues to set.
324:             */
325:            protected void setInverseCumulativeTestValues(
326:                    int[] inverseCumulativeTestValues) {
327:                this .inverseCumulativeTestValues = inverseCumulativeTestValues;
328:            }
329:
330:            /**
331:             * @return Returns the tolerance.
332:             */
333:            protected double getTolerance() {
334:                return tolerance;
335:            }
336:
337:            /**
338:             * @param tolerance The tolerance to set.
339:             */
340:            protected void setTolerance(double tolerance) {
341:                this.tolerance = tolerance;
342:            }
343:
344:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.