@@ -234,19 +234,44 @@ class RecursionReachabilityTest {
234
234
235
235
@Test
236
236
fun testTreeTraversalReachable () {
237
- // Test reachability through simplified tree traversal (no actual recursion):
238
- // direct property access -> if (found target 15) -> return 1
237
+ // Test reachability through simplified tree traversal with parameterized target:
238
+ // if (treeNode.value === target) -> return 1 (reachable when target = 10)
239
+ // if (treeNode.left.value === target) -> return 2 (reachable when target = 5)
240
+ // if (treeNode.right.value === target) -> return 3 (reachable when target = 15)
239
241
val machine = TsMachine (scene, options, tsOptions, machineObserver = ReachabilityObserver ())
240
242
val method = scene.projectClasses
241
243
.flatMap { it.methods }
242
244
.single { it.name == " treeTraversalReachable" }
243
245
244
246
val initialTarget = TsReachabilityTarget .InitialPoint (method.cfg.stmts.first())
245
- var target: TsTarget = initialTarget
246
247
247
- // The method uses direct property access, so focus on final return
248
- val returnStmt = method.cfg.stmts.filterIsInstance<EtsReturnStmt >()[0 ]
249
- target.addChild(TsReachabilityTarget .FinalPoint (returnStmt))
248
+ // Path 1:
249
+ // if (treeNode.value === target)
250
+ // return 1
251
+ val ifStmt1 = method.cfg.stmts.filterIsInstance<EtsIfStmt >()[0 ]
252
+ val returnStmt1 = method.cfg.stmts.filterIsInstance<EtsReturnStmt >()[0 ]
253
+
254
+ initialTarget
255
+ .addChild(TsReachabilityTarget .IntermediatePoint (ifStmt1))
256
+ .addChild(TsReachabilityTarget .FinalPoint (returnStmt1))
257
+
258
+ // Path 2:
259
+ // if (treeNode.left.value === target)
260
+ // return 2
261
+ val ifStmt2 = method.cfg.stmts.filterIsInstance<EtsIfStmt >()[1 ]
262
+ val returnStmt2 = method.cfg.stmts.filterIsInstance<EtsReturnStmt >()[1 ]
263
+ initialTarget
264
+ .addChild(TsReachabilityTarget .IntermediatePoint (ifStmt2))
265
+ .addChild(TsReachabilityTarget .FinalPoint (returnStmt2))
266
+
267
+ // Path 3:
268
+ // if (treeNode.right.value === target)
269
+ // return 3
270
+ val ifStmt3 = method.cfg.stmts.filterIsInstance<EtsIfStmt >()[2 ]
271
+ val returnStmt3 = method.cfg.stmts.filterIsInstance<EtsReturnStmt >()[2 ]
272
+ initialTarget
273
+ .addChild(TsReachabilityTarget .IntermediatePoint (ifStmt3))
274
+ .addChild(TsReachabilityTarget .FinalPoint (returnStmt3))
250
275
251
276
val results = machine.analyze(listOf (method), listOf (initialTarget))
252
277
assertTrue(
@@ -256,8 +281,16 @@ class RecursionReachabilityTest {
256
281
257
282
val reachedStatements = results.flatMap { it.pathNode.allStatements }.toSet()
258
283
assertTrue(
259
- returnStmt in reachedStatements,
260
- " Expected return statement to be reached when value 15 exists in tree"
284
+ returnStmt1 in reachedStatements,
285
+ " Expected 'return 1' to be reached when target = 10"
286
+ )
287
+ assertTrue(
288
+ returnStmt2 in reachedStatements,
289
+ " Expected 'return 2' to be reached when target = 5"
290
+ )
291
+ assertTrue(
292
+ returnStmt3 in reachedStatements,
293
+ " Expected 'return 3' to be reached when target = 15"
261
294
)
262
295
}
263
296
0 commit comments