use of module.LongTest in project solution-finder by knewjade.
the class AnalyzeTreeTest method randomLong.
@Test
@LongTest
void randomLong() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 8; size <= 11; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
AnalyzeTree tree = new AnalyzeTree();
HashSet<LongPieces> success = new HashSet<>();
HashSet<LongPieces> failed = new HashSet<>();
generator.blocksStream().forEach(blocks -> {
boolean flag = randoms.nextBoolean();
List<Piece> pieceList = blocks.getPieces();
tree.set(flag, pieceList);
LongPieces longPieces = new LongPieces(pieceList);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isVisited(blocks) && tree.isSucceed(blocks);
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isVisited(blocks) && !tree.isSucceed(blocks);
});
assertThat(isFailed).isTrue();
double percent = (double) success.size() / (success.size() + failed.size());
assertThat(tree.getSuccessPercent()).isCloseTo(percent, offset(0.0001));
}
}
use of module.LongTest in project solution-finder by knewjade.
the class ConcurrentVisitedTreeTest method randomLong.
@Test
@LongTest
void randomLong() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 8; size <= 11; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
ConcurrentVisitedTree tree = new ConcurrentVisitedTree();
Set<LongPieces> success = Collections.synchronizedSet(new HashSet<>());
Set<LongPieces> failed = Collections.synchronizedSet(new HashSet<>());
List<Pieces> piecesList = generator.blocksStream().collect(Collectors.toList());
piecesList.parallelStream().forEach(pieces -> {
boolean flag = randoms.nextBoolean();
List<Piece> blocks = pieces.getPieces();
tree.set(flag, blocks);
LongPieces longPieces = new LongPieces(blocks);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
});
assertThat(isFailed).isTrue();
}
}
use of module.LongTest in project solution-finder by knewjade.
the class VisitedTreeTest method randomLong.
@Test
@LongTest
void randomLong() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 8; size <= 11; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
VisitedTree tree = new VisitedTree();
HashSet<LongPieces> success = new HashSet<>();
HashSet<LongPieces> failed = new HashSet<>();
generator.blocksStream().forEach(pieces -> {
boolean flag = randoms.nextBoolean();
List<Piece> blocks = pieces.getPieces();
tree.set(flag, blocks);
LongPieces longPieces = new LongPieces(blocks);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
});
assertThat(isFailed).isTrue();
}
}
use of module.LongTest in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testCaseList.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, int expectedCount) throws Exception {
// Field
int maxClearLine = 4;
int maxDepth = 10;
Field field = FieldFactory.createField(maxClearLine);
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
// Set test case
List<Piece> piecesList = pieces.getPieces();
// Execute
List<Result> results = checkmate.search(field, piecesList, candidate, maxClearLine, maxDepth);
assertThat(results).as(piecesList.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, piecesList);
}
Aggregations