// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForChar() {
//     return requireValidSizeChar(current().nextInt(1, Character.SIZE));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
//     return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
//     return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
//     return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static char randomValueForChar(final int size) {
//     return (char) (current().nextInt(Character.MAX_VALUE + 1) >> (Integer.SIZE - size));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomValueForInt(final boolean unsigned, final int size) {
//     final int value;
//     if (unsigned) {
//         value = current().nextInt() >>> (Integer.SIZE - size);
//         assertTrue(value >= 0);
//     } else {
//         value = current().nextInt() >> (Integer.SIZE - size);
//         if (size < Integer.SIZE) {
//             assertEquals(value >> size, value >= 0 ? 0 : -1);
//         }
//     }
//     return value;
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static long randomValueForLong(final boolean unsigned, final int size) {
//     final long value;
//     if (unsigned) {
//         value = current().nextLong() >>> (Long.SIZE - size);
//         assertTrue(value >= 0);
//     } else {
//         value = current().nextLong() >> (Long.SIZE - size);
//         if (size < Long.SIZE) {
//             assertEquals(value >> size, value >= 0L ? 0L : -1L);
//         }
//     }
//     return value;
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static short randomValueForShort(final boolean unsigned, final int size) {
//     final short value;
//     if (unsigned) {
//         value = (short) (current().nextInt() >>> (Integer.SIZE - size));
//         assertTrue(value >= 0);
//     } else {
//         value = (short) (current().nextInt() >> (Integer.SIZE - size));
//         assertEquals(value >> size, value >= 0 ? 0 : -1);
//     }
//     return value;
// }


import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
package com.github.jinahya.bit.io;

/*-
 * #%L
 * bit-io
 * %%
 * Copyright (C) 2014 - 2019 Jinahya, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * A class for unit-testing {@link AbstractBitOutput} class.
 *
 * @author Jin Kwon &lt;onacit_at_gmail.com&gt;
 * @see AbstractBitInputSpyTest
 */
@ExtendWith({MockitoExtension.class})
@Slf4j
final class AbstractBitOutputSpyTest {

    // -----------------------------------------------------------------------------------------------------------------
    @BeforeEach
    void stubWrite() throws IOException {
        //lenient().doNothing().when(bitOutput).write(anyInt());
    }

    // -----------------------------------------------------------------------------------------------------------------
    @AfterEach
    void alignAfterEach() throws IOException {
        bitOutput.align(current().nextInt(1, 8));
    }

    // --------------------------------------------------------------------------------------------------------- boolean
    @RepeatedTest(8)
    void testWriteBoolean() throws IOException {
        final boolean value = current().nextBoolean();
        bitOutput.writeBoolean(value);
    }

    // ------------------------------------------------------------------------------------------------------------ byte
    @RepeatedTest(8)
    void testWriteByte() throws IOException {
        final boolean unsigned = current().nextBoolean();
        final int size = BitIoTests.randomSizeForByte(unsigned);
        final byte value = BitIoTests.randomValueForByte(unsigned, size);
        bitOutput.writeByte(unsigned, size, value);
    }

    // ----------------------------------------------------------------------------------------------------------- short
    @RepeatedTest(8)
    void testWriteShort() throws IOException {
        final boolean unsigned = current().nextBoolean();
        final int size = randomSizeForShort(unsigned);
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForChar() {
//     return requireValidSizeChar(current().nextInt(1, Character.SIZE));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
//     return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
//     return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
//     return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static char randomValueForChar(final int size) {
//     return (char) (current().nextInt(Character.MAX_VALUE + 1) >> (Integer.SIZE - size));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomValueForInt(final boolean unsigned, final int size) {
//     final int value;
//     if (unsigned) {
//         value = current().nextInt() >>> (Integer.SIZE - size);
//         assertTrue(value >= 0);
//     } else {
//         value = current().nextInt() >> (Integer.SIZE - size);
//         if (size < Integer.SIZE) {
//             assertEquals(value >> size, value >= 0 ? 0 : -1);
//         }
//     }
//     return value;
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static long randomValueForLong(final boolean unsigned, final int size) {
//     final long value;
//     if (unsigned) {
//         value = current().nextLong() >>> (Long.SIZE - size);
//         assertTrue(value >= 0);
//     } else {
//         value = current().nextLong() >> (Long.SIZE - size);
//         if (size < Long.SIZE) {
//             assertEquals(value >> size, value >= 0L ? 0L : -1L);
//         }
//     }
//     return value;
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static short randomValueForShort(final boolean unsigned, final int size) {
//     final short value;
//     if (unsigned) {
//         value = (short) (current().nextInt() >>> (Integer.SIZE - size));
//         assertTrue(value >= 0);
//     } else {
//         value = (short) (current().nextInt() >> (Integer.SIZE - size));
//         assertEquals(value >> size, value >= 0 ? 0 : -1);
//     }
//     return value;
// }


// Path: src/test/java/com/github/jinahya/bit/io/AbstractBitOutputSpyTest.java
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

package com.github.jinahya.bit.io;

/*-
 * #%L
 * bit-io
 * %%
 * Copyright (C) 2014 - 2019 Jinahya, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * A class for unit-testing {@link AbstractBitOutput} class.
 *
 * @author Jin Kwon &lt;onacit_at_gmail.com&gt;
 * @see AbstractBitInputSpyTest
 */
@ExtendWith({MockitoExtension.class})
@Slf4j
final class AbstractBitOutputSpyTest {

    // -----------------------------------------------------------------------------------------------------------------
    @BeforeEach
    void stubWrite() throws IOException {
        //lenient().doNothing().when(bitOutput).write(anyInt());
    }

    // -----------------------------------------------------------------------------------------------------------------
    @AfterEach
    void alignAfterEach() throws IOException {
        bitOutput.align(current().nextInt(1, 8));
    }

    // --------------------------------------------------------------------------------------------------------- boolean
    @RepeatedTest(8)
    void testWriteBoolean() throws IOException {
        final boolean value = current().nextBoolean();
        bitOutput.writeBoolean(value);
    }

    // ------------------------------------------------------------------------------------------------------------ byte
    @RepeatedTest(8)
    void testWriteByte() throws IOException {
        final boolean unsigned = current().nextBoolean();
        final int size = BitIoTests.randomSizeForByte(unsigned);
        final byte value = BitIoTests.randomValueForByte(unsigned, size);
        bitOutput.writeByte(unsigned, size, value);
    }

    // ----------------------------------------------------------------------------------------------------------- short
    @RepeatedTest(8)
    void testWriteShort() throws IOException {
        final boolean unsigned = current().nextBoolean();
        final int size = randomSizeForShort(unsigned);
        final short value = randomValueForShort(unsigned, size);