use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ReverseOrderLookUpTest method parseJustRandom.
@Test
void parseJustRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 2; size <= 13; size++) {
List<Piece> blocks = randoms.blocks(size);
int fromDepth = blocks.size();
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(blocks.size(), fromDepth);
List<LongPieces> reverse = reverseOrderLookUp.parse(blocks).map(LongPieces::new).collect(Collectors.toList());
LongPieces target = new LongPieces(blocks);
ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(blocks.size(), fromDepth);
for (LongPieces pieces : reverse) {
boolean isFound = forwardOrderLookUp.parse(pieces.getPieces()).map(LongPieces::new).anyMatch(target::equals);
assertThat(isFound).isTrue();
}
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ReverseOrderLookUpTest method parseOverRandom.
@Test
@LongTest
void parseOverRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 2; size <= 13; size++) {
List<Piece> pieces = randoms.blocks(size);
int fromDepth = pieces.size() + 1;
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(pieces.size(), fromDepth);
List<Stream<Piece>> reverse = reverseOrderLookUp.parse(pieces).collect(Collectors.toList());
LongPieces target = new LongPieces(pieces);
ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(pieces.size(), fromDepth);
for (Stream<Piece> stream : reverse) {
List<Piece> sample = stream.map(block -> block != null ? block : randoms.block()).collect(Collectors.toList());
boolean isFound = forwardOrderLookUp.parse(sample).map(LongPieces::new).anyMatch(target::equals);
assertThat(isFound).isTrue();
}
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ReverseOrderLookUpTest method parseOver2Random.
@Test
void parseOver2Random() throws Exception {
Randoms randoms = new Randoms();
for (int size = 2; size <= 12; size++) {
List<Piece> pieces = randoms.blocks(size);
int fromDepth = pieces.size() + 2;
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(pieces.size(), fromDepth);
List<Stream<Piece>> reverse = reverseOrderLookUp.parse(pieces).collect(Collectors.toList());
LongPieces target = new LongPieces(pieces);
ForwardOrderLookUp forwardOrderLookUp = new ForwardOrderLookUp(pieces.size(), fromDepth);
for (Stream<Piece> stream : reverse) {
List<Piece> sample = stream.map(block -> block != null ? block : randoms.block()).collect(Collectors.toList());
boolean isFound = forwardOrderLookUp.parse(sample).map(LongPieces::new).anyMatch(target::equals);
assertThat(isFound).isTrue();
}
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ForwardOrderLookUpTest method parseJustBlocksRandom.
@Test
void parseJustBlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 2; size <= 15; size++) {
List<Piece> pieces = randoms.blocks(size);
int toDepth = pieces.size();
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, 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;
}
}
// ホールドを追加
sample.add(pieces.get(holdIndex));
assertThat(new LongPieces(sample)).isIn(forward);
}
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ForwardOrderLookUpTest method parseJustBlocks.
@Test
void parseJustBlocks() throws Exception {
List<Piece> pieceList = Arrays.asList(Piece.I, Piece.T, Piece.Z, Piece.O, Piece.I, Piece.L);
int toDepth = pieceList.size();
PiecesNumberComparator comparator = new PiecesNumberComparator();
List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
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