use of lib.Randoms in project solution-finder by knewjade.
the class PermutationIterableTest method iteratorRandomBlock.
@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 < 1000; count++) {
List<Piece> sample = randoms.sample(allPieces, pop);
LongPieces pieces = new LongPieces(sample);
assertThat(pieces).isIn(sets);
}
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class ForwardOrderLookUpTest method parseOverBlocksRandom.
@Test
void parseOverBlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 3; size <= 15; size++) {
List<Piece> pieces = randoms.blocks(size);
int toDepth = pieces.size();
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth - 1, pieces.size());
HashSet<LongPieces> forward = lookUp.parse(pieces).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
for (int count = 0; count < 10000; count++) {
ArrayList<Piece> sample = new ArrayList<>();
int holdIndex = 0;
for (int index = 1; index < size; index++) {
if (randoms.nextBoolean(0.3)) {
// そのまま追加
sample.add(pieces.get(index));
} else {
// ホールドを追加
sample.add(pieces.get(holdIndex));
holdIndex = index;
}
}
assertThat(new LongPieces(sample)).isIn(forward);
}
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class OperationHistoryTest method random.
@Test
void random() throws ExecutionException, InterruptedException {
Randoms randoms = new Randoms();
for (int count = 0; count < 1000; count++) {
int size = randoms.nextInt(1, 10);
ArrayList<Operation> operations = new ArrayList<>();
OperationHistory history = new OperationHistory(size);
for (int index = 0; index < size; index++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int y = randoms.nextInt(4);
int x = randoms.nextInt(10);
MinimalAction action = MinimalAction.create(x, y, rotate);
history = history.recordAndReturnNew(piece, action);
operations.add(new SimpleOperation(piece, rotate, x, y));
}
List<Operation> actual = history.getOperationStream().collect(Collectors.toList());
assertThat(actual).isEqualTo(operations);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class OrderLookupTest method reverseOver2BlocksRandom.
@Test
void reverseOver2BlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int fromDepth = pieceList.size() + 2;
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 OrderLookupTest method reverseJustBlocksRandom.
@Test
void reverseJustBlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int fromDepth = pieceList.size();
PiecesNumberComparator comparator = new PiecesNumberComparator();
List<LongPieces> forward1 = OrderLookup.reverseBlocks(pieceList, fromDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
ReverseOrderLookUp lookUp = new ReverseOrderLookUp(pieceList.size(), fromDepth);
List<LongPieces> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
assertThat(forward2).isEqualTo(forward1);
}
}
Aggregations