Search in sources :

Example 61 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class OperationWithKeyInterpreterTest method parseRandom.

@Test
void parseRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    for (int size = 1; size < 20; size++) {
        List<OperationWithKey> operations = Stream.generate(() -> {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(4);
            long deleteKey = randoms.key();
            long usingKey = randoms.key();
            return new FullOperationWithKey(minoFactory.create(piece, rotate), x, y, deleteKey, usingKey);
        }).limit(size).collect(Collectors.toList());
        String str = OperationWithKeyInterpreter.parseToString(operations);
        List<MinoOperationWithKey> actual = OperationWithKeyInterpreter.parseToList(str, minoFactory);
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 62 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class LongPiecesTest method createEqualsRandom.

@Test
void createEqualsRandom() throws Exception {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        int size1 = randoms.nextInt(1, 21);
        List<Piece> blocks1 = randoms.blocks(size1);
        int size2 = randoms.nextInt(1, 22);
        List<Piece> blocks2 = randoms.blocks(size2);
        if (blocks1.equals(blocks2))
            blocks1.add(Piece.I);
        Pieces pieces1 = new LongPieces(blocks1);
        Pieces pieces2 = new LongPieces(blocks2);
        assertThat(pieces1.equals(pieces2)).isFalse();
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) Test(org.junit.jupiter.api.Test)

Example 63 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class PiecesTest method testHashCode.

@Test
void testHashCode() throws Exception {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        int size = randoms.nextInt(4, 10);
        List<Piece> pieces = randoms.blocks(size);
        ReadOnlyListPieces readOnlyListPieces = new ReadOnlyListPieces(pieces);
        LongPieces longPieces = new LongPieces(pieces);
        assertThat(readOnlyListPieces.hashCode()).as(pieces.toString()).isEqualTo(longPieces.hashCode());
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) Test(org.junit.jupiter.api.Test)

Example 64 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class ReadOnlyListPiecesTest method equalToLongPieces.

@Test
void equalToLongPieces() throws Exception {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        int size = randoms.nextInt(1, 22);
        List<Piece> pieces = randoms.blocks(size);
        Pieces readOnlyListPieces = new ReadOnlyListPieces(pieces);
        LongPieces longPieces = new LongPieces(pieces);
        assertThat(readOnlyListPieces.equals(longPieces)).as(longPieces.getPieces().toString()).isTrue();
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) Test(org.junit.jupiter.api.Test)

Example 65 with Randoms

use of lib.Randoms in project solution-finder by knewjade.

the class CombinationIterableTest method iteratorRandomBlockCount.

@Test
void iteratorRandomBlockCount() throws Exception {
    Randoms randoms = new Randoms();
    ArrayList<Piece> allPieces = Lists.newArrayList(Iterables.concat(Piece.valueList(), Piece.valueList()));
    for (int pop = 1; pop <= 14; pop++) {
        CombinationIterable<Piece> iterable = new CombinationIterable<>(allPieces, pop);
        Set<PieceCounter> sets = StreamSupport.stream(iterable.spliterator(), false).map(PieceCounter::new).collect(Collectors.toSet());
        // ランダムに組み合わせを選択し、必ず列挙したセットの中にあることを確認
        for (int count = 0; count < 10000; count++) {
            List<Piece> combinations = randoms.sample(allPieces, pop);
            PieceCounter pieceCounter = new PieceCounter(combinations);
            assertThat(pieceCounter).isIn(sets);
        }
    }
}
Also used : Randoms(lib.Randoms) Piece(core.mino.Piece) PieceCounter(common.datastore.PieceCounter) Test(org.junit.jupiter.api.Test)

Aggregations

Randoms (lib.Randoms)108 Test (org.junit.jupiter.api.Test)103 Piece (core.mino.Piece)58 LongTest (module.LongTest)32 Field (core.field.Field)29 Action (common.datastore.action.Action)25 LongPieces (common.datastore.blocks.LongPieces)24 MinoFactory (core.mino.MinoFactory)20 ArrayList (java.util.ArrayList)19 LockedCandidate (core.action.candidate.LockedCandidate)17 Mino (core.mino.Mino)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 MinoShifter (core.mino.MinoShifter)14 MinoRotation (core.srs.MinoRotation)14 Rotate (core.srs.Rotate)13 Collectors (java.util.stream.Collectors)13 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)12 PatternGenerator (common.pattern.PatternGenerator)12 List (java.util.List)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)12