EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.probfunction.math.test]

COVERAGE SUMMARY FOR SOURCE FILE [BoxedPDFTest.java]

nameclass, %method, %block, %line, %
BoxedPDFTest.java100% (1/1)80%  (12/15)76%  (515/682)77%  (56/73)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BoxedPDFTest100% (1/1)80%  (12/15)76%  (515/682)77%  (56/73)
checkConstraints1 (): void 0%   (0/1)0%   (0/48)0%   (0/4)
checkConstraints2 (): void 0%   (0/1)0%   (0/48)0%   (0/4)
mult (): void 0%   (0/1)0%   (0/71)0%   (0/9)
BoxedPDFTest (): void 100% (1/1)100% (6/6)100% (2/2)
add (): void 100% (1/1)100% (59/59)100% (6/6)
arithmeticMean (): void 100% (1/1)100% (14/14)100% (4/4)
checkConstraints (): void 100% (1/1)100% (4/4)100% (2/2)
createBoxedPDF (Double []): IBoxedPDF 100% (1/1)100% (38/38)100% (6/6)
equals (): void 100% (1/1)100% (113/113)100% (9/9)
getMedian (): void 100% (1/1)100% (67/67)100% (5/5)
percentile (): void 100% (1/1)100% (29/29)100% (5/5)
scale (): void 100% (1/1)100% (54/54)100% (5/5)
setUp (): void 100% (1/1)100% (103/103)100% (4/4)
suite (): Test 100% (1/1)100% (5/5)100% (1/1)
timeDomain (): void 100% (1/1)100% (23/23)100% (7/7)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.probfunction.math.test;
5 
6import java.util.ArrayList;
7import java.util.List;
8 
9import junit.framework.Assert;
10import junit.framework.JUnit4TestAdapter;
11 
12import org.junit.Before;
13import org.junit.Ignore;
14import org.junit.Test;
15 
16import de.uka.ipd.sdq.probfunction.math.IBoxedPDF;
17import de.uka.ipd.sdq.probfunction.math.IContinuousSample;
18import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction;
19import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory;
20import de.uka.ipd.sdq.probfunction.math.ISamplePDF;
21import de.uka.ipd.sdq.probfunction.math.exception.DomainNotNumbersException;
22import de.uka.ipd.sdq.probfunction.math.exception.DoubleSampleException;
23import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInTimeDomainException;
24import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException;
25import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException;
26import de.uka.ipd.sdq.probfunction.math.exception.InvalidSampleValueException;
27import de.uka.ipd.sdq.probfunction.math.exception.NegativeDistanceException;
28import de.uka.ipd.sdq.probfunction.math.exception.ProbabilitySumNotOneException;
29import de.uka.ipd.sdq.probfunction.math.exception.UnitNameNotSetException;
30import de.uka.ipd.sdq.probfunction.math.exception.UnitNotSetException;
31import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException;
32import de.uka.ipd.sdq.probfunction.math.exception.UnorderedDomainException;
33 
34/**
35 * @author Ihssane
36 * 
37 */
38public class BoxedPDFTest{
39        private IBoxedPDF df1, df2;
40        private IProbabilityFunctionFactory dfFactory = IProbabilityFunctionFactory.eINSTANCE;
41 
42        private IBoxedPDF createBoxedPDF(Double[] samples)
43                        throws DoubleSampleException {
44                List<IContinuousSample> sList = new ArrayList<IContinuousSample>();
45                for (int i = 0; i < samples.length; i += 2) {
46                        IContinuousSample s = dfFactory.createContinuousSample(samples[i],
47                                        samples[i + 1]);
48                        sList.add(s);
49                }
50                return dfFactory.createBoxedPDF(sList, dfFactory.createDefaultUnit());
51        }
52 
53        @Before
54        public void setUp() throws DoubleSampleException {
55                df1 = createBoxedPDF(new Double[]{3.0, 0.1, 2.1, 0.2, 4.3, 0.4, 1.5, 0.3});
56                df2 = createBoxedPDF(new Double[]{3.0, 0.0, 2.1, 0.2, 2.2, 0.1, 2.5,
57                                0.2, 4.3, 0.3});
58 
59        }
60        
61        @Test
62        public void arithmeticMean() throws DomainNotNumbersException, FunctionNotInTimeDomainException{
63                
64                double meanDf1 = 0.75 * 0.3 + 1.8 * 0.2 + 2.55 * 0.1 + 3.65 * 0.4;
65                System.out.println(df1);
66 
67                Assert.assertEquals(meanDf1, df1.getArithmeticMeanValue());
68                //Assert.assertEquals(2.43, df1.getArithmeticMeanValue());
69        }
70 
71        @Test
72        public void timeDomain() throws FunctionNotInTimeDomainException {
73                Assert.assertTrue(df1.isInTimeDomain());
74                Assert.assertTrue(df2.isInTimeDomain());
75                Assert.assertFalse(df1.isInFrequencyDomain());
76                IProbabilityDensityFunction pdf = df1.getFourierTransform();
77                Assert.assertFalse(pdf.isInTimeDomain());
78                Assert.assertTrue(pdf.isInFrequencyDomain());
79        }
80 
81        @Test
82        public void equals() throws DoubleSampleException {
83                Assert.assertTrue(df1.equals(df1));
84 
85                IBoxedPDF df1copy = createBoxedPDF(new Double[]{3.0, 0.1, 2.1, 0.2,
86                                4.3, 0.4, 1.5, 0.3});
87                Assert.assertTrue(df1.equals(df1copy));
88 
89                Assert.assertFalse(df2.equals(df1));
90                IBoxedPDF df1WrongCopy = createBoxedPDF(new Double[]{2.1, 0.2, 3.0,
91                                0.1, 4.3, 0.4, 1.5, 0.3});
92                Assert.assertTrue(df1.equals(df1WrongCopy));
93        }
94 
95        @Test
96        public void scale() throws DoubleSampleException {
97                IProbabilityDensityFunction df1scale = df1.scale(0.1);
98                IBoxedPDF spdf = createBoxedPDF(new Double[]{3.0, 0.01, 2.1, 0.02, 4.3,
99                                0.04, 1.5, 0.03});
100                Assert.assertEquals(spdf, df1scale);
101        }
102 
103        @Test
104        public void add() throws DoubleSampleException,
105                        FunctionsInDifferenDomainsException, UnknownPDFTypeException,
106                        IncompatibleUnitsException {
107                IProbabilityDensityFunction sum = df1.add(df1);
108                IBoxedPDF sumExpected = createBoxedPDF(new Double[]{3.0, 0.2, 2.1, 0.4,
109                                4.3, 0.8, 1.5, 0.6});
110                Assert.assertEquals(dfFactory.transformToSamplePDF(sumExpected),
111                                (ISamplePDF) sum);
112 
113        }
114 
115        @Test
116        @Ignore
117        public void mult() throws FunctionsInDifferenDomainsException,
118                        UnknownPDFTypeException, IncompatibleUnitsException,
119                        DoubleSampleException {
120                // IProbabilityDensityFunction prod = df1.mult(df1);
121                ISamplePDF df11 = dfFactory.transformToSamplePDF(df1);
122                IProbabilityDensityFunction prod = df11.mult(df11);
123                System.out.println(prod);
124                IBoxedPDF expected = createBoxedPDF(new Double[]{3.0, 0.01, 2.1, 0.04,
125                                4.3, 0.16, 1.5, 0.09});
126                ISamplePDF sExpexted = dfFactory.transformToSamplePDF(expected);
127                System.out.println(sExpexted);
128                Assert.assertEquals(sExpexted, (ISamplePDF) prod);
129        }
130 
131        @Test
132        public void percentile() throws IndexOutOfBoundsException,
133                        UnorderedDomainException {
134                Assert.assertEquals(0.3, df1.getPercentile(10));
135                Assert.assertEquals(0.2, df1.getPercentile(40));
136                Assert.assertEquals(0.1, df1.getPercentile(50));
137                Assert.assertEquals(0.4, df1.getPercentile(99));
138        }
139 
140        @Test
141        public void getMedian() throws UnorderedDomainException,
142                        DoubleSampleException {
143                Assert.assertEquals(2.55, df1.getMedian());
144                IBoxedPDF df = createBoxedPDF(new Double[]{3.0, 0.1, 2.1, 0.2, 4.3,
145                                0.4, 1.5, 0.1, 1.4, 0.2});
146                Assert.assertEquals(2.1, df.getMedian());
147        }
148 
149        @Test
150        public void checkConstraints() throws NegativeDistanceException,
151                        ProbabilitySumNotOneException, FunctionNotInTimeDomainException,
152                        UnitNotSetException, UnitNameNotSetException,
153                        InvalidSampleValueException {
154                df1.checkConstrains();
155        }
156 
157        @Test(expected = InvalidSampleValueException.class)
158        public void checkConstraints1() throws DoubleSampleException,
159                        NegativeDistanceException, ProbabilitySumNotOneException,
160                        FunctionNotInTimeDomainException, UnitNotSetException,
161                        UnitNameNotSetException, InvalidSampleValueException {
162                IBoxedPDF b = createBoxedPDF(new Double[]{3.0, 0.1, 2.1, 0.4, 4.3, 0.3,
163                                -1.5, 0.2});
164                b.checkConstrains();
165        }
166 
167        @Test(expected = ProbabilitySumNotOneException.class)
168        public void checkConstraints2() throws DoubleSampleException,
169                        NegativeDistanceException, ProbabilitySumNotOneException,
170                        FunctionNotInTimeDomainException, UnitNotSetException,
171                        UnitNameNotSetException, InvalidSampleValueException {
172                IBoxedPDF b = createBoxedPDF(new Double[]{3.0, 0.1, 2.1, 0.4, 4.3, 0.3,
173                                1.5, 0.3});
174                b.checkConstrains();
175        }
176 
177        //TODO uncomment after refactoring in BoxedPDFImpl.checkConstrains()
178//        @Test(expected = UnitNotSetException.class)
179//        public void checkConstraints3() throws DoubleSampleException,
180//                        NegativeDistanceException, ProbabilitySumNotOneException,
181//                        FunctionNotInTimeDomainException, UnitNotSetException,
182//                        UnitNameNotSetException, InvalidSampleValueException {
183//                List<IContinuousSample> samples = new ArrayList<IContinuousSample>();
184//                Collections.addAll(samples, dfFactory.createContinuousSample(3.0, 0.1),
185//                                dfFactory.createContinuousSample(2.1, 0.4), dfFactory
186//                                                .createContinuousSample(4.3, 0.5));
187//
188//                IBoxedPDF b = dfFactory.createBoxedPDF(samples, null);
189//                b.checkConstrains();
190//        }
191 
192        public static junit.framework.Test suite() {
193                return new JUnit4TestAdapter(BoxedPDFTest.class);
194        }
195}

[all classes][de.uka.ipd.sdq.probfunction.math.test]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov