88
99package org .sosy_lab .java_smt .test ;
1010
11- import static com .google .common .base .Preconditions .checkArgument ;
1211import static com .google .common .truth .Truth .assertThat ;
1312import static com .google .common .truth .TruthJUnit .assume ;
14- import static org .junit .Assert .assertThrows ;
1513import static org .sosy_lab .java_smt .api .FormulaType .BooleanType ;
1614import static org .sosy_lab .java_smt .api .FormulaType .IntegerType ;
1715
@@ -170,18 +168,9 @@ protected List<String> getAllNames() {
170168 .build ();
171169 }
172170
173- boolean allowInvalidNames () {
174- return true ;
175- }
176-
177171 @ CanIgnoreReturnValue
178172 private <T extends Formula > T createVariableWith (Function <String , T > creator , String name ) {
179- if (allowInvalidNames () && !mgr .isValidName (name )) {
180- assertThrows (IllegalArgumentException .class , () -> creator .apply (name ));
181- return null ;
182- } else {
183- return creator .apply (name );
184- }
173+ return creator .apply (name );
185174 }
186175
187176 private <T extends Formula > void testName0 (
@@ -191,9 +180,6 @@ private <T extends Formula> void testName0(
191180
192181 // create a variable
193182 T var = createVariableWith (creator , name );
194- if (var == null ) {
195- return ;
196- }
197183
198184 // check whether it exists with the given name
199185 Map <String , Formula > map = mgr .extractVariables (var );
@@ -206,9 +192,6 @@ private <T extends Formula> void testName0(
206192
207193 // check whether we can create the same variable again
208194 T var2 = createVariableWith (creator , name );
209- if (var2 == null ) {
210- return ;
211- }
212195
213196 // for simple formulas, we can expect a direct equality
214197 // (for complex formulas this is not satisfied)
@@ -227,10 +210,8 @@ private <T extends Formula> void testName0(
227210 @ SuppressWarnings ("unused" )
228211 String dump = mgr .dumpFormula (eq .apply (var , var )).toString ();
229212
230- if (allowInvalidNames ()) {
231- // try to create a new (!) variable with a different name, the escaped previous name.
232- assertThat (createVariableWith (creator , "|" + name + "|" )).isEqualTo (null );
233- }
213+ // Adding SMTLIB quotes to the name should make it illegal
214+ assertThat (mgr .isValidName ("|" + name + "|" )).isFalse ();
234215 }
235216
236217 @ Test
@@ -296,8 +277,6 @@ public void testNameIntArray() throws SolverException, InterruptedException {
296277 public void testNameBvArray () throws SolverException , InterruptedException {
297278 requireBitvectors ();
298279 requireArrays ();
299- // Someone who knows princess has to debug this!
300- assume ().that (solverToUse ()).isNotEqualTo (Solvers .PRINCESS );
301280 for (String name : NAMES ) {
302281 testName0 (
303282 name ,
@@ -335,8 +314,6 @@ public void testNameUF1Int() throws SolverException, InterruptedException {
335314 @ Test
336315 public void testNameUFBv () throws SolverException , InterruptedException {
337316 requireBitvectors ();
338- // Someone who knows princess has to debug this!
339- assume ().that (solverToUse ()).isNotEqualTo (Solvers .PRINCESS );
340317 for (String name : getAllNames ()) {
341318 testName0 (
342319 name ,
@@ -371,11 +348,7 @@ public void testNameInQuantification() {
371348 requireIntegers ();
372349
373350 for (String name : getAllNames ()) {
374-
375351 IntegerFormula var = createVariableWith (imgr ::makeVariable , name );
376- if (var == null ) {
377- continue ;
378- }
379352 IntegerFormula zero = imgr .makeNumber (0 );
380353 BooleanFormula eq = imgr .equal (var , zero );
381354 BooleanFormula exists = qmgr .exists (var , eq );
@@ -401,10 +374,7 @@ public Void visitQuantifier(
401374 Quantifier pQuantifier ,
402375 List <Formula > pBoundVariables ,
403376 BooleanFormula pBody ) {
404- if (solverToUse () != Solvers .PRINCESS ) {
405- // TODO Princess does not (yet) return quantified variables.
406- assertThat (pBoundVariables ).hasSize (1 );
407- }
377+ assertThat (pBoundVariables ).hasSize (1 );
408378 for (Formula f : pBoundVariables ) {
409379 Map <String , Formula > map = mgr .extractVariables (f );
410380 assertThat (map ).hasSize (1 );
@@ -427,11 +397,7 @@ public void testNameInNestedQuantification() {
427397 requireIntegers ();
428398
429399 for (String name : getAllNames ()) {
430-
431400 IntegerFormula var1 = createVariableWith (imgr ::makeVariable , name + 1 );
432- if (var1 == null ) {
433- continue ;
434- }
435401 IntegerFormula var2 = createVariableWith (imgr ::makeVariable , name + 2 );
436402 IntegerFormula var3 = createVariableWith (imgr ::makeVariable , name + 3 );
437403 IntegerFormula var4 = createVariableWith (imgr ::makeVariable , name + 4 );
@@ -487,10 +453,8 @@ public Void visitQuantifier(
487453 Quantifier pQuantifier ,
488454 List <Formula > pBoundVariables ,
489455 BooleanFormula pBody ) {
490- if (solverToUse () != Solvers .PRINCESS ) {
491- // TODO Princess does not return quantified variables.
492- assertThat (pBoundVariables ).hasSize (1 );
493- }
456+ assertThat (pBoundVariables ).hasSize (1 );
457+ assertThat (pBoundVariables ).hasSize (1 );
494458 for (Formula f : pBoundVariables ) {
495459 Map <String , Formula > map = mgr .extractVariables (f );
496460 assertThat (map ).hasSize (1 );
@@ -514,9 +478,6 @@ public void testBoolVariableNameInVisitor() {
514478
515479 for (String name : getAllNames ()) {
516480 BooleanFormula var = createVariableWith (bmgr ::makeVariable , name );
517- if (var == null ) {
518- continue ;
519- }
520481
521482 bmgr .visit (
522483 var ,
@@ -545,22 +506,17 @@ public void testBoolVariableDump() {
545506 assume ().that (solverToUse ()).isNotEqualTo (Solvers .YICES2 );
546507 for (String name : getAllNames ()) {
547508 BooleanFormula var = createVariableWith (bmgr ::makeVariable , name );
548- if (var != null ) {
549- @ SuppressWarnings ("unused" )
550- String dump = mgr .dumpFormula (var ).toString ();
551- }
509+ @ SuppressWarnings ("unused" )
510+ String dump = mgr .dumpFormula (var ).toString ();
552511 }
553512 }
554513
555514 @ Test
556515 public void testEqBoolVariableDump () {
557- // FIXME: Rewrite test? Most solvers will simplify the formula to `true`.
558516 for (String name : getAllNames ()) {
559517 BooleanFormula var = createVariableWith (bmgr ::makeVariable , name );
560- if (var != null ) {
561- @ SuppressWarnings ("unused" )
562- String dump = mgr .dumpFormula (bmgr .equivalence (var , var )).toString ();
563- }
518+ @ SuppressWarnings ("unused" )
519+ String dump = mgr .dumpFormula (bmgr .equivalence (var , var )).toString ();
564520 }
565521 }
566522
@@ -610,8 +566,6 @@ public void testIntArrayVariable() {
610566 public void testBvArrayVariable () {
611567 requireArrays ();
612568 requireBitvectors ();
613- // Someone who knows princess has to debug this!
614- assume ().that (solverToUse ()).isNotEqualTo (Solvers .PRINCESS );
615569 for (String name : getAllNames ()) {
616570 createVariableWith (
617571 v ->
@@ -626,12 +580,7 @@ public void testBvArrayVariable() {
626580 @ Test
627581 public void sameBehaviorTest () {
628582 for (String name : getAllNames ()) {
629- if (mgr .isValidName (name )) {
630- // should pass without exception
631- checkArgument (FormulaCreator .isValidName (name ));
632- } else {
633- assertThrows (IllegalArgumentException .class , () -> FormulaCreator .isValidName (name ));
634- }
583+ assertThat (mgr .isValidName (name )).isEqualTo (FormulaCreator .isValidName (name ));
635584 }
636585 }
637586}
0 commit comments