use of lib.Randoms in project solution-finder by knewjade.
the class VisitedTreeTest method random.
@Test
void random() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 1; size <= 7; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
VisitedTree tree = new VisitedTree();
HashSet<LongPieces> success = new HashSet<>();
HashSet<LongPieces> failed = new HashSet<>();
generator.blocksStream().forEach(pieces -> {
boolean flag = randoms.nextBoolean();
List<Piece> blocks = pieces.getPieces();
tree.set(flag, blocks);
LongPieces longPieces = new LongPieces(blocks);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
});
assertThat(isFailed).isTrue();
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class VisitedTreeTest method randomLong.
@Test
@LongTest
void randomLong() throws SyntaxException {
Randoms randoms = new Randoms();
for (int size = 8; size <= 11; size++) {
PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
VisitedTree tree = new VisitedTree();
HashSet<LongPieces> success = new HashSet<>();
HashSet<LongPieces> failed = new HashSet<>();
generator.blocksStream().forEach(pieces -> {
boolean flag = randoms.nextBoolean();
List<Piece> blocks = pieces.getPieces();
tree.set(flag, blocks);
LongPieces longPieces = new LongPieces(blocks);
if (flag) {
success.add(longPieces);
} else {
failed.add(longPieces);
}
});
boolean isSucceed = success.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
});
assertThat(isSucceed).isTrue();
boolean isFailed = failed.stream().allMatch(pieces -> {
List<Piece> blocks = pieces.getPieces();
return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
});
assertThat(isFailed).isTrue();
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class FullOperationSeparableMinoComparatorTest method compareMinoFieldDiff.
@Test
void compareMinoFieldDiff() {
List<SeparableMino> minos = separableMinos.getMinos();
Randoms randoms = new Randoms();
FullOperationSeparableMinoComparator comparator = new FullOperationSeparableMinoComparator();
for (int count = 0; count < 100000; count++) {
int index1 = randoms.nextInt(minos.size() - 1);
int index2 = randoms.nextInt(minos.size());
if (index1 == index2)
index2 += 1;
// assert is not 0 & sign reversed
SeparableMino mino1 = minos.get(index1);
SeparableMino mino2 = minos.get(index2);
assertThat(comparator.compare(mino1, mino2) * comparator.compare(mino2, mino1)).isLessThan(0);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class MinoFieldComparatorTest method compareMinoFieldDiffSize.
@Test
void compareMinoFieldDiffSize() {
Randoms randoms = new Randoms();
List<SeparableMino> minos = separableMinos.getMinos();
int index = randoms.nextInt(0, minos.size() - 1);
SeparableMino mino = minos.get(index);
RecursiveMinoField recursiveMinoField1 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
RecursiveMinoField recursiveMinoField2 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
recursiveMinoField2 = new RecursiveMinoField(mino, recursiveMinoField2, ColumnFieldFactory.createField(), separableMinos);
// assert is not 0 & sign reversed
MinoFieldComparator comparator = new MinoFieldComparator();
assertThat(comparator.compare(recursiveMinoField1, recursiveMinoField2) * comparator.compare(recursiveMinoField2, recursiveMinoField1)).isLessThan(0);
}
use of lib.Randoms in project solution-finder by knewjade.
the class HoldBreakEnumeratePiecesTest method enumerateOverRandom.
@Test
void enumerateOverRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 3; size <= 15; size++) {
List<Piece> blocks = randoms.blocks(size);
String pattern = blocks.stream().map(Piece::getName).collect(Collectors.joining(","));
PatternGenerator blocksGenerator = new LoadedPatternGenerator(pattern);
HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(blocksGenerator, size - 1);
Set<LongPieces> pieces = core.enumerate();
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(blocks.get(index));
} else {
// ホールドを追加
sample.add(blocks.get(holdIndex));
holdIndex = index;
}
}
assertThat(new LongPieces(sample)).isIn(pieces);
}
}
}
Aggregations