Skip to content

Commit

Permalink
Add tests of ground explosion program
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbehofsics committed Jul 26, 2023
1 parent dbaab67 commit 20c6ebd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package at.ac.tuwien.kr.alpha.core.solver.reboot;

import at.ac.tuwien.kr.alpha.core.solver.RegressionTest;
import at.ac.tuwien.kr.alpha.core.solver.RegressionTestConfig;

import java.util.stream.IntStream;

import static at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSets;

public class GroundExplosionTest {
@RegressionTest
public void testGroundExplosion_1(RegressionTestConfig cfg) {
String domainStr = getDomainString(1);
assertRegressionTestAnswerSets(cfg,
getProgramString(1),
domainStr,
"sel(1), p(1,1,1,1,1,1), " + domainStr);
}

@RegressionTest
public void testGroundExplosion_5(RegressionTestConfig cfg) {
String domainStr = getDomainString(5);
assertRegressionTestAnswerSets(cfg,
getProgramString(5),
domainStr,
"sel(1), p(1,1,1,1,1,1), " + domainStr,
"sel(2), p(2,2,2,2,2,2), " + domainStr,
"sel(3), p(3,3,3,3,3,3), " + domainStr,
"sel(4), p(4,4,4,4,4,4), " + domainStr,
"sel(5), p(5,5,5,5,5,5), " + domainStr);
}

/**
* Constructs a ground explosion program string with the given domain size.
*
* @param n the size of the encoded domain.
*/
private String getProgramString(int n) {
return "{ sel(X) } :- dom(X)." +
":- sel(X), sel(Y), X != Y." +
"p(X1,X2,X3,X4,X5,X6) :- sel(X1), sel(X2), sel(X3), sel(X4), sel(X5), sel(X6)." +
String.format("dom(1..%d).", n);
}

/**
* Constructs a string of atoms representing a domain of the given size.
*
* @param n the size of the encoded domain.
*/
private String getDomainString(int n) {
return IntStream.range(1, n + 1)
.mapToObj(x -> String.format("dom(%d)", x))
.reduce((x, y) -> String.format("%s, %s", x, y))
.orElse("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,8 @@ public static void ignoreTestForRebootEnabled(RegressionTestConfig cfg) {
Assumptions.assumeFalse(cfg.isRebootEnabled());
}

public static void ignoreTestForRebootDisabled(RegressionTestConfig cfg) {
Assumptions.assumeTrue(cfg.isRebootEnabled());
}

}

0 comments on commit 20c6ebd

Please sign in to comment.