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);
}
}
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();
}
}
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());
}
}
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();
}
}
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);
}
}
}
Aggregations