use of module.LongTest in project solution-finder by knewjade.
the class BuildUpStreamTest method randomLong.
@Test
@LongTest
void randomLong() throws ExecutionException, InterruptedException {
// Initialize
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
// Define size
int height = 4;
int basicWidth = 3;
SizedBit sizedBit = new SizedBit(basicWidth, height);
SeparableMinos separableMinos = SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
// Create basic solutions
TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
LockedReachableThreadLocal lockedReachableThreadLocal = new LockedReachableThreadLocal(minoFactory, minoShifter, minoRotation, height);
Predicate<ColumnField> memorizedPredicate = (columnField) -> true;
OnDemandBasicSolutions basicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
AtomicInteger counter = new AtomicInteger();
for (int count = 0; count < 10; count++) {
// Create field
int numOfMinos = randoms.nextIntClosed(7, 9);
Field field = randoms.field(height, numOfMinos);
// Search
List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(basicWidth, height, field);
SolutionFilter solutionFilter = createRandomSolutionFilter(randoms, sizedBit, lockedReachableThreadLocal, field);
PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
Optional<Result> resultOptional = searcher.findAny();
// If found solution
resultOptional.ifPresent(result -> {
counter.incrementAndGet();
LinkedList<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(basicWidth).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
// Create Pieces
LockedReachable reachable = lockedReachableThreadLocal.get();
Set<List<MinoOperationWithKey>> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).collect(Collectors.toSet());
PermutationIterable<MinoOperationWithKey> permutations = new PermutationIterable<>(operationWithKeys, operationWithKeys.size());
for (List<MinoOperationWithKey> permutation : permutations) {
boolean canBuild = BuildUp.cansBuild(field, permutation, height, reachable);
if (canBuild) {
assertThat(valid).as(FieldView.toString(field)).contains(permutation);
} else {
assertThat(valid).as(FieldView.toString(field)).doesNotContain(permutation);
}
}
});
}
System.out.println(counter);
}
use of module.LongTest in project solution-finder by knewjade.
the class MappedBasicSolutionsFactoryTest method create2x6.
@Test
@LongTest
void create2x6() throws Exception {
SizedBit sizedBit = new SizedBit(2, 6);
int expectedSolutions = 3490;
int expectedSolutionItems = 8380826;
assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
use of module.LongTest in project solution-finder by knewjade.
the class OnDemandBasicSolutionsFactoryTest method create2x6.
@Test
@LongTest
void create2x6() throws Exception {
SizedBit sizedBit = new SizedBit(2, 6);
int expectedSolutions = 3490;
int expectedSolutionItems = 8380826;
assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
use of module.LongTest in project solution-finder by knewjade.
the class CheckerNoHoldTest method testCaseList.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, boolean expectedCount) throws Exception {
int maxDepth = 10;
int maxClearLine = 4;
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
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(isSucceed).isEqualTo(expectedCount);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, piecesList);
}
use of module.LongTest in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testPossiblePerfect.
@Test
@LongTest
void testPossiblePerfect() throws Exception {
// Field
Field field = FieldFactory.createSmallField();
int maxClearLine = 4;
int maxDepth = 10;
// Set to check No Possible Perfect
String noPerfectPath = ClassLoader.getSystemResource("orders/noperfect.txt").getPath();
HashSet<LongPieces> noPerfectSet = Files.lines(Paths.get(noPerfectPath)).map(BlockInterpreter::parse).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
// Set test case
int cycle = randoms.nextIntClosed(0, 8);
List<Piece> pieces = randoms.block11InCycle(cycle);
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
boolean expectedFlag = !noPerfectSet.contains(new LongPieces(pieces));
assertThat(isSucceed).isEqualTo(expectedFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
Aggregations