-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests of ground explosion program
- Loading branch information
1 parent
dbaab67
commit 20c6ebd
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
alpha-core/src/test/java/at/ac/tuwien/kr/alpha/core/solver/reboot/GroundExplosionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters