intermediate/MyTest

From ggc

Jump to: navigation, search

01 package intermediate;
02 
03 
04 public class MyTest extends DefiniteNumericCollectionTest
05 {
06 
07   @Override
08   public void runTests(DefiniteNumericCollection collection)
09   {
10     try
11     {
12       runEmptyTest(collection);
13     }
14     catch(Exception e)
15     {
16       failed.add("Average test for NaN on empty collection (Exception occurred).");
17     }
18     //try
19     //{
20     runOneElementTest(collection);
21     //}
22     //catch(Exception e)
23     //{
24     //  failed.add("Average test for collection {5} (Exception occurred).");
25     //}
26   }
27 
28   private void runEmptyTest(DefiniteNumericCollection collection)
29   {
30     collection.clear();
31     if(Double.isNaN(collection.getAverage().doubleValue()))
32     {
33       passed.add("Average test for NaN on empty collection.");
34     }
35     else
36     {
37       failed.add("Average test for NaN on empty collection.");
38     }
39 
40   }
41 
42   private void runOneElementTest(DefiniteNumericCollection collection)
43   {
44     collection.clear();
45     collection.add(new Integer(5));
46     if(collection.getAverage().intValue()==5)
47     {
48       passed.add("Average test for collection {5}.");
49     }
50     else
51     {
52       failed.add("Average test for collection {5}.");
53     }
54 
55   }
56 
57   /**
58    @param args
59    */
60   public static void main(String[] args)
61   {
62     DefiniteNumericCollectionTest test=new MyTest();
63     DefiniteNumericCollection collection;
64     collection=new MyDefiniteNumericCollection();
65     test.runTests(collection);
66   }
67 
68 }


Download/View intermediate/MyTest.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter