@@ -550,6 +550,36 @@ void testTransitive() {
550550 assertEquals ("a == 1" , result .getValue ().toString (), "Expected result to be a == 1" );
551551 }
552552
553+ @ Test
554+ void testShouldNotOversimplifyToTrue () {
555+ // Given: x > 5 && x == y && y == 10
556+ // Iteration 1: resolves y == 10, substitutes y -> 10: x > 5 && x == 10
557+ // Iteration 2: resolves x == 10, substitutes x -> 10: 10 > 5 && 10 == 10 -> true
558+ // Expected: x > 5 && x == 10 (should NOT simplify to true)
559+
560+ Expression varX = new Var ("x" );
561+ Expression varY = new Var ("y" );
562+ Expression five = new LiteralInt (5 );
563+ Expression ten = new LiteralInt (10 );
564+
565+ Expression xGreater5 = new BinaryExpression (varX , ">" , five );
566+ Expression xEqualsY = new BinaryExpression (varX , "==" , varY );
567+ Expression yEquals10 = new BinaryExpression (varY , "==" , ten );
568+
569+ Expression firstAnd = new BinaryExpression (xGreater5 , "&&" , xEqualsY );
570+ Expression fullExpression = new BinaryExpression (firstAnd , "&&" , yEquals10 );
571+
572+ // When
573+ ValDerivationNode result = ExpressionSimplifier .simplify (fullExpression );
574+
575+ // Then
576+ assertNotNull (result , "Result should not be null" );
577+ assertFalse (result .getValue () instanceof LiteralBoolean ,
578+ "Should not oversimplify to a boolean literal, but got: " + result .getValue ());
579+ assertEquals ("x > 5 && x == 10" , result .getValue ().toString (),
580+ "Should stop simplification before collapsing to true" );
581+ }
582+
553583 /**
554584 * Helper method to compare two derivation nodes recursively
555585 */
0 commit comments