/// <summary>
/// Some basic tests.
/// </summary>
static void BasicTests(Context ctx)
{
Console.WriteLine("BasicTests");
Symbol qi = ctx.MkSymbol(1);
Symbol fname = ctx.MkSymbol("f");
Symbol x = ctx.MkSymbol("x");
Symbol y = ctx.MkSymbol("y");
Sort bs = ctx.MkBoolSort();
Sort[] domain = { bs, bs };
FuncDecl f = ctx.MkFuncDecl(fname, domain, bs);
Expr fapp = ctx.MkApp(f, ctx.MkConst(x, bs), ctx.MkConst(y, bs));
Expr[] fargs2 = { ctx.MkFreshConst("cp", bs) };
Sort[] domain2 = { bs };
Expr fapp2 = ctx.MkApp(ctx.MkFreshFuncDecl("fp", domain2, bs), fargs2);
BoolExpr trivial_eq = ctx.MkEq(fapp, fapp);
BoolExpr nontrivial_eq = ctx.MkEq(fapp, fapp2);
Goal g = ctx.MkGoal(true);
g.Assert(trivial_eq);
g.Assert(nontrivial_eq);
Console.WriteLine("Goal: " + g);
Solver solver = ctx.MkSolver();
foreach (BoolExpr a in g.Formulas)
solver.Assert(a);
if (solver.Check() != Status.SATISFIABLE)
throw new TestFailedException();
ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g);
if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat))
throw new TestFailedException();
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat)
throw new TestFailedException();
g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)),
ctx.MkNumeral(2, ctx.MkBitVecSort(32))));
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
throw new TestFailedException();
Goal g2 = ctx.MkGoal(true, true);
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat)
throw new TestFailedException();
g2 = ctx.MkGoal(true, true);
g2.Assert(ctx.MkFalse());
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
throw new TestFailedException();
Goal g3 = ctx.MkGoal(true, true);
Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort);
Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort);
g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort)));
g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort)));
BoolExpr constr = ctx.MkEq(xc, yc);
g3.Assert(constr);
ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3);
if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat)
throw new TestFailedException();
ModelConverterTest(ctx);
// Real num/den test.
RatNum rn = ctx.MkReal(42, 43);
Expr inum = rn.Numerator;
Expr iden = rn.Denominator;
Console.WriteLine("Numerator: " + inum + " Denominator: " + iden);
if (inum.ToString() != "42" || iden.ToString() != "43")
throw new TestFailedException();
if (rn.ToDecimalString(3) != "0.976?")
throw new TestFailedException();
BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333"));
BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333"));
BigIntCheck(ctx, ctx.MkReal("-234234333"));
BigIntCheck(ctx, ctx.MkReal("234234333/2"));
string bn = "1234567890987654321";
if (ctx.MkInt(bn).BigInteger.ToString() != bn)
throw new TestFailedException();
if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn)
throw new TestFailedException();
if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn)
throw new TestFailedException();
// Error handling test.
try
{
IntExpr i = ctx.MkInt("1/2");
throw new TestFailedException(); // unreachable
}
catch (Z3Exception)
{
}
}