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 [ProbabilityMassFunctionTest.java]

nameclass, %method, %block, %line, %
ProbabilityMassFunctionTest.java100% (1/1)57%  (13/23)88%  (1109/1260)80%  (94/118)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProbabilityMassFunctionTest100% (1/1)57%  (13/23)88%  (1109/1260)80%  (94/118)
addExtendedDomOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
addExtendedDomUnOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
addOrderedUnOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
checkConstrains1 (): void 0%   (0/1)0%   (0/49)0%   (0/4)
checkConstrains3 (): void 0%   (0/1)0%   (0/49)0%   (0/4)
multExtendedDomOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
multExtendedDomUnOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
multOrderedUnOrdered (): void 0%   (0/1)0%   (0/7)0%   (0/2)
unorderedGetMedian (): void 0%   (0/1)0%   (0/5)0%   (0/2)
unorderedPercentile (): void 0%   (0/1)0%   (0/6)0%   (0/2)
ProbabilityMassFunctionTest (): void 100% (1/1)100% (6/6)100% (2/2)
addSameDom (): void 100% (1/1)100% (199/199)100% (15/15)
checkConstrains4 (): void 100% (1/1)100% (10/10)100% (4/4)
createPMF (Object [], boolean): IProbabilityMassFunction 100% (1/1)100% (44/44)100% (9/9)
equalsOrdered (): void 100% (1/1)100% (82/82)100% (9/9)
equalsUnordered (): void 100% (1/1)100% (78/78)100% (9/9)
getMedian (): void 100% (1/1)100% (7/7)100% (2/2)
hasOrderDomain (): void 100% (1/1)100% (9/9)100% (3/3)
multSameDom (): void 100% (1/1)100% (107/107)100% (9/9)
percentile (): void 100% (1/1)100% (8/8)100% (2/2)
scale (): void 100% (1/1)100% (51/51)100% (5/5)
setUp (): void 100% (1/1)100% (489/489)100% (21/21)
testCreatePMF (): void 100% (1/1)100% (19/19)100% (4/4)

