Search in sources :

Example 1 with LongTest

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);
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SeparableMinos(searcher.pack.SeparableMinos) InOutPairField(searcher.pack.InOutPairField) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) MinoFactory(core.mino.MinoFactory) LinkedList(java.util.LinkedList) List(java.util.List) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) PermutationIterable(common.iterable.PermutationIterable) ColumnField(core.column_field.ColumnField) MinoRotation(core.srs.MinoRotation) Randoms(lib.Randoms) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SizedBit(searcher.pack.SizedBit) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 2 with LongTest

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);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 3 with LongTest

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);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 4 with LongTest

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);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 5 with LongTest

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);
    }
}
Also used : Action(common.datastore.action.Action) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) BlockInterpreter(common.parser.BlockInterpreter) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

LongTest (module.LongTest)44 Test (org.junit.jupiter.api.Test)28 Piece (core.mino.Piece)26 Field (core.field.Field)24 Randoms (lib.Randoms)20 Action (common.datastore.action.Action)19 LockedCandidate (core.action.candidate.LockedCandidate)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)16 Log (_usecase.Log)13 MinoFactory (core.mino.MinoFactory)12 MinoShifter (core.mino.MinoShifter)12 MinoRotation (core.srs.MinoRotation)10 LockedReachable (core.action.reachable.LockedReachable)9 List (java.util.List)9 LongPieces (common.datastore.blocks.LongPieces)8 SizedBit (searcher.pack.SizedBit)8 ColumnField (core.column_field.ColumnField)7 Collectors (java.util.stream.Collectors)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7