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

COVERAGE SUMMARY FOR SOURCE FILE [TypeInferTests.java]

nameclass, %method, %block, %line, %
TypeInferTests.java0%   (0/1)0%   (0/16)0%   (0/334)0%   (0/76)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TypeInferTests0%   (0/1)0%   (0/16)0%   (0/334)0%   (0/76)
TypeInferTests (): void 0%   (0/1)0%   (0/3)0%   (0/1)
infer (Expression, ExpressionInferTypeVisitor): TypeEnum 0%   (0/1)0%   (0/10)0%   (0/3)
infer (String): TypeEnum 0%   (0/1)0%   (0/7)0%   (0/1)
infer (String, ExpressionInferTypeVisitor): TypeEnum 0%   (0/1)0%   (0/12)0%   (0/3)
parser (String): Expression 0%   (0/1)0%   (0/21)0%   (0/5)
testDoubleAnyCompare (): void 0%   (0/1)0%   (0/19)0%   (0/5)
testDoubleAnyCompareIfElse (): void 0%   (0/1)0%   (0/26)0%   (0/6)
testEnums (): void 0%   (0/1)0%   (0/37)0%   (0/9)
testIntPMF (): void 0%   (0/1)0%   (0/19)0%   (0/5)
testNegativeDoublePDF (): void 0%   (0/1)0%   (0/19)0%   (0/5)
testParenthesis (): void 0%   (0/1)0%   (0/19)0%   (0/5)
testSubFuncInfer (): void 0%   (0/1)0%   (0/29)0%   (0/6)
testTenaryOp (): void 0%   (0/1)0%   (0/15)0%   (0/4)
testTypeInfererBool (): void 0%   (0/1)0%   (0/46)0%   (0/6)
testVariables (): void 0%   (0/1)0%   (0/19)0%   (0/5)
testsubInfer (): void 0%   (0/1)0%   (0/33)0%   (0/7)

