View Javadoc
1   package integrationTests;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   
5   import org.junit.jupiter.api.Disabled;
6   import org.junit.jupiter.api.Test;
7   
8   class IfElseStatementsTest extends CoverageTest {
9       IfElseStatements tested;
10  
11      @Test
12      void simpleIf() {
13          tested.simpleIf(true);
14          tested.simpleIf(false);
15  
16          assertLines(16, 20, 4);
17          assertLine(16, 3, 3, 2);
18          assertLine(17, 1, 1, 1);
19          assertLine(20, 1, 1, 2);
20  
21          assertBranchingPoints(16, 2, 2);
22          assertBranchingPoints(17, 0, 0);
23      }
24  
25      @Test
26      void ifAndElse() {
27          tested.ifAndElse(true);
28          tested.ifAndElse(false);
29      }
30  
31      @Test
32      void singleLineIf() {
33          tested.singleLineIf(true);
34          tested.singleLineIf(false);
35  
36          assertLines(43, 46, 2);
37          assertLine(44, 3, 3, 2);
38          assertLine(46, 1, 1, 2);
39      }
40  
41      @Test
42      void singleLineIfAndElse() {
43          tested.singleLineIfAndElse(true);
44          tested.singleLineIfAndElse(false);
45  
46          assertLines(55, 58, 2);
47          assertLine(56, 3, 3, 2, 1, 1);
48          assertLine(58, 1, 1, 2);
49      }
50  
51      @Test
52      void singleLineIfAndElseWhereOnlyTheElseIsExecuted() {
53          tested.anotherSingleLineIfAndElse(false);
54  
55          assertLines(248, 248, 1);
56          assertLine(248, 3, 2, 1, 0, 1);
57      }
58  
59      @Test
60      void singleLineIfAndElseWhereElseIsExecutedMoreTimes() {
61          tested.yetAnotherSingleLineIfAndElse(false);
62          tested.yetAnotherSingleLineIfAndElse(true);
63          tested.yetAnotherSingleLineIfAndElse(false);
64  
65          assertLines(262, 262, 1);
66          assertLine(262, 3, 3, 3, 1, 2);
67      }
68  
69      @Test
70      void ifWithBooleanAndOperator() {
71          tested.ifWithBooleanAndOperator(true, false);
72          tested.ifWithBooleanAndOperator(false, true);
73  
74          assertLines(275, 278, 2);
75          assertLine(275, 5, 4, 2, 1);
76          assertLine(276, 1, 0, 0);
77          assertLine(278, 1, 1, 2);
78      }
79  
80      @Disabled
81      @Test
82      void anotherIfWithBooleanAndOperator() {
83          tested.anotherIfWithBooleanAndOperator(true, true);
84          tested.anotherIfWithBooleanAndOperator(true, false);
85  
86          assertLines(172, 175, 3);
87          assertLine(172, 3, 2, 2, 2, 0);
88          assertLine(173, 1, 1, 1);
89          assertLine(175, 1, 1, 2);
90      }
91  
92      @Test
93      void ifWithBooleanOrOperator() {
94          tested.ifWithBooleanOrOperator(false, false);
95          tested.ifWithBooleanOrOperator(true, true);
96  
97          assertLines(289, 292, 3);
98          assertLine(289, 5, 4, 2, 1);
99          assertLine(290, 1, 1, 1);
100         assertLine(292, 1, 1, 2);
101     }
102 
103     @Test
104     void methodWithFourDifferentPathsAndSimpleLines_exerciseTwoOppositePaths() {
105         tested.methodWithFourDifferentPathsAndSimpleLines(true, 0);
106         tested.methodWithFourDifferentPathsAndSimpleLines(false, 1);
107 
108         // TODO: assertions
109     }
110 
111     @Test
112     void methodWithFourDifferentPathsAndSegmentedLines_exerciseTwoOppositePaths() {
113         tested.methodWithFourDifferentPathsAndSegmentedLines(false, -1);
114         tested.methodWithFourDifferentPathsAndSegmentedLines(true, 1);
115 
116         // TODO: assertions
117     }
118 
119     @Test
120     void ifElseWithComplexBooleanCondition() {
121         tested.ifElseWithComplexBooleanCondition(true, false);
122 
123         // TODO: assertions
124     }
125 
126     @Test
127     void returnInput() {
128         assertEquals(2, tested.returnInput(1, true, false, false));
129         assertEquals(2, tested.returnInput(2, false, false, false));
130         assertEquals(2, tested.returnInput(3, false, true, false));
131         assertEquals(4, tested.returnInput(4, false, false, true));
132         assertEquals(5, tested.returnInput(5, true, true, false));
133         assertEquals(5, tested.returnInput(6, false, true, true));
134         assertEquals(7, tested.returnInput(7, true, true, true));
135         assertEquals(9, tested.returnInput(8, true, false, true));
136     }
137 
138     @Test
139     void nestedIf() {
140         assertEquals(1, tested.nestedIf(false, false));
141         assertEquals(2, tested.nestedIf(true, true));
142 
143         // TODO: assertions
144     }
145 
146     @Test
147     void ifElseWithNestedIf() {
148         assertEquals(1, tested.ifElseWithNestedIf(true, false));
149         assertEquals(2, tested.ifElseWithNestedIf(true, true));
150         assertEquals(3, tested.ifElseWithNestedIf(false, false));
151 
152         // TODO: assertions
153     }
154 
155     @Test
156     void nestedIfElse() {
157         assertEquals(1, tested.nestedIfElse(false, false));
158         assertEquals(2, tested.nestedIfElse(true, true));
159         assertEquals(3, tested.nestedIfElse(true, false));
160         assertEquals(4, tested.nestedIfElse(false, true));
161 
162         // TODO: assertions
163     }
164 
165     @Test
166     void infeasiblePaths() {
167         tested.infeasiblePaths(true);
168         tested.infeasiblePaths(false);
169 
170         // TODO: assertions
171     }
172 
173     @Test
174     void ifSpanningMultipleLines() {
175         tested.ifSpanningMultipleLines(true, 0);
176         tested.ifSpanningMultipleLines(false, -1);
177         tested.ifSpanningMultipleLines(false, 1);
178 
179         assertLines(317, 325, 3);
180         assertLine(318, 5, 5, 3);
181         assertLine(322, 1, 1, 2);
182         assertLine(325, 1, 1, 3);
183     }
184 }