Source Code Cross Referenced for StatisticalRuleTest.java in  » Code-Analyzer » pmd-4.2rc1 » test » net » sourceforge » pmd » stat » 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 » Code Analyzer » pmd 4.2rc1 » test.net.sourceforge.pmd.stat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * <copyright>
003:         *  Copyright 1997-2002 BBNT Solutions, LLC
004:         *  under sponsorship of the Defense Advanced Research Projects Agency (DARPA).
005:         *
006:         *  This program is free software; you can redistribute it and/or modify
007:         *  it under the terms of the Cougaar Open Source License as published by
008:         *  DARPA on the Cougaar Open Source Website (www.cougaar.org).
009:         *
010:         *  THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
011:         *  PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
012:         *  IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
013:         *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
014:         *  ANY WARRANTIES AS TO NON-INFRINGEMENT.  IN NO EVENT SHALL COPYRIGHT
015:         *  HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
016:         *  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
017:         *  TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
018:         *  PERFORMANCE OF THE COUGAAR SOFTWARE.
019:         * </copyright>
020:         *
021:         * Created on Aug 26, 2002
022:         */package test.net.sourceforge.pmd.stat;
023:
024:        import static org.junit.Assert.assertEquals;
025:        import static org.junit.Assert.assertTrue;
026:        import net.sourceforge.pmd.Report;
027:        import net.sourceforge.pmd.Rule;
028:        import net.sourceforge.pmd.RuleContext;
029:        import net.sourceforge.pmd.ast.SimpleJavaNode;
030:        import net.sourceforge.pmd.ast.SimpleNode;
031:        import net.sourceforge.pmd.stat.DataPoint;
032:        import net.sourceforge.pmd.stat.Metric;
033:        import net.sourceforge.pmd.stat.StatisticalRule;
034:        import net.sourceforge.pmd.symboltable.SourceFileScope;
035:
036:        import org.junit.Before;
037:        import org.junit.Test;
038:
039:        import java.util.ArrayList;
040:        import java.util.Collections;
041:        import java.util.Iterator;
042:        import java.util.List;
043:        import java.util.Random;
044:
045:        import junit.framework.AssertionFailedError;
046:
047:        /**
048:         * This class tests the Statistical Rules in PMD.
049:         * <p/>
050:         * The idea is, that we fill up 999 datapoints into
051:         * the Stat Rule, and then throw random parameters
052:         * at it.
053:         * <p/>
054:         * The three parameters which are checked are:
055:         * sigma - # Sigmas over the mean.
056:         * topscore - Only the top 5 or so items.
057:         * minimum - Only things of score 10 or better
058:         * <p/>
059:         * When more than one parameter is lumped together, then
060:         * we expect the one which would return the fewest to
061:         * determine what gets sent back.
062:         * <p/>
063:         * So, we throw each collection of parameters, where each
064:         * one is a different order into the system.  We check the
065:         * results off of what the smallest value should be.
066:         * <p/>
067:         * If you are going to work with StatisticalRule any, please
068:         * bump the "NUM_TESTS" number up to something like 128.  That
069:         * way you are more likely to identify problems.  It is set low
070:         * now to make building and running tests easier (when we aren't
071:         * touching the file.)
072:         * <p/>
073:         * Note also, that when verifying the Sigma, I wasn't quite able
074:         * to determine how many results it would return (it would vary
075:         * from -2 to 2 of what I expected.)  That is what the delta
076:         * parameter on the verify method takes.  If you can figure it
077:         * out exactly, (without stealing code from the StatRule) then
078:         * feel free to change it and tighten the deltas.
079:         */
080:        public class StatisticalRuleTest {
081:
082:            private static final int POINTS = 100;
083:
084:            private DataPoint points[] = new DataPoint[POINTS];
085:            private MockStatisticalRule IUT = null;
086:            private String testName = "";//FIXME - why/when was this added. It was never set.
087:            private Random random = new Random();
088:
089:            public static final double MAX_MINIMUM = POINTS;
090:            public static final double NO_MINIMUM = -1.0;
091:            public static final double MAX_SIGMA = 5.0;
092:            public static final double NO_SIGMA = -1.0;
093:            public static final int MIN_TOPSCORE = 0;
094:            public static final int NO_TOPSCORE = -1;
095:
096:            public static final double MEAN = 49.5;
097:            public static final double SIGMA = 29.0115;
098:            public static final int NUM_TESTS = 1;
099:
100:            public static final double DELTA = 0.005;
101:
102:            @Before
103:            public void setUp() {
104:                IUT = new MockStatisticalRule();
105:                if (testName.endsWith("0")) {
106:                    for (int i = 0; i < POINTS; i++) {
107:                        points[i] = new DataPoint();
108:                        points[i].setScore(1.0 * i);
109:                        SimpleNode s = new SimpleJavaNode(1);
110:                        s.setScope(new SourceFileScope("foo"));
111:                        s.testingOnly__setBeginLine(i);
112:                        s.testingOnly__setBeginColumn(1);
113:                        points[i].setNode(s);
114:                        points[i].setMessage("DataPoint[" + Integer.toString(i)
115:                                + "]");
116:
117:                        IUT.addDataPoint(points[i]);
118:                    }
119:                } else if (testName.endsWith("1")) {
120:                    for (int i = POINTS - 1; i >= 0; i--) {
121:                        points[i] = new DataPoint();
122:                        points[i].setScore(1.0 * i);
123:                        SimpleNode s = new SimpleJavaNode(1);
124:                        s.setScope(new SourceFileScope("foo"));
125:                        s.testingOnly__setBeginLine(i);
126:                        s.testingOnly__setBeginColumn(1);
127:                        points[i].setNode(s);
128:                        points[i].setMessage("DataPoint[" + Integer.toString(i)
129:                                + "]");
130:
131:                        IUT.addDataPoint(points[i]);
132:                    }
133:                } else {
134:                    List<DataPoint> lPoints = new ArrayList<DataPoint>();
135:                    for (int i = 0; i < POINTS; i++) {
136:                        points[i] = new DataPoint();
137:                        points[i].setScore(1.0 * i);
138:                        SimpleNode s = new SimpleJavaNode(1);
139:                        s.setScope(new SourceFileScope("foo"));
140:                        s.testingOnly__setBeginLine(i);
141:                        s.testingOnly__setBeginColumn(1);
142:                        s.testingOnly__setBeginColumn(1);
143:                        points[i].setNode(s);
144:                        points[i].setMessage("DataPoint[" + Integer.toString(i)
145:                                + "]");
146:
147:                        lPoints.add(points[i]);
148:                    }
149:
150:                    Collections.shuffle(lPoints);
151:                    for (int i = 0; i < POINTS; i++) {
152:                        IUT.addDataPoint(lPoints.get(i));
153:                    }
154:                }
155:
156:            }
157:
158:            /**
159:             * This test verifies that the Stat rule creates a Metric,
160:             * with the proper values.
161:             */
162:            @Test
163:            public void testMetrics() throws Throwable {
164:                Report report = makeReport(IUT);
165:                Iterator metrics = report.metrics();
166:
167:                assertTrue(metrics.hasNext());
168:                Object o = metrics.next();
169:
170:                assertTrue(o instanceof  Metric);
171:                Metric m = (Metric) o;
172:
173:                assertEquals(
174:                        "test.net.sourceforge.pmd.stat.MockStatisticalRule", m
175:                                .getMetricName());
176:
177:                assertEquals(0.0, m.getLowValue(), 0.05);
178:                assertEquals(POINTS - 1.0, m.getHighValue(), 0.05);
179:                assertEquals(MEAN, m.getAverage(), 0.05);
180:                assertEquals(SIGMA, m.getStandardDeviation(), 0.05);
181:            }
182:
183:            /**
184:             * This returns a Random value for Sigma which will
185:             * return some values.
186:             */
187:            public double randomSigma() {
188:                return random.nextDouble() * 1.0;
189:            }
190:
191:            /**
192:             * This returns a Random value for Sigma which value
193:             * is greater than the parameter.
194:             */
195:            public double randomSigma(int minimum) {
196:                double minSigma = ((POINTS - 1 - minimum) - MEAN) / SIGMA;
197:
198:                if ((minSigma <= 0) || (minSigma > 2))
199:                    return randomSigma();
200:
201:                return minSigma + (random.nextDouble() * (2 - minSigma));
202:            }
203:
204:            /**
205:             * This returns the expected number of results when
206:             * the Sigma rating is the smallest.
207:             */
208:            public int expectedSigma(double sigma) {
209:                long expectedMin = Math.round(MEAN + (sigma * SIGMA));
210:
211:                if (((POINTS - 1) - expectedMin) < 0)
212:                    return 0;
213:                return (POINTS - 1) - (int) expectedMin;
214:            }
215:
216:            /**
217:             * This generates a random minimum value for testing.
218:             */
219:            public double randomMinimum() {
220:                return random.nextDouble() * (POINTS - 1);
221:            }
222:
223:            /**
224:             * This generates a random minimum value for which fewer
225:             * results would be returned.
226:             */
227:            public double randomMinimum(int minimum) {
228:                double diffTarget = 1.0 * (POINTS - 1 - minimum);
229:                return (random.nextDouble() * minimum) + diffTarget;
230:            }
231:
232:            /**
233:             * This returns the expected number of reports.
234:             * <p/>
235:             * If the Minimum comes in at 521.569 then we expect
236:             * 522, 523, ... 999 will pass.
237:             */
238:            public int expectedMinimum(double minimum) {
239:                Double d = new Double(minimum);
240:                return POINTS - 1 - d.intValue();
241:            }
242:
243:            @Test
244:            public void testExpectedMinimum() {
245:                for (int i = 0; i < POINTS - 1; i++) {
246:                    assertEquals("Integer Min", POINTS - 1 - i,
247:                            expectedMinimum(i * 1.0));
248:                    assertEquals("Double Min", POINTS - 1 - i,
249:                            expectedMinimum((i * 1.0) + 0.5));
250:                }
251:            }
252:
253:            /**
254:             * This returns a random value for Top Score.
255:             */
256:            public int randomTopScore() {
257:                return random.nextInt(POINTS - 1);
258:            }
259:
260:            /**
261:             * This will return a random value for the Top Score
262:             * which will return more than the minimum provided.
263:             */
264:            public int randomTopScore(double target) {
265:                if (target < 0)
266:                    return 0;
267:
268:                return random.nextInt((new Double(target)).intValue());
269:            }
270:
271:            /**
272:             * This will return the expected number of results
273:             * with the given Top Score.
274:             */
275:            public int expectedTopScore(int target) {
276:                return target;
277:            }
278:
279:            // Test Single Datapoint
280:            @Test
281:            public void testSingleDatapoint() {
282:                StatisticalRule IUT = new MockStatisticalRule();
283:
284:                DataPoint point = new DataPoint();
285:                point.setScore(POINTS + 1.0);
286:                SimpleNode s = new SimpleJavaNode(1);
287:                s.setScope(new SourceFileScope("foo"));
288:                s.testingOnly__setBeginLine(POINTS + 1);
289:                s.testingOnly__setBeginColumn(1);
290:                point.setNode(s);
291:                point.setMessage("SingleDataPoint");
292:
293:                IUT.addProperty("minimum", Integer.toString(POINTS));
294:
295:                IUT.addDataPoint(point);
296:
297:                Report report = makeReport(IUT);
298:
299:                assertEquals("Expecting only one result.", 1, report.size());
300:            }
301:
302:            // Okay, we have three properties we need to
303:            // test in Combination:
304:            //  S = Sigma
305:            //  T = Top Score
306:            //  M = Minimum
307:            //
308:            // They are listed in decreasing order of what
309:            // to expect.
310:            //
311:            // Thus testSM() should have the Sigma less than
312:            // the minimum, so we expect the Minimum # of results.
313:            //
314:
315:            @Test
316:            public void testS() throws Throwable {
317:                verifyResults(MAX_SIGMA, NO_MINIMUM, NO_TOPSCORE, 0, 2);
318:
319:                for (int i = 0; i < NUM_TESTS; i++) {
320:                    double sigma = randomSigma();
321:                    verifyResults(sigma, -1.0, -1, expectedSigma(sigma), 2);
322:                }
323:            }
324:
325:            @Test
326:            public void testS1() throws Throwable {
327:                testS();
328:            }
329:
330:            @Test
331:            public void testS2() throws Throwable {
332:                testS();
333:            }
334:
335:            @Test
336:            public void testS3() throws Throwable {
337:                testS();
338:            }
339:
340:            @Test
341:            public void testS4() throws Throwable {
342:                testS();
343:            }
344:
345:            @Test
346:            public void testS5() throws Throwable {
347:                testS();
348:            }
349:
350:            @Test
351:            public void testT() throws Throwable {
352:                verifyResults(NO_SIGMA, NO_MINIMUM, MIN_TOPSCORE, 0, 0);
353:
354:                for (int i = 0; i < NUM_TESTS; i++) {
355:                    int topScore = randomTopScore();
356:                    verifyResults(-1.0, -1.0, topScore,
357:                            expectedTopScore(topScore), 0);
358:                }
359:            }
360:
361:            @Test
362:            public void testT1() throws Throwable {
363:                testT();
364:            }
365:
366:            @Test
367:            public void testT2() throws Throwable {
368:                testT();
369:            }
370:
371:            @Test
372:            public void testT3() throws Throwable {
373:                testT();
374:            }
375:
376:            @Test
377:            public void testT4() throws Throwable {
378:                testT();
379:            }
380:
381:            @Test
382:            public void testT5() throws Throwable {
383:                testT();
384:            }
385:
386:            @Test
387:            public void testM() throws Throwable {
388:                verifyResults(NO_SIGMA, MAX_MINIMUM, NO_TOPSCORE, 0, 0);
389:
390:                for (int i = 0; i < NUM_TESTS; i++) {
391:                    double minimum = randomMinimum();
392:                    verifyResults(-1.0, minimum, -1, expectedMinimum(minimum),
393:                            0);
394:                }
395:            }
396:
397:            @Test
398:            public void testM1() throws Throwable {
399:                testM();
400:            }
401:
402:            @Test
403:            public void testM2() throws Throwable {
404:                testM();
405:            }
406:
407:            @Test
408:            public void testM3() throws Throwable {
409:                testM();
410:            }
411:
412:            @Test
413:            public void testM4() throws Throwable {
414:                testM();
415:            }
416:
417:            @Test
418:            public void testM5() throws Throwable {
419:                testM();
420:            }
421:
422:            @Test
423:            public void testST() throws Throwable {
424:                verifyResults(randomSigma(), NO_MINIMUM, MIN_TOPSCORE, 0, 0);
425:
426:                for (int i = 0; i < NUM_TESTS; i++) {
427:                    double sigma = randomSigma();
428:                    int topScore = randomTopScore(expectedSigma(sigma));
429:
430:                    verifyResults(sigma, NO_MINIMUM, topScore,
431:                            expectedTopScore(topScore), 0);
432:                }
433:            }
434:
435:            @Test
436:            public void testST1() throws Throwable {
437:                testST();
438:            }
439:
440:            @Test
441:            public void testST2() throws Throwable {
442:                testST();
443:            }
444:
445:            @Test
446:            public void testST3() throws Throwable {
447:                testST();
448:            }
449:
450:            @Test
451:            public void testST4() throws Throwable {
452:                testST();
453:            }
454:
455:            @Test
456:            public void testST5() throws Throwable {
457:                testST();
458:            }
459:
460:            @Test
461:            public void testTS() throws Throwable {
462:                verifyResults(MAX_SIGMA, NO_MINIMUM, randomTopScore(), 0, 0);
463:
464:                for (int i = 0; i < NUM_TESTS; i++) {
465:                    int topScore = randomTopScore();
466:                    double sigma = randomSigma(expectedTopScore(topScore));
467:
468:                    verifyResults(sigma, -1.0, topScore, expectedSigma(sigma),
469:                            2);
470:                }
471:            }
472:
473:            @Test
474:            public void testTS1() throws Throwable {
475:                testTS();
476:            }
477:
478:            @Test
479:            public void testTS2() throws Throwable {
480:                testTS();
481:            }
482:
483:            @Test
484:            public void testTS3() throws Throwable {
485:                testTS();
486:            }
487:
488:            @Test
489:            public void testTS4() throws Throwable {
490:                testTS();
491:            }
492:
493:            @Test
494:            public void testTS5() throws Throwable {
495:                testTS();
496:            }
497:
498:            @Test
499:            public void testSM() throws Throwable {
500:                verifyResults(randomSigma(), MAX_MINIMUM, NO_TOPSCORE, 0, 0);
501:                for (int i = 0; i < NUM_TESTS; i++) {
502:                    double sigma = randomSigma();
503:                    double minimum = randomMinimum(expectedSigma(sigma));
504:
505:                    verifyResults(sigma, minimum, -1, expectedMinimum(minimum),
506:                            0);
507:                }
508:
509:            }
510:
511:            @Test
512:            public void testSM1() throws Throwable {
513:                testSM();
514:            }
515:
516:            @Test
517:            public void testSM2() throws Throwable {
518:                testSM();
519:            }
520:
521:            @Test
522:            public void testSM3() throws Throwable {
523:                testSM();
524:            }
525:
526:            @Test
527:            public void testSM4() throws Throwable {
528:                testSM();
529:            }
530:
531:            @Test
532:            public void testSM5() throws Throwable {
533:                testSM();
534:            }
535:
536:            @Test
537:            public void testMS() throws Throwable {
538:                verifyResults(MAX_SIGMA, randomMinimum(), NO_TOPSCORE, 0, 0);
539:                for (int i = 0; i < NUM_TESTS; i++) {
540:                    double minimum = randomMinimum();
541:                    double sigma = randomSigma(expectedMinimum(minimum));
542:
543:                    verifyResults(sigma, minimum, -1, expectedSigma(sigma), 2);
544:                }
545:            }
546:
547:            @Test
548:            public void testMS1() throws Throwable {
549:                testMS();
550:            }
551:
552:            @Test
553:            public void testMS2() throws Throwable {
554:                testMS();
555:            }
556:
557:            @Test
558:            public void testMS3() throws Throwable {
559:                testMS();
560:            }
561:
562:            @Test
563:            public void testMS4() throws Throwable {
564:                testMS();
565:            }
566:
567:            @Test
568:            public void testMS5() throws Throwable {
569:                testMS();
570:            }
571:
572:            @Test
573:            public void testTM() throws Throwable {
574:                verifyResults(NO_SIGMA, MAX_MINIMUM, randomTopScore(), 0, 0);
575:                for (int i = 0; i < NUM_TESTS; i++) {
576:                    int topScore = randomTopScore();
577:                    double minimum = randomMinimum(expectedTopScore(topScore));
578:
579:                    verifyResults(NO_SIGMA, minimum, topScore,
580:                            expectedMinimum(minimum), 0);
581:                }
582:            }
583:
584:            @Test
585:            public void testTM1() throws Throwable {
586:                testTM();
587:            }
588:
589:            @Test
590:            public void testTM2() throws Throwable {
591:                testTM();
592:            }
593:
594:            @Test
595:            public void testTM3() throws Throwable {
596:                testTM();
597:            }
598:
599:            @Test
600:            public void testTM4() throws Throwable {
601:                testTM();
602:            }
603:
604:            @Test
605:            public void testTM5() throws Throwable {
606:                testTM();
607:            }
608:
609:            @Test
610:            public void testMT() throws Throwable {
611:                verifyResults(NO_SIGMA, randomMinimum(), MIN_TOPSCORE, 0, 0);
612:                for (int i = 0; i < NUM_TESTS; i++) {
613:                    double minimum = randomMinimum();
614:                    int topScore = randomTopScore(expectedMinimum(minimum));
615:
616:                    verifyResults(NO_SIGMA, minimum, topScore,
617:                            expectedTopScore(topScore), 0);
618:                }
619:            }
620:
621:            @Test
622:            public void testMT1() throws Throwable {
623:                testMT();
624:            }
625:
626:            @Test
627:            public void testMT2() throws Throwable {
628:                testMT();
629:            }
630:
631:            @Test
632:            public void testMT3() throws Throwable {
633:                testMT();
634:            }
635:
636:            @Test
637:            public void testMT4() throws Throwable {
638:                testMT();
639:            }
640:
641:            @Test
642:            public void testMT5() throws Throwable {
643:                testMT();
644:            }
645:
646:            @Test
647:            public void testSTM() throws Throwable {
648:                double sigma = randomSigma();
649:                verifyResults(sigma, MAX_MINIMUM,
650:                        randomTopScore(expectedSigma(sigma)), 0, 0);
651:
652:                for (int i = 0; i < NUM_TESTS; i++) {
653:                    sigma = randomSigma();
654:                    int topScore = randomTopScore(expectedSigma(sigma));
655:                    double minimum = randomMinimum(expectedTopScore(topScore));
656:
657:                    verifyResults(sigma, minimum, topScore,
658:                            expectedMinimum(minimum), 0);
659:                }
660:            }
661:
662:            @Test
663:            public void testSTM1() throws Throwable {
664:                testSTM();
665:            }
666:
667:            @Test
668:            public void testSTM2() throws Throwable {
669:                testSTM();
670:            }
671:
672:            @Test
673:            public void testSTM3() throws Throwable {
674:                testSTM();
675:            }
676:
677:            @Test
678:            public void testSTM4() throws Throwable {
679:                testSTM();
680:            }
681:
682:            @Test
683:            public void testSTM5() throws Throwable {
684:                testSTM();
685:            }
686:
687:            @Test
688:            public void testSMT() throws Throwable {
689:                double sigma = randomSigma();
690:                verifyResults(sigma, randomMinimum(expectedSigma(sigma)),
691:                        MIN_TOPSCORE, 0, 0);
692:
693:                for (int i = 0; i < NUM_TESTS; i++) {
694:                    sigma = randomSigma();
695:                    double minimum = randomMinimum(expectedSigma(sigma));
696:                    int topScore = randomTopScore(expectedMinimum(minimum));
697:
698:                    verifyResults(sigma, minimum, topScore,
699:                            expectedTopScore(topScore), 0);
700:                }
701:            }
702:
703:            @Test
704:            public void testSMT1() throws Throwable {
705:                testSMT();
706:            }
707:
708:            @Test
709:            public void testSMT2() throws Throwable {
710:                testSMT();
711:            }
712:
713:            @Test
714:            public void testSMT3() throws Throwable {
715:                testSMT();
716:            }
717:
718:            @Test
719:            public void testSMT4() throws Throwable {
720:                testSMT();
721:            }
722:
723:            @Test
724:            public void testSMT5() throws Throwable {
725:                testSMT();
726:            }
727:
728:            @Test
729:            public void testTSM() throws Throwable {
730:                int topScore = randomTopScore();
731:                verifyResults(randomSigma(expectedTopScore(topScore)),
732:                        MAX_MINIMUM, topScore, 0, 0);
733:
734:                for (int i = 0; i < NUM_TESTS; i++) {
735:                    topScore = randomTopScore();
736:                    double sigma = randomSigma(expectedTopScore(topScore));
737:                    double minimum = randomMinimum(expectedSigma(sigma));
738:
739:                    verifyResults(sigma, minimum, topScore,
740:                            expectedMinimum(minimum), 0);
741:                }
742:            }
743:
744:            @Test
745:            public void testTSM1() throws Throwable {
746:                testTSM();
747:            }
748:
749:            @Test
750:            public void testTSM2() throws Throwable {
751:                testTSM();
752:            }
753:
754:            @Test
755:            public void testTSM3() throws Throwable {
756:                testTSM();
757:            }
758:
759:            @Test
760:            public void testTSM4() throws Throwable {
761:                testTSM();
762:            }
763:
764:            @Test
765:            public void testTSM5() throws Throwable {
766:                testTSM();
767:            }
768:
769:            @Test
770:            public void testTMS() throws Throwable {
771:                int topScore = randomTopScore();
772:                verifyResults(MAX_SIGMA,
773:                        randomMinimum(expectedTopScore(topScore)), topScore, 0,
774:                        0);
775:
776:                for (int i = 0; i < NUM_TESTS; i++) {
777:                    topScore = randomTopScore();
778:                    double minimum = randomMinimum(expectedTopScore(topScore));
779:                    double sigma = randomSigma(expectedMinimum(minimum));
780:
781:                    verifyResults(sigma, minimum, topScore,
782:                            expectedSigma(sigma), 2);
783:                }
784:            }
785:
786:            @Test
787:            public void testTMS1() throws Throwable {
788:                testTMS();
789:            }
790:
791:            @Test
792:            public void testTMS2() throws Throwable {
793:                testTMS();
794:            }
795:
796:            @Test
797:            public void testTMS3() throws Throwable {
798:                testTMS();
799:            }
800:
801:            @Test
802:            public void testTMS4() throws Throwable {
803:                testTMS();
804:            }
805:
806:            @Test
807:            public void testTMS5() throws Throwable {
808:                testTMS();
809:            }
810:
811:            /**
812:             * Verifies what happens when you pass these parameters
813:             * into the thing.  DELTA is the amount of error allowed.
814:             * Usually DELTA is only used for Sigma, as we really can't
815:             * calculate it exactly.
816:             */
817:
818:            public void verifyResults(double sigma, double minimum,
819:                    int topScore, int expected, int delta) {
820:                try {
821:                    setUp();
822:                    if (sigma >= 0) {
823:                        IUT.addProperty("sigma", Double.toString(sigma));
824:                    }
825:
826:                    if (minimum >= 0) {
827:                        IUT.addProperty("minimum", Double.toString(minimum));
828:                    }
829:
830:                    if (topScore >= 0) {
831:                        IUT.addProperty("topscore", Integer.toString(topScore));
832:                    }
833:
834:                    Report report = makeReport(IUT);
835:                    if (delta == 0) {
836:                        assertEquals("Unexpected number of results: sigma= "
837:                                + Double.toString(sigma) + " min= "
838:                                + Double.toString(minimum) + " topscore= "
839:                                + Integer.toString(topScore), expected, report
840:                                .size());
841:                    } else {
842:                        String assertStr = "Unexpected number of results: sigma= "
843:                                + Double.toString(sigma)
844:                                + " min= "
845:                                + Double.toString(minimum)
846:                                + " topscore= "
847:                                + Integer.toString(topScore)
848:                                + " expected= "
849:                                + Integer.toString(expected)
850:                                + " +/- "
851:                                + Integer.toString(delta)
852:                                + " actual-result= "
853:                                + report.size();
854:
855:                        assertTrue(assertStr,
856:                                report.size() >= (expected - delta));
857:                        assertTrue(assertStr,
858:                                report.size() <= (expected + delta));
859:                    }
860:                } catch (AssertionFailedError afe) {
861:                    System.err.println("******** " + testName + " ***********");
862:                    if (sigma != NO_SIGMA) {
863:                        System.err.println("SIGMA: " + Double.toString(sigma)
864:                                + " EXPECT: "
865:                                + Integer.toString(expectedSigma(sigma)));
866:                    }
867:
868:                    if (minimum != NO_MINIMUM) {
869:                        System.err.println("MIN: " + Double.toString(minimum)
870:                                + " EXPECT: "
871:                                + Integer.toString(expectedMinimum(minimum)));
872:                    }
873:
874:                    if (topScore != NO_TOPSCORE) {
875:                        System.err.println("TOP: " + Integer.toString(topScore)
876:                                + " EXPECT: "
877:                                + Integer.toString(expectedTopScore(topScore)));
878:                    }
879:
880:                    throw afe;
881:
882:                }
883:            }
884:
885:            public Report makeReport(Rule IUT) {
886:                List list = new ArrayList();
887:                Report report = new Report();
888:
889:                RuleContext ctx = new RuleContext();
890:                ctx.setReport(report);
891:                ctx.setSourceCodeFilename(testName);
892:
893:                IUT.apply(list, ctx);
894:
895:                return report;
896:            }
897:
898:            public static junit.framework.Test suite() {
899:                return new junit.framework.JUnit4TestAdapter(
900:                        StatisticalRuleTest.class);
901:            }
902:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.