68
68
CPPUNIT_TEST(testDontAddOnePredsThatAreNotHeads);
69
69
CPPUNIT_TEST(testDontAddDuplicateBodies);
70
70
CPPUNIT_TEST(testDontAddDuplicateSumBodies);
71
CPPUNIT_TEST(testDontAddDuplicateSimpBodies);
71
72
CPPUNIT_TEST(testDontAddUnsupported);
72
73
CPPUNIT_TEST(testDontAddUnsupportedNoEq);
73
74
CPPUNIT_TEST(testDontAddUnsupportedExtNoEq);
126
127
CPPUNIT_TEST(writeIntegrityConstraint);
127
128
CPPUNIT_TEST(testComputeTrueBug);
128
129
CPPUNIT_TEST(testBackprop);
130
CPPUNIT_TEST(testBackpropTrueCon);
131
CPPUNIT_TEST(testBackpropWrite);
130
133
CPPUNIT_TEST(testSimpleIncremental);
131
134
CPPUNIT_TEST(testIncrementalFreeze);
508
511
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram());
509
512
CPPUNIT_ASSERT(builder.stats.bodies == 2);
514
void testDontAddDuplicateSimpBodies() {
517
// a :- 8 [c=2, b=3, d=4].
519
.setAtomName(1, "a").setAtomName(2, "b").setAtomName(3, "c").setAtomName(4, "d")
520
.startRule(CHOICERULE).addHead(1).addHead(2).addHead(3).addHead(4).endRule()
521
.startRule().addHead(1).addToBody(2, true).addToBody(3, true).addToBody(4, true).endRule()
522
.startRule(WEIGHTRULE, 8).addHead(1).addToBody(3, true, 2).addToBody(2, true, 3).addToBody(4, true, 4).endRule()
524
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram());
525
CPPUNIT_ASSERT(builder.stats.bodies == 2);
512
528
void testDontAddUnsupported() {
1425
1441
CPPUNIT_ASSERT(ctx.numVars() == 0);
1444
void testBackpropTrueCon() {
1445
Var r, s, x, y, a, t;
1446
builder.start(ctx, LogicProgram::AspOptions().backpropagate())
1447
.setAtomName(r = 2, "r").setAtomName(s = 3, "s").setAtomName(x=4, "x").setAtomName(a=5, "a").setAtomName(y=6, "y").setAtomName(t=7, "t")
1448
.startRule().addHead(t).endRule() // t.
1449
.startRule(CHOICERULE).addHead(r).addHead(s).endRule() // {r,s}.
1450
.startRule().addHead(x).addToBody(y, false).endRule() // x :- not y.
1451
.startRule().addHead(1).addToBody(a, false).endRule() // :- not a.
1452
.startRule(CONSTRAINTRULE, 1).addHead(a).addToBody(r, false).addToBody(s, false).endRule() // a :- 1 {not r, not s}.
1453
.setCompute(1, false)
1455
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram() && ctx.endInit());
1456
ctx.master()->assume(builder.getLiteral(r)) && ctx.master()->propagate();
1457
CPPUNIT_ASSERT(ctx.master()->isFalse(builder.getLiteral(s)));
1458
ctx.master()->undoUntil(0);
1459
ctx.master()->assume(builder.getLiteral(s)) && ctx.master()->propagate();
1460
CPPUNIT_ASSERT(ctx.master()->isFalse(builder.getLiteral(r)));
1462
void testBackpropWrite() {
1463
builder.start(ctx, LogicProgram::AspOptions().backpropagate())
1464
.setAtomName(1, "a").setAtomName(2, "b").setAtomName(3, "c").setAtomName(4, "d").setAtomName(5, "_FAIL")
1465
.startRule(DISJUNCTIVERULE).addHead(1).addHead(2).endRule() // a | b.
1466
.startRule().addHead(3).addToBody(1, true).endRule() // c :- a.
1467
.startRule().addHead(1).addToBody(3, true).endRule() // a :- c.
1468
.startRule().addHead(4).addToBody(3, false).endRule() // d :- not c.
1469
.startRule().addHead(5).addToBody(1, true).addToBody(3, true).endRule() // _FAIL :- a,c.
1470
.setCompute(5, false)
1472
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram() && ctx.endInit());
1473
CPPUNIT_ASSERT(ctx.numVars() == 0);
1474
CPPUNIT_ASSERT(ctx.master()->isFalse(builder.getLiteral(1)));
1475
CPPUNIT_ASSERT(ctx.master()->isFalse(builder.getLiteral(3)));
1476
CPPUNIT_ASSERT(ctx.master()->isTrue(builder.getLiteral(2)));
1477
CPPUNIT_ASSERT(ctx.master()->isTrue(builder.getLiteral(4)));
1479
std::string x = str.str();
1480
CPPUNIT_ASSERT(x.find("1 2 0 0") != std::string::npos || x.find("1 2 1 0 4"));
1481
CPPUNIT_ASSERT(x.find("1 4 0 0") != std::string::npos || x.find("1 4 1 0 2"));
1482
CPPUNIT_ASSERT(x.find("1 1") == std::string::npos);
1483
CPPUNIT_ASSERT(x.find("1 3") == std::string::npos);
1428
1486
void testSimpleIncremental() {
1429
1487
builder.start(ctx);