lib.Randoms.nextBoolean()

Here are the examples of the java api lib.Randoms.nextBoolean() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

21 Examples 7

17 Source : SmallFieldTest.java
with MIT License
from knewjade

@Test
void slideLeft() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new SmallField();
        Field expected = new SmallField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 0; x < slide; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = slide; x < FIELD_WIDTH; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x - slide, y);
                }
            }
        }
        field.slideLeft(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : SmallFieldTest.java
with MIT License
from knewjade

@Test
void slideRight() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new SmallField();
        Field expected = new SmallField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 9; 9 - slide < x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = 9 - slide; 0 <= x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x + slide, y);
                }
            }
        }
        field.slideRight(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : SmallFieldTest.java
with MIT License
from knewjade

@Test
void slideDown() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new SmallField();
        Field expected = new SmallField();
        for (int x = 0; x < FIELD_WIDTH; x++) {
            if (randoms.nextBoolean())
                field.setBlock(x, 0);
        }
        for (int y = 1; y < FIELD_HEIGHT; y++) {
            for (int x = 0; x < FIELD_WIDTH; x++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x, y - 1);
                }
            }
        }
        field.slideDown();
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : MiddleFieldTest.java
with MIT License
from knewjade

@Test
void slideLeft() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new MiddleField();
        Field expected = new MiddleField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 0; x < slide; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = slide; x < FIELD_WIDTH; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x - slide, y);
                }
            }
        }
        field.slideLeft(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : MiddleFieldTest.java
with MIT License
from knewjade

@Test
void slideRight() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new MiddleField();
        Field expected = new MiddleField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 9; 9 - slide < x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = 9 - slide; 0 <= x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x + slide, y);
                }
            }
        }
        field.slideRight(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : MiddleFieldTest.java
with MIT License
from knewjade

@Test
void slideDown() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new MiddleField();
        Field expected = new MiddleField();
        for (int x = 0; x < FIELD_WIDTH; x++) {
            if (randoms.nextBoolean())
                field.setBlock(x, 0);
        }
        for (int y = 1; y < FIELD_HEIGHT; y++) {
            for (int x = 0; x < FIELD_WIDTH; x++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x, y - 1);
                }
            }
        }
        field.slideDown();
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : LargeFieldTest.java
with MIT License
from knewjade

@Test
void slideDown() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new LargeField();
        Field expected = new LargeField();
        for (int x = 0; x < FIELD_WIDTH; x++) {
            if (randoms.nextBoolean())
                field.setBlock(x, 0);
        }
        for (int y = 1; y < FIELD_HEIGHT; y++) {
            for (int x = 0; x < FIELD_WIDTH; x++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x, y - 1);
                }
            }
        }
        field.slideDown();
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : LargeFieldTest.java
with MIT License
from knewjade

@Test
void isWallBetweenLeft() throws Exception {
    Randoms randoms = new Randoms();
    for (int y = 0; y < FIELD_HEIGHT; y++) {
        for (int x = 1; x < FIELD_WIDTH; x++) {
            Field field = FieldFactory.createLargeField();
            for (int i = 0; i < y; i++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, i);
                else
                    field.setBlock(x - 1, i);
            }
            for (int i = 0; i < FIELD_HEIGHT; i++) replacedertThat(field.isWallBetweenLeft(x, i)).isEqualTo(i <= y);
        }
    }
}

17 Source : LargeFieldTest.java
with MIT License
from knewjade

@Test
void slideRight() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new LargeField();
        Field expected = new LargeField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 9; 9 - slide < x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = 9 - slide; 0 <= x; x--) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x + slide, y);
                }
            }
        }
        field.slideRight(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : LargeFieldTest.java
with MIT License
from knewjade

@Test
void slideLeft() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 100000; count++) {
        Field field = new LargeField();
        Field expected = new LargeField();
        int slide = randoms.nextIntClosed(0, 9);
        for (int x = 0; x < slide; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean())
                    field.setBlock(x, y);
            }
        }
        for (int x = slide; x < FIELD_WIDTH; x++) {
            for (int y = 0; y < FIELD_HEIGHT; y++) {
                if (randoms.nextBoolean()) {
                    field.setBlock(x, y);
                    expected.setBlock(x - slide, y);
                }
            }
        }
        field.slideLeft(slide);
        replacedertThat(field).isEqualTo(expected);
    }
}

17 Source : KeyOperatorsTest.java
with MIT License
from knewjade

@Test
void extractLowerBit() {
    Randoms randoms = new Randoms();
    for (int y = 0; y < 24; y++) {
        long key = KeyOperators.getBitKey(y);
        long current = key;
        for (int dy = y + 1; dy < 24; dy++) {
            if (randoms.nextBoolean()) {
                current |= KeyOperators.getBitKey(dy);
            }
        }
        replacedertThat(KeyOperators.extractLowerBit(current)).isEqualTo(key);
    }
}

