Search in sources :

Example 36 with LongTest

use of module.LongTest in project solution-finder by knewjade.

the class CheckmateNoHoldTest method testLong10.

@Test
@LongTest
void testLong10() throws Exception {
    List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {

        {
            add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z, T), 3));
            add(new Pair<>(Arrays.asList(S, Z, T, L, J, I, O, S, Z, T, L), 6));
            add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L, I), 21));
            add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L, T), 21));
            add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L), 21));
            add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z), 3));
            add(new Pair<>(Arrays.asList(T, S, L, I, Z, J, L, O, O, S), 2));
            add(new Pair<>(Arrays.asList(L, Z, S, J, Z, Z, Z, I, T, T), 7));
            add(new Pair<>(Arrays.asList(T, T, S, S, Z, Z, L, L, J, J), 18));
            add(new Pair<>(Arrays.asList(O, S, O, S, Z, L, Z, L, I, I), 4));
            add(new Pair<>(Arrays.asList(J, I, T, O, L, S, I, T, Z, O), 9));
            add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L, L), 16));
        }
    };
    // 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
    for (Pair<List<Piece>, Integer> testCase : testCases) {
        // Set test case
        List<Piece> pieces = testCase.getKey();
        int expectedCount = testCase.getValue();
        // Execute
        List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(results).as(pieces.toString()).hasSize(expectedCount);
        // Check result
        for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) ArrayList(java.util.ArrayList) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) List(java.util.List) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) LongTest(module.LongTest)

Example 37 with LongTest

use of module.LongTest in project solution-finder by knewjade.

the class CheckmateUsingHoldReuseTest method randomCheckmateWithJustBlock.

@Test
@LongTest
void randomCheckmateWithJustBlock() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 25; count++) {
        int maxClearLine = randoms.nextInt(3, 8);
        int maxDepth = randoms.nextIntClosed(5, 7);
        List<Piece> pieces = randoms.blocks(maxDepth);
        Field field = randoms.field(maxClearLine, maxDepth);
        Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
        Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
        Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
        for (int swap = 0; swap < 250; swap++) {
            int index = randoms.nextInt(3, pieces.size());
            Piece pop = pieces.remove(index);
            pieces.add(pop);
            stopwatchNoUse.start();
            List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchNoUse.stop();
            stopwatchReuse.start();
            List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchReuse.stop();
            assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
        }
    // TODO:
    // assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 38 with LongTest

use of module.LongTest in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight4.

// 高さ4: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
@LongTest
void testAllSRSValidPacksHeight4() throws Exception {
    int width = 3;
    int height = 4;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height4.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 39 with LongTest

use of module.LongTest in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight6.

// 高さ6: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
@LongTest
void testAllSRSValidPacksHeight6() throws Exception {
    int width = 2;
    int height = 6;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height6.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 40 with LongTest

use of module.LongTest in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testRandomLocked.

@Disabled
@Test
@LongTest
// TODO: mesure time, 移動回数をチェックしていないためテストに失敗することがある
void testRandomLocked() {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LimitIterationCandidate limitIterationCandidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 12);
    for (int count = 0; count < 10; count++) {
        int randomHeight = randoms.nextIntClosed(10, 12);
        int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
        Field field = randoms.field(randomHeight, numOfMinos);
        int clearLine = field.clearLine();
        int height = randomHeight - clearLine;
        Piece piece = randoms.block();
        String description = FieldView.toString(field, height) + piece;
        Set<Action> actions1 = limitIterationCandidate.search(field, piece, height);
        LockedCandidate lockedCandidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
        Set<Action> actions2 = lockedCandidate.search(field, piece, height);
        assertThat(actions2).as(description).isEqualTo(actions1);
    }
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest) Disabled(org.junit.jupiter.api.Disabled)

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