Skip to content

Commit 56d681b

Browse files
Move test filters to helpers file
1 parent 61b0aac commit 56d681b

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

src/it/scala/smtlib/it/TestHelpers.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import parser.Parser
1212
import lexer.Lexer
1313
import printer.RecursivePrinter
1414
import interpreters._
15+
import smtlib.trees.Commands.*
16+
import smtlib.trees.Terms.Term
17+
import smtlib.trees.Tree
18+
import smtlib.trees.TreesOps
19+
import smtlib.theories.FixedSizeBitVectors.BitVectorSort
20+
import smtlib.theories.FloatingPoint.FloatingPointSort
1521

1622
/** Provide helper functions to test solver interfaces and files.
1723
*
@@ -91,5 +97,43 @@ trait TestHelpers {
9197
Seq("bitwuzla", "-v", "0", "--lang", "--smt2", file.getPath) ! ProcessLogger(f, s => ())
9298
}
9399

100+
////////////////////////////////////////////////////////////////
101+
// Solver specific helpers
102+
103+
/**
104+
* Is test in the fragment supported by bitwuzla?
105+
*
106+
* May not contain ints, reals, arrays, ADTs
107+
*
108+
*/
109+
def testIsBitwuzlaCompatible(cmds: Seq[Command], formula: Term): Boolean =
110+
def isCompat(term: Term): Boolean =
111+
def violatingTerm(term: Tree, children: Seq[Boolean]): Boolean = {
112+
import smtlib.theories.*
113+
term match
114+
case FixedSizeBitVectors.BitVectorConstant(_, _) => false // internally contains IntNumeral, but in a valid place
115+
case Ints.NumeralLit(_) => true
116+
case Reals.DecimalLit(_) => true
117+
case FixedSizeBitVectors.Int2BV(_, _) => true
118+
case FixedSizeBitVectors.BV2Nat(_) => true
119+
// this is enough to rule out the current problematic tests,
120+
// but may need refinement
121+
case _ => children.contains(true)
122+
}
123+
!TreesOps.fold(violatingTerm)(term)
124+
125+
def compatibleCommand(cmd: Command): Boolean =
126+
cmd match
127+
case DeclareFun(_, paramSorts, sort) => (sort +: paramSorts).forall {
128+
case BitVectorSort(_) => true
129+
case FloatingPointSort(_, _) => true
130+
case _ => false
131+
}
132+
case DeclareSort(_, _) => false
133+
case DeclareDatatypes(_) => false
134+
case Assert(term) => isCompat(term)
135+
case _ => true // may need refinement
136+
cmds.forall(compatibleCommand) && (isCompat(formula))
137+
94138
}
95139

src/it/scala/smtlib/it/TheoriesBuilderTests.scala

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import org.scalatest.funsuite.AnyFunSuite
55
import smtlib.trees.Commands._
66
import smtlib.trees.CommandsResponses._
77
import smtlib.trees.Terms._
8-
import smtlib.theories.FloatingPoint.FloatingPointSort
9-
import smtlib.theories.FixedSizeBitVectors.BitVectorSort
10-
import smtlib.trees.TreesOps
11-
import smtlib.trees.Tree
12-
import smtlib.theories.FixedSizeBitVectors
138

149
/** Checks that formula build with theories module are correctly handled by solvers */
1510
class TheoriesBuilderTests extends AnyFunSuite with TestHelpers {
@@ -62,43 +57,8 @@ class TheoriesBuilderTests extends AnyFunSuite with TestHelpers {
6257
ignore(cvc5Test) {}
6358
}
6459

65-
/**
66-
* Is test in the fragment supported by bitwuzla?
67-
*
68-
* May not contain ints, reals, arrays, ADTs
69-
*
70-
*/
71-
def testIsBitwuzlaCompatible: Boolean =
72-
def isCompat(term: Term): Boolean =
73-
def violatingTerm(term: Tree, children: Seq[Boolean]): Boolean = {
74-
import smtlib.theories.*
75-
term match
76-
case FixedSizeBitVectors.BitVectorConstant(_, _) => false // internally contains IntNumeral, but in a valid place
77-
case Ints.NumeralLit(_) => true
78-
case Reals.DecimalLit(_) => true
79-
case FixedSizeBitVectors.Int2BV(_, _) => true
80-
case FixedSizeBitVectors.BV2Nat(_) => true
81-
// this is enough to rule out the current problematic tests,
82-
// but may need refinement
83-
case _ => children.contains(true)
84-
}
85-
!TreesOps.fold(violatingTerm)(term)
86-
87-
def compatibleCommand(cmd: Command): Boolean =
88-
cmd match
89-
case DeclareFun(_, paramSorts, sort) => (sort +: paramSorts).forall {
90-
case BitVectorSort(_) => true
91-
case FloatingPointSort(_, _) => true
92-
case _ => false
93-
}
94-
case DeclareSort(_, _) => false
95-
case DeclareDatatypes(_) => false
96-
case Assert(term) => isCompat(term)
97-
case _ => true // may need refinement
98-
cmds.forall(compatibleCommand) && (isCompat(formula))
99-
10060
val bitwuzlaTest = prefix + ": with Bitwuzla"
101-
if (isBitwuzlaAvailable && testIsBitwuzlaCompatible) {
61+
if (isBitwuzlaAvailable && testIsBitwuzlaCompatible(cmds, formula)) {
10262
test(bitwuzlaTest) {
10363
runAndCheck(getBitwuzlaInterpreter)
10464
}

0 commit comments

Comments
 (0)