use of lib.Randoms in project solution-finder by knewjade.
the class OrderLookupTest method reverseOverBlocksRandom.
@Test
void reverseOverBlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int fromDepth = pieceList.size() + 1;
Comparator<List<Piece>> comparator = new ListComparator<>(Comparator.nullsFirst(Comparator.comparingInt(Piece::getNumber)));
List<List<Piece>> forward1 = OrderLookup.reverseBlocks(pieceList, fromDepth).stream().map(StackOrder::toList).sorted(comparator).collect(Collectors.toList());
ReverseOrderLookUp lookUp = new ReverseOrderLookUp(pieceList.size(), fromDepth);
List<List<Piece>> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).sorted(comparator).collect(Collectors.toList());
assertThat(forward2).isEqualTo(forward1);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class OperationInterpreterTest method parseRandom.
@Test
void parseRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size < 20; size++) {
List<Operation> operationList = Stream.generate(() -> {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int x = randoms.nextInt(10);
int y = randoms.nextInt(4);
return new SimpleOperation(piece, rotate, x, y);
}).limit(size).collect(Collectors.toList());
Operations operations = new Operations(operationList);
String str = OperationInterpreter.parseToString(operations);
Operations actual = OperationInterpreter.parseToOperations(str);
assertThat(actual).isEqualTo(operations);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class PieceInterpreterTest method parseRandom.
@Test
void parseRandom() {
Randoms randoms = new Randoms();
for (int count = 0; count < 10000; count++) {
int size = randoms.nextInt(1, 100);
List<Piece> pieces = randoms.blocks(size);
String name = pieces.stream().map(Piece::getName).collect(Collectors.joining());
Stream<Piece> stream = BlockInterpreter.parse(name);
assertThat(stream).containsExactlyElementsOf(pieces);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class FieldFactoryTest method testRandom.
@Test
void testRandom() {
Randoms randoms = new Randoms();
int width = 10;
for (int count = 0; count < 10000; count++) {
int height = randoms.nextIntClosed(1, 12);
boolean[][] fields = new boolean[height][width];
for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) fields[y][x] = randoms.nextBoolean();
StringBuilder builder = new StringBuilder();
for (int y = height - 1; 0 <= y; y--) {
for (int x = 0; x < width; x++) {
boolean isEmpty = fields[y][x];
builder.append(isEmpty ? '_' : 'X');
}
}
String marks = builder.toString();
Field field = FieldFactory.createField(marks);
for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) assertThat(field.isEmpty(x, y)).isEqualTo(fields[y][x]);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class LongBoardMapTest method insertBlackLine.
@Test
void insertBlackLine() {
Randoms randoms = new Randoms();
BooleanWalker.walk(6).forEach(booleans -> {
SmallField expect = new SmallField();
SmallField field = new SmallField();
long deleteKey = 0L;
int expectY = 0;
for (int y = 0; y < booleans.size(); y++) {
if (booleans.get(y)) {
// ラインを全て埋める
for (int x = 0; x < 10; x++) expect.setBlock(x, y);
deleteKey += KeyOperators.getDeleteBitKey(y);
} else {
// ラインを全て埋めない
for (int x = 0; x < 10; x++) {
if (randoms.nextBoolean(0.8)) {
expect.setBlock(x, y);
field.setBlock(x, expectY);
}
}
int removeX = randoms.nextInt(0, 10);
expect.removeBlock(removeX, y);
field.removeBlock(removeX, expectY);
expectY += 1;
}
}
long board = field.getXBoard();
assertThat(LongBoardMap.insertBlackLine(board, deleteKey)).isEqualTo(expect.getXBoard());
});
}
Aggregations