16 Source : LongBoardMapTest.java
with MIT License
from knewjade

@Test
void deleteLine() {
    Randoms randoms = new Randoms();
    BooleanWalker.walk(6).forEach(booleans -> {
        SmallField field = new SmallField();
        SmallField expect = new SmallField();
        int expectY = 0;
        for (int y = 0; y < booleans.size(); y++) {
            if (booleans.get(y)) {
                // ラインを全て埋める
                for (int x = 0; x < 10; x++) field.setBlock(x, y);
            } else {
                // ラインを全て埋めない
                for (int x = 0; x < 10; x++) {
                    if (randoms.nextBoolean(0.8)) {
                        field.setBlock(x, y);
                        expect.setBlock(x, expectY);
                    }
                }
                int removeX = randoms.nextIntOpen(0, 10);
                field.removeBlock(removeX, y);
                expect.removeBlock(removeX, expectY);
                expectY += 1;
            }
        }
        long board = field.getXBoard();
        long deleteKey = KeyOperators.getDeleteKey(board);
        replacedertThat(LongBoardMap.deleteLine(board, deleteKey)).isEqualTo(expect.getXBoard());
    });
}

16 Source : LongBoardMapTest.java
with MIT License
from knewjade

@Test
void insertWhiteLine() {
    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)) {
                // ラインを空白にする
                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.nextIntOpen(0, 10);
                expect.removeBlock(removeX, y);
                field.removeBlock(removeX, expectY);
                expectY += 1;
            }
        }
        long board = field.getXBoard();
        replacedertThat(LongBoardMap.insertWhiteLine(board, deleteKey)).isEqualTo(expect.getXBoard());
    });
}

16 Source : LongBoardMapTest.java
with MIT License
from knewjade

@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.nextIntOpen(0, 10);
                expect.removeBlock(removeX, y);
                field.removeBlock(removeX, expectY);
                expectY += 1;
            }
        }
        long board = field.getXBoard();
        replacedertThat(LongBoardMap.insertBlackLine(board, deleteKey)).isEqualTo(expect.getXBoard());
    });
}

16 Source : KeyOperatorsTest.java
with MIT License
from knewjade

@Test
void getDeleteKey() {
    Randoms randoms = new Randoms();
    BooleanWalker.walk(6).forEach(booleans -> {
        SmallField field = new SmallField();
        long expectDeleteKey = 0L;
        for (int y = 0; y < booleans.size(); y++) {
            if (booleans.get(y)) {
                // ラインを全て埋める
                for (int x = 0; x < 10; x++) field.setBlock(x, y);
                expectDeleteKey += KeyOperators.getDeleteBitKey(y);
            } else {
                // ラインを全て埋めない
                for (int x = 0; x < 10; x++) if (randoms.nextBoolean(0.8))
                    field.setBlock(x, y);
                field.removeBlock(randoms.nextIntOpen(0, 10), y);
            }
        }
        long board = field.getXBoard();
        long deleteKey = KeyOperators.getDeleteKey(board);
        replacedertThat(deleteKey).isEqualTo(expectDeleteKey);
    });
}

16 Source : BuildUpStreamTest.java
with MIT License
from knewjade

private SolutionFilter createRandomSolutionFilter(Randoms randoms, SizedBit sizedBit, LockedReachableThreadLocal lockedReachableThreadLocal, Field field) {
    if (randoms.nextBoolean(0.3))
        return new SRSValidSolutionFilter(field, lockedReachableThreadLocal, sizedBit);
    else
        return new AllPreplacededSolutionFilter();
}

15 Source : HoldBreakEnumeratePiecesTest.java
with MIT License
from knewjade

@Test
void enumerateJustRandom() 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);
        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;
                }
            }
            // ホールドを追加
            sample.add(blocks.get(holdIndex));
            replacedertThat(new LongPieces(sample)).isIn(pieces);
        }
    }
}

15 Source : HoldBreakEnumeratePiecesTest.java
with MIT License
from knewjade

@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;
                }
            }
            replacedertThat(new LongPieces(sample)).isIn(pieces);
        }
    }
}

12 Source : ForwardOrderLookUpTest.java
with MIT License
from knewjade

@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;
                }
            }
            replacedertThat(new LongPieces(sample)).isIn(forward);
        }
    }
}

12 Source : ForwardOrderLookUpTest.java
with MIT License
from knewjade

@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;
                }
            }
            replacedertThat(new LongPieces(sample)).isIn(forward);
        }
    }
}

12 Source : ForwardOrderLookUpTest.java
with MIT License
from knewjade

@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));
            replacedertThat(new LongPieces(sample)).isIn(forward);
        }
    }
}