lib.Randoms.sample()

Here are the examples of the java api lib.Randoms.sample() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

16 Source : NeighborTest.java
with MIT License
from knewjade

@Test
void getNextMovesSources() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.createPieces());
    Randoms randoms = new Randoms();
    ArrayList<Neighbor> all = new ArrayList<>();
    // left
    for (OriginalPiece sample : randoms.sample(pieces, 3)) {
        Neighbor nei = new Neighbor(sample);
        if (!all.contains(nei)) {
            neighbor.updateLeft(nei);
            all.add(nei);
        }
    }
    // right
    for (OriginalPiece sample : randoms.sample(pieces, 3)) {
        Neighbor nei = new Neighbor(sample);
        if (!all.contains(nei)) {
            neighbor.updateRight(nei);
            all.add(nei);
        }
    }
    // up
    for (OriginalPiece sample : randoms.sample(pieces, 3)) {
        Neighbor nei = new Neighbor(sample);
        if (!all.contains(nei)) {
            neighbor.updateUp(nei);
            all.add(nei);
        }
    }
    replacedertThat(neighbor.getNextMovesSources()).containsAll(all);
}

15 Source : NeighborTest.java
with MIT License
from knewjade

@Test
void getNextLeftRotateSources() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.createPieces());
    Randoms randoms = new Randoms();
    List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
    neighbor.updateLeftRotateSource(samples);
    replacedertThat(neighbor.getNextLeftRotateSources()).containsAll(samples);
}

15 Source : NeighborTest.java
with MIT License
from knewjade

@Test
void getNextRightRotateSources() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.createPieces());
    Randoms randoms = new Randoms();
    List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
    neighbor.updateRightRotateSource(samples);
    replacedertThat(neighbor.getNextRightRotateSources()).containsAll(samples);
}

15 Source : NeighborTest.java
with MIT License
from knewjade

@Test
void getNextRightRotateDestinations() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.createPieces());
    Randoms randoms = new Randoms();
    List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
    neighbor.updateRightRotateDestination(samples);
    replacedertThat(neighbor.getNextRightRotateDestinations()).containsAll(samples);
}

15 Source : NeighborTest.java
with MIT License
from knewjade

@Test
void getNextLeftRotateDestinations() {
    OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
    Neighbor neighbor = new Neighbor(piece);
    OriginalPieceFactory factory = new OriginalPieceFactory(4);
    List<OriginalPiece> pieces = new ArrayList<>(factory.createPieces());
    Randoms randoms = new Randoms();
    List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
    neighbor.updateLeftRotateDestination(samples);
    replacedertThat(neighbor.getNextLeftRotateDestinations()).containsAll(samples);
}

12 Source : PermutationIterableTest.java
with MIT License
from knewjade

@Test
@LongTest
void iteratorRandomBlock() throws Exception {
    Randoms randoms = new Randoms();
    ArrayList<Piece> allPieces = Lists.newArrayList(Iterables.concat(Piece.valueList(), Piece.valueList()));
    for (int pop = 1; pop <= 7; pop++) {
        PermutationIterable<Piece> iterable = new PermutationIterable<>(allPieces, pop);
        HashSet<LongPieces> sets = StreamSupport.stream(iterable.spliterator(), false).map(Collection::stream).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
        // ランダムにサンプルを選択し、必ず列挙したセットの中にあることを確認
        for (int count = 0; count < 500; count++) {
            List<Piece> sample = randoms.sample(allPieces, pop);
            LongPieces pieces = new LongPieces(sample);
            replacedertThat(pieces).isIn(sets);
        }
    }
}

8 Source : CombinationIterableTest.java
with MIT License
from knewjade

@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);
            replacedertThat(pieceCounter).isIn(sets);
        }
    }
}

5 Source : PiecesNumberComparatorTest.java
with MIT License
from knewjade

@Test
void compareDiffRandom() throws Exception {
    List<Piece> allPieces = Arrays.asList(Piece.T, Piece.I, Piece.O, Piece.S, Piece.Z, Piece.J, Piece.L, Piece.T, Piece.I, Piece.O, Piece.S, Piece.Z, Piece.J, Piece.L);
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        List<Piece> blocks1 = randoms.sample(allPieces, randoms.nextIntOpen(10));
        List<Piece> blocks2 = randoms.sample(allPieces, randoms.nextIntOpen(10));
        if (blocks1.equals(blocks2))
            blocks1.add(Piece.O);
        LongPieces pieces1 = new LongPieces(blocks1);
        LongPieces pieces2 = new LongPieces(blocks2);
        // replacedert is not 0 & sign reversed
        PiecesNumberComparator comparator = new PiecesNumberComparator();
        replacedertThat(comparator.compare(pieces1, pieces2) * comparator.compare(pieces2, pieces1)).as(pieces2.toString()).isLessThan(0);
    }
}

5 Source : PiecesNameComparatorTest.java
with MIT License
from knewjade

@Test
void compareDiffRandom() throws Exception {
    List<Piece> allPieces = Arrays.asList(Piece.T, Piece.I, Piece.O, Piece.S, Piece.Z, Piece.J, Piece.L, Piece.T, Piece.I, Piece.O, Piece.S, Piece.Z, Piece.J, Piece.L);
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        List<Piece> blocks1 = randoms.sample(allPieces, randoms.nextIntOpen(10));
        List<Piece> blocks2 = randoms.sample(allPieces, randoms.nextIntOpen(10));
        if (blocks1.equals(blocks2))
            blocks1.add(Piece.O);
        LongPieces pieces1 = new LongPieces(blocks1);
        LongPieces pieces2 = new LongPieces(blocks2);
        // replacedert is not 0 & sign reversed
        PiecesNameComparator comparator = new PiecesNameComparator();
        replacedertThat(comparator.compare(pieces1, pieces2) * comparator.compare(pieces2, pieces1)).as(pieces2.toString()).isLessThan(0);
    }
}