use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class NormalEnumeratePiecesTest method enumerateJustRandomNoHold.
@Test
void enumerateJustRandomNoHold() throws Exception {
List<Piece> failedPieces = Arrays.asList(Piece.I, Piece.O, Piece.L, Piece.J, Piece.S, Piece.Z);
List<Piece> allPieces = new ArrayList<>(Piece.valueList());
for (int size = 1; size <= 7; size++) {
PatternGenerator blocksGenerator = new LoadedPatternGenerator("T, *p" + size);
NormalEnumeratePieces core = new NormalEnumeratePieces(blocksGenerator, size + 1, false);
Set<LongPieces> pieces = core.enumerate();
for (int count = 0; count < 1000; count++) {
List<Piece> sample = new ArrayList<>();
sample.add(Piece.T);
Collections.shuffle(allPieces);
sample.addAll(allPieces.subList(0, size));
assertThat(new LongPieces(sample)).isIn(pieces);
for (Piece piece : failedPieces) {
sample.set(0, piece);
assertThat(new LongPieces(sample)).isNotIn(pieces);
}
}
}
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class NormalEnumeratePiecesTest method enumerateHoldMulti.
@Test
void enumerateHoldMulti() throws Exception {
PatternGenerator generator = new LoadedPatternGenerator(Arrays.asList("T, J, O, Z, I", "J, O, S, T, Z", "T, J, O, I, S", "T, J, O, Z, I"));
NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 3, true);
Set<LongPieces> pieces = core.enumerate();
assertThat(pieces).hasSize(3);
assertThat(core.getCounter()).isEqualTo(4);
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class NormalEnumeratePiecesTest method enumerateHoldOver2.
@Test
void enumerateHoldOver2() throws Exception {
PatternGenerator generator = new LoadedPatternGenerator("*p7");
NormalEnumeratePieces core = new NormalEnumeratePieces(generator, 4, true);
Set<LongPieces> pieces = core.enumerate();
assertThat(pieces).hasSize(2520);
assertThat(core.getCounter()).isEqualTo(5040);
}
use of common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class ForwardOrderLookUpTest method parseOver2BlocksRandom.
@Test
void parseOver2BlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 4; size <= 15; size++) {
List<Piece> pieces = randoms.blocks(size);
int toDepth = pieces.size();
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth - 2, 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 - 1; 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 common.datastore.blocks.LongPieces in project solution-finder by knewjade.
the class OrderLookupTest method forwardOver2BlocksRandom.
@Test
void forwardOver2BlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 4; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int toDepth = pieceList.size() - 2;
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