View Javadoc
1   package integrationTests;
2   
3   /**
4    * The Class BooleanExpressions.
5    */
6   public final class BooleanExpressions {
7   
8       /**
9        * Eval 1.
10       *
11       * @param x
12       *            the x
13       * @param y
14       *            the y
15       * @param z
16       *            the z
17       *
18       * @return true, if successful
19       */
20      public boolean eval1(boolean x, boolean y, int z) {
21          return x && (y || z > 0);
22      }
23  
24      /**
25       * Eval 2.
26       *
27       * @param x
28       *            the x
29       * @param y
30       *            the y
31       * @param z
32       *            the z
33       *
34       * @return true, if successful
35       */
36      public boolean eval2(boolean x, boolean y, int z) {
37          return x && (y || z > 0);
38      }
39  
40      /**
41       * Eval 3.
42       *
43       * @param x
44       *            the x
45       * @param y
46       *            the y
47       * @param z
48       *            the z
49       *
50       * @return true, if successful
51       */
52      public boolean eval3(boolean x, boolean y, boolean z) {
53          return x && (y || z); // LOAD 1 IFEQ L1, LOAD 2 IFNE L2, LOAD 3 IFEQ L1, [L2 1 GOTO L3], [L1 0 L3 RETURN]
54      }
55  
56      /**
57       * Eval 4.
58       *
59       * @param x
60       *            the x
61       * @param y
62       *            the y
63       * @param z
64       *            the z
65       *
66       * @return true, if successful
67       */
68      public boolean eval4(boolean x, boolean y, boolean z) {
69          return x && (!y || z);
70      }
71  
72      /**
73       * Eval 5.
74       *
75       * @param a
76       *            the a
77       * @param b
78       *            the b
79       * @param c
80       *            the c
81       *
82       * @return true, if successful
83       */
84      public boolean eval5(boolean a, boolean b, boolean c) {
85          if (a) {
86              return true;
87          }
88          if (b || c) {
89              return false;
90          }
91  
92          return !c;
93      }
94  
95      /**
96       * Checks if is same type ignoring auto boxing.
97       *
98       * @param firstType
99       *            the first type
100      * @param secondType
101      *            the second type
102      *
103      * @return true, if is same type ignoring auto boxing
104      */
105     static boolean isSameTypeIgnoringAutoBoxing(Class<?> firstType, Class<?> secondType) {
106         return firstType == secondType || firstType.isPrimitive() && isWrapperOfPrimitiveType(firstType, secondType)
107                 || secondType.isPrimitive() && isWrapperOfPrimitiveType(secondType, firstType);
108     }
109 
110     /**
111      * Checks if is wrapper of primitive type.
112      *
113      * @param primitiveType
114      *            the primitive type
115      * @param otherType
116      *            the other type
117      *
118      * @return true, if is wrapper of primitive type
119      */
120     static boolean isWrapperOfPrimitiveType(Class<?> primitiveType, Class<?> otherType) {
121         return primitiveType == int.class && otherType == Integer.class
122                 || primitiveType == long.class && otherType == Long.class
123                 || primitiveType == double.class && otherType == Double.class
124                 || primitiveType == float.class && otherType == Float.class
125                 || primitiveType == boolean.class && otherType == Boolean.class;
126     }
127 
128     /**
129      * Simply returns input.
130      *
131      * @param b
132      *            the b
133      *
134      * @return true, if successful
135      */
136     public boolean simplyReturnsInput(boolean b) {
137         return b;
138     }
139 
140     /**
141      * Returns negated input.
142      *
143      * @param b
144      *            the b
145      *
146      * @return true, if successful
147      */
148     public boolean returnsNegatedInput(boolean b) {
149         return !b; // LOAD 1 IFNE L1, 1 GOTO L2, L1 0 L2 RETURN
150     }
151 
152     /**
153      * Returns trivial result from input after if else.
154      *
155      * @param b
156      *            the b
157      * @param i
158      *            the i
159      *
160      * @return true, if successful
161      */
162     public boolean returnsTrivialResultFromInputAfterIfElse(boolean b, int i) {
163         String s;
164 
165         if (b) {
166             s = "one";
167         } else {
168             s = "two";
169         }
170 
171         return i != 0; // LOAD 2 IFEQ L1, 1 GOTO L2, L1 0 L2 RETURN
172     }
173 
174     /**
175      * Returns result previously computed from input.
176      *
177      * @param b
178      *            the b
179      * @param i
180      *            the i
181      *
182      * @return true, if successful
183      */
184     public boolean returnsResultPreviouslyComputedFromInput(boolean b, int i) {
185         String s = b ? "a" : "b";
186         boolean res;
187 
188         if (i != 0) {
189             res = true;
190         } else {
191             res = false;
192             System.out.checkError();
193         }
194 
195         return res;
196     }
197 
198     /**
199      * Method with too many conditions for path analysis.
200      *
201      * @param i
202      *            the i
203      * @param j
204      *            the j
205      * @param b
206      *            the b
207      *
208      * @return true, if successful
209      */
210     public boolean methodWithTooManyConditionsForPathAnalysis(int i, int j, boolean b) {
211         if (i > 0 && j < 5 || (b ? i > 1 : j > 5) || (i <= 3 || j >= 4) && b) {
212             return i + j == 3 == b;
213         }
214         if (i < 0 || j < 0) {
215             return i < j;
216         }
217 
218         return b;
219     }
220 
221     /**
222      * Returns negated input from local variable.
223      *
224      * @param b
225      *            the b
226      *
227      * @return true, if successful
228      */
229     public boolean returnsNegatedInputFromLocalVariable(boolean b) {
230         return !b; // LOAD 1 IFNE L1, [1 GOTO L2], [L1 0], L2 STORE 2, L3 LOAD 2 RETURN
231     }
232 }