1package de.uka.ipd.sdq.probfunction.math.test;
2 
3import java.util.ArrayList;
4import java.util.List;
5 
6import junit.framework.Assert;
7 
8import org.junit.Before;
9import org.junit.Test;
10 
11import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory;
12import de.uka.ipd.sdq.probfunction.math.IProbabilityMassFunction;
13import de.uka.ipd.sdq.probfunction.math.ISample;
14import de.uka.ipd.sdq.probfunction.math.IUnit;
15import de.uka.ipd.sdq.probfunction.math.exception.DifferentDomainsException;
16import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInTimeDomainException;
17import de.uka.ipd.sdq.probfunction.math.exception.InvalidSampleValueException;
18import de.uka.ipd.sdq.probfunction.math.exception.NegativeDistanceException;
19import de.uka.ipd.sdq.probfunction.math.exception.ProbabilitySumNotOneException;
20import de.uka.ipd.sdq.probfunction.math.exception.UnitNameNotSetException;
21import de.uka.ipd.sdq.probfunction.math.exception.UnitNotSetException;
22import de.uka.ipd.sdq.probfunction.math.exception.UnorderedDomainException;
23 
24public class ProbabilityMassFunctionTest {
25 
26        // unordered domain
27        IProbabilityMassFunction u1, u1extended, u1exDiffProbs, u1same, u2;
28 
29        // ordered domain
30        IProbabilityMassFunction o1, o1extended, o1exDiffProbs, o1same, o2;
31 
32        @Before
33        public void setUp() throws Exception {
34                u1 = createPMF(new Object[]{"car", 0.1, "house", 0.5, "bike", 0.3,
35                                "street", 0.1}, false);
36                u1same = createPMF(new Object[]{"car", 0.2, "house", 0.3, "bike", 0.4,
37                                "street", 0.1}, false);
38 
39                u1extended = createPMF(new Object[]{"car", 0.1, "house", 0.5, "bike",
40                                0.3, "street", 0.1, "tree", 0.0}, false);
41                u1exDiffProbs = createPMF(new Object[]{"car", 0.1, "house", 0.15,
42                                "bike", 0.3, "street", 0.1, "tree", 3.5}, false);
43                u2 = createPMF(new Object[]{"dog", 0.2, "cat", 0.3, "pig", 0.4, "cow",
44                                0.1}, false);
45 
46                o1 = createPMF(new Object[]{0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.1},
47                                true);
48                o1same = createPMF(
49                                new Object[]{0.1, 0.1, 0.2, 0.4, 0.3, 0.2, 0.4, 0.3}, true);
50 
51                o1extended = createPMF(new Object[]{0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4,
52                                0.1, 0.5, 0.0}, true);
53                o1exDiffProbs = createPMF(new Object[]{0.1, 0.1, 0.2, 0.15, 0.3, 0.25,
54                                0.4, 0.3, 0.5, 0.1}, true);
55                o2 = createPMF(new Object[]{0.2, 0.2, 0.4, 0.3, 0.6, 0.4, 0.8, 0.1},
56                                true);
57        }
58 
59        @Test
60        public void testCreatePMF() {
61                Assert.assertEquals(4, o1.getSamples().size());
62                Assert.assertEquals(4, u1.getSamples().size());
63                Assert.assertEquals(5, u1extended.getSamples().size());
64        }
65 
66        @Test
67        public void equalsUnordered() {
68                Assert.assertTrue(u1.equals(u1));
69 
70                IProbabilityMassFunction u1copy = createPMF(new Object[]{"car", 0.1,
71                                "house", 0.5, "bike", 0.3, "street", 0.1}, false);
72                Assert.assertTrue(u1.equals(u1copy));
73 
74                Assert.assertFalse(u1.equals(u1same));
75 
76                Assert.assertFalse(u1.equals(u2));
77 
78                Assert.assertFalse(u1extended.equals(u1exDiffProbs));
79 
80                Assert.assertFalse(u1.equals(u1extended));
81 
82        }
83 
84        @Test
85        public void equalsOrdered() {
86                Assert.assertTrue(o1.equals(o1));
87 
88                IProbabilityMassFunction o1copy = createPMF(new Object[]{0.1, 0.2, 0.2,
89                                0.3, 0.3, 0.4, 0.4, 0.1}, true);
90                Assert.assertTrue(o1.equals(o1copy));
91 
92                Assert.assertFalse(o1.equals(o1same));
93 
94                Assert.assertFalse(o1.equals(o2));
95 
96                Assert.assertFalse(o1extended.equals(o1exDiffProbs));
97 
98                Assert.assertFalse(o1.equals(o1extended));
99        }
100 
101        @Test
102        public void hasOrderDomain() {
103                Assert.assertTrue(o1.hasOrderedDomain());
104                Assert.assertFalse(u1.hasOrderedDomain());
105        }
106 
107        @Test(expected = UnorderedDomainException.class)
108        public void unorderedGetMedian() throws UnorderedDomainException {
109                u1.getMedian();
110        }
111 
112        @Test(expected = UnorderedDomainException.class)
113        public void unorderedPercentile() throws UnorderedDomainException {
114                u1.getPercentile(10);
115        }
116 
117        @Test
118        public void percentile() throws IndexOutOfBoundsException,
119                        UnorderedDomainException {
120                Assert.assertEquals(0.3, o1.getPercentile(50)); // ??
121        }
122 
123        @Test
124        public void getMedian() throws UnorderedDomainException {
125                Assert.assertEquals(0.3, o1.getMedian());
126        }
127 
128        @Test
129        public void addSameDom() throws DifferentDomainsException {
130                IProbabilityMassFunction sum = o1.add(o1same);
131                IProbabilityMassFunction expected = createPMF(new Object[]{0.1, 0.3,
132                                0.2, 0.7, 0.3, 0.6, 0.4, 0.4}, true);
133                Assert.assertEquals(expected, sum);
134 
135                sum = u1.add(u1same);
136                expected = createPMF(new Object[]{"car", 0.3, "house", 0.8, "bike",
137                                0.7, "street", 0.2}, true);
138                Assert.assertEquals(expected, sum);
139 
140                IProbabilityMassFunction unsorted = createPMF(new Object[]{"car", 0.2,
141                                "street", 0.1, "house", 0.3, "bike", 0.4}, false);
142                sum = u1.add(unsorted);
143                expected = createPMF(new Object[]{"house", 0.8, "bike", 0.7, "car",
144                                0.3, "street", 0.2}, true);
145                Assert.assertEquals(expected, sum);
146        }
147 
148        @Test(expected = DifferentDomainsException.class)
149        public void addExtendedDomOrdered() throws DifferentDomainsException {
150                o1.add(o1extended);
151        }
152 
153        @Test(expected = DifferentDomainsException.class)
154        public void addExtendedDomUnOrdered() throws DifferentDomainsException {
155                u1.add(u1extended);
156        }
157 
158        @Test(expected = DifferentDomainsException.class)
159        public void addOrderedUnOrdered() throws DifferentDomainsException {
160                o1.add(u1);
161        }
162 
163        @Test
164        public void multSameDom() throws DifferentDomainsException {
165                IProbabilityMassFunction sum = o1.mult(o1same);
166                IProbabilityMassFunction expected = createPMF(new Object[]{0.1, 0.02,
167                                0.2, 0.12, 0.3, 0.08, 0.4, 0.03}, true);
168                Assert.assertEquals(expected, sum);
169 
170                sum = u1.mult(u1same);
171                expected = createPMF(new Object[]{"car", 0.1 * 0.2, "house", 0.5 * 0.3,
172                                "bike", 0.3 * 0.4, "street", 0.1 * 0.1}, false);
173                Assert.assertEquals(expected, sum);
174        }
175 
176        @Test
177        public void scale() {
178                IProbabilityMassFunction result = u1.scale(0.1);
179                IProbabilityMassFunction expected = createPMF(new Object[]{"car", 0.01,
180                                "house", 0.05, "bike", 0.03, "street", 0.01}, false);
181                Assert.assertEquals(expected, result);
182        }
183 
184        @Test(expected = DifferentDomainsException.class)
185        public void multExtendedDomOrdered() throws DifferentDomainsException {
186                o1.add(o1extended);
187        }
188 
189        @Test(expected = DifferentDomainsException.class)
190        public void multExtendedDomUnOrdered() throws DifferentDomainsException {
191                u1.add(u1extended);
192        }
193 
194        @Test(expected = DifferentDomainsException.class)
195        public void multOrderedUnOrdered() throws DifferentDomainsException {
196                o1.add(u1);
197        }
198 
199        @Test(expected = ProbabilitySumNotOneException.class)
200        public void checkConstrains1() throws NegativeDistanceException,
201                        ProbabilitySumNotOneException, FunctionNotInTimeDomainException,
202                        UnitNotSetException, UnitNameNotSetException,
203                        InvalidSampleValueException {
204                IProbabilityMassFunction pmf = createPMF(new Object[]{0.1, 0.3, 0.2,
205                                0.3, 0.3, 0.4, 0.4, 0.1}, true);
206                pmf.checkConstrains();
207        }
208 
209        @Test(expected = InvalidSampleValueException.class)
210        public void checkConstrains3() throws NegativeDistanceException,
211                        ProbabilitySumNotOneException, FunctionNotInTimeDomainException,
212                        UnitNotSetException, UnitNameNotSetException,
213                        InvalidSampleValueException {
214                IProbabilityMassFunction pmf = createPMF(new Object[]{0.1, 0.3, 0.2,
215                                0.4, 0.4, 0.4, 0.4, -0.1}, true);
216                pmf.checkConstrains();
217        }
218 
219//  Commented this because UnitNotSetException is obsolete  
220//
221//        @Test(expected = UnitNotSetException.class)
222//        public void checkConstrains2() throws NegativeDistanceException,
223//                        ProbabilitySumNotOneException, FunctionNotInTimeDomainException,
224//                        UnitNotSetException, UnitNameNotSetException,
225//                        InvalidSampleValueException {
226//                List<ISample> samples = new ArrayList<ISample>();
227//                Collections.addAll(samples, dfFactory.createSample(0.1, 0.3), dfFactory
228//                                .createSample(0.2, 0.2), dfFactory.createSample(0.3, 0.4),
229//                                dfFactory.createSample(0.4, 0.1));
230//                IProbabilityMassFunction pmf = dfFactory.createProbabilityMassFunction(
231//                                samples, null, true);
232//                pmf.checkConstrains();
233//        }
234 
235        @Test
236        public void checkConstrains4() throws NegativeDistanceException,
237                        ProbabilitySumNotOneException, FunctionNotInTimeDomainException,
238                        UnitNotSetException, UnitNameNotSetException,
239                        InvalidSampleValueException {
240                u1.checkConstrains();
241                o1.checkConstrains();
242                u1extended.checkConstrains();
243        }
244 
245        private IProbabilityFunctionFactory dfFactory = IProbabilityFunctionFactory.eINSTANCE;
246 
247        private IProbabilityMassFunction createPMF(Object[] samples,
248                        boolean isOrderedSet) {
249                List<ISample> sList = new ArrayList<ISample>();
250                for (int i = 0; i < samples.length; i += 2) {
251                        ISample s = dfFactory.createSample(samples[i],
252                                        (Double) samples[i + 1]);
253                        sList.add(s);
254                }
255                IUnit ms = dfFactory.createUnit("ms");
256                IProbabilityMassFunction pmf = dfFactory.createProbabilityMassFunction(
257                                sList, ms, isOrderedSet);
258                return pmf;
259        }
260}

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