1package de.uka.ipd.sdq.pcm.stochasticexpressions.tests;
2 
3import junit.framework.Assert;
4import junit.framework.TestCase;
5import org.antlr.runtime.ANTLRStringStream;
6import org.antlr.runtime.CommonTokenStream;
7import org.antlr.runtime.RecognitionException;
8 
9import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.PCMStoExLexer;
10import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.PCMStoExParser;
11import de.uka.ipd.sdq.stoex.Expression;
12import de.uka.ipd.sdq.stoex.FunctionLiteral;
13import de.uka.ipd.sdq.stoex.IfElseExpression;
14import de.uka.ipd.sdq.stoex.analyser.visitors.ExpressionInferTypeVisitor;
15import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum;
16 
17public class TypeInferTests extends TestCase {
18 
19        public void testEnums() throws RecognitionException{
20                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
21                Expression expression = parser("\"blah\"");
22                infer(expression,visitor);
23                Assert.assertEquals(TypeEnum.ENUM, visitor.getType(expression));
24                visitor = new ExpressionInferTypeVisitor();
25                expression = parser("EnumPMF[(\"blah\";0.4)(\"blub\";0.6)]");
26                infer(expression,visitor);
27                Assert.assertEquals(TypeEnum.ENUM_PMF, visitor.getType(expression));
28        }
29        
30        public void testIntPMF() throws RecognitionException{
31                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
32                Expression expression = parser("IntPMF[(1;0.2)(2;0.4)]");
33                infer(expression,visitor);
34                Assert.assertEquals(TypeEnum.INT_PMF, visitor.getType(expression));
35        }
36 
37        public void testNegativeDoublePDF() throws RecognitionException{
38                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
39                Expression expression = parser("DoublePDF[(-1.0;0.2)(2.0;0.4)]");
40                infer(expression,visitor);
41                Assert.assertEquals(TypeEnum.DOUBLE_PDF, visitor.getType(expression));
42        }
43 
44        
45        public void testDoubleAnyCompare() throws RecognitionException{
46                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
47                Expression expression = parser("192.0 / file.STRUCTURE < 1");
48                infer(expression,visitor);
49                Assert.assertEquals(TypeEnum.BOOL_PMF, visitor.getType(expression));
50        }
51 
52        public void testDoubleAnyCompareIfElse() throws RecognitionException{
53                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
54                IfElseExpression expression = (IfElseExpression) parser("192.0 / file.STRUCTURE < 1 ? 5 : 5");
55                infer(expression,visitor);
56                Assert.assertEquals(TypeEnum.ANY, visitor.getType(expression));
57                Assert.assertEquals(TypeEnum.BOOL_PMF, visitor.getType(expression.getConditionExpression()));
58        }
59 
60        public void testTypeInfererBool() throws RecognitionException {
61                Assert.assertTrue(infer("true AND false") == TypeEnum.BOOL);
62                Assert.assertTrue(infer("true OR false") == TypeEnum.BOOL);
63                Assert.assertTrue(infer("128.0 < 192 OR false") == TypeEnum.BOOL);
64                Assert.assertTrue(infer("NOT(128.0 < 192 OR false)") == TypeEnum.BOOL);
65                Assert.assertTrue(infer("true ? 1 : 5") == TypeEnum.ANY);
66        }
67        
68        public void testsubInfer() throws RecognitionException {
69                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
70                IfElseExpression expression = (IfElseExpression) parser("true ? 1 : 5.5");
71                infer(expression,visitor);
72                Assert.assertEquals(visitor.getType(expression.getConditionExpression()),TypeEnum.BOOL);
73                Assert.assertEquals(TypeEnum.INT,visitor.getType(expression.getIfExpression()));
74                Assert.assertEquals(TypeEnum.DOUBLE,visitor.getType(expression.getElseExpression()));
75        }
76 
77        public void testSubFuncInfer() throws RecognitionException {
78                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
79                FunctionLiteral expression = (FunctionLiteral) parser("Trunc(2.5)");
80                infer(expression,visitor);
81                Assert.assertEquals(TypeEnum.INT_PMF,visitor.getType(expression));
82                Assert.assertEquals(TypeEnum.DOUBLE,visitor.getType(expression.getParameters_FunctionLiteral().get(0)));
83        }        
84 
85        public void testVariables() throws RecognitionException {
86                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
87                Expression expression = parser("file.TYPE");
88                infer(expression,visitor);
89                Assert.assertEquals(TypeEnum.ANY_PMF,visitor.getType(expression));
90        }
91 
92        public void testParenthesis() throws RecognitionException {
93                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
94                Expression expression = parser("file.BYTESIZE * ( file.TYPE / 192 )");
95                infer(expression,visitor);
96                Assert.assertEquals(TypeEnum.ANY_PMF,visitor.getType(expression));
97        }
98        
99        public void testTenaryOp() throws RecognitionException {
100                ExpressionInferTypeVisitor visitor = new ExpressionInferTypeVisitor();
101                IfElseExpression expression = (IfElseExpression) parser("file.TYPE > 192 ? file.BYTESIZE * ( file.TYPE / 192 ) : file.BYTESIZE");
102                infer(expression,visitor);
103        }
104        
105        private TypeEnum infer(String expression) throws RecognitionException{
106                return infer(expression, new ExpressionInferTypeVisitor());
107        }
108        
109        private  TypeEnum infer(String expression, ExpressionInferTypeVisitor typeInferer) throws RecognitionException{
110                Expression formula = parser(expression);
111                typeInferer.doSwitch(formula);
112                
113                return typeInferer.getType(formula);
114        }
115 
116        private  TypeEnum infer(Expression expression, ExpressionInferTypeVisitor typeInferer) throws RecognitionException{
117                Expression formula = expression;
118                typeInferer.doSwitch(formula);
119                
120                return typeInferer.getType(formula);
121        }
122        
123        private Expression parser(String expression) throws RecognitionException {
124                PCMStoExLexer lexer = new PCMStoExLexer(
125                                new ANTLRStringStream(expression));
126                Expression formula = null;
127                formula = new PCMStoExParser(new CommonTokenStream(lexer)).expression();
128                return formula;
129        }
130}

[all classes][de.uka.ipd.sdq.pcm.stochasticexpressions.tests]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov