// Path: src/main/java/io/github/novacrypto/base58/CapacityCalculator.java
// static int maximumBase58StringLength(final int byteLength) {
//     return (int) Math.ceil(byteLength * storageRatio);
// }
// 
// Path: src/test/java/io/github/novacrypto/base58/CapacityCalculatorTests.java
// static byte[] getBytesWithMaxValue(final int byteLength) {
//     final byte[] bytes = new byte[byteLength];
//     for (int i = 0; i < byteLength; i++) {
//         bytes[i] = (byte) 255;
//     }
//     return bytes;
// }


import org.junit.Test;
import static io.github.novacrypto.base58.CapacityCalculator.maximumBase58StringLength;
import static io.github.novacrypto.base58.CapacityCalculatorTests.getBytesWithMaxValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/*
 *  Base58 library, a Java implementation of Base58 encode/decode
 *  Copyright (C) 2017-2019 Alan Evans, NovaCrypto
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 *  Original source: https://github.com/NovaCrypto/Base58
 *  You can contact the authors via github issues.
 */

package io.github.novacrypto.base58;



public final class EncodeTargetCapacitySetTests {

    static class CapacityTargetSpy implements EncodeTargetCapacity, EncodeTarget {

        private boolean beforeAppend = true;
        int capacityOnFirstAppend;

        @Override
        public void setCapacity(final int characters) {
            assertTrue(beforeAppend);
            this.capacityOnFirstAppend = characters;
        }

        @Override
        public void append(final char c) {
            beforeAppend = false;
        }
    }

    static class CapacityTargetSpyFromCapacity implements EncodeTargetFromCapacity {

        int capacitySet;
        final StringBuilder sb = new StringBuilder();

        @Override
        public EncodeTarget withCapacity(final int characters) {
            capacitySet = characters;
            return sb::append;
        }
    }

    @Test
    public void sets_capacity_3bytes() {
        final CapacityTargetSpy spy = new CapacityTargetSpy();
// Path: src/main/java/io/github/novacrypto/base58/CapacityCalculator.java
// static int maximumBase58StringLength(final int byteLength) {
//     return (int) Math.ceil(byteLength * storageRatio);
// }
// 
// Path: src/test/java/io/github/novacrypto/base58/CapacityCalculatorTests.java
// static byte[] getBytesWithMaxValue(final int byteLength) {
//     final byte[] bytes = new byte[byteLength];
//     for (int i = 0; i < byteLength; i++) {
//         bytes[i] = (byte) 255;
//     }
//     return bytes;
// }


// Path: src/test/java/io/github/novacrypto/base58/EncodeTargetCapacitySetTests.java
import org.junit.Test;
import static io.github.novacrypto.base58.CapacityCalculator.maximumBase58StringLength;
import static io.github.novacrypto.base58.CapacityCalculatorTests.getBytesWithMaxValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/*
 *  Base58 library, a Java implementation of Base58 encode/decode
 *  Copyright (C) 2017-2019 Alan Evans, NovaCrypto
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 *  Original source: https://github.com/NovaCrypto/Base58
 *  You can contact the authors via github issues.
 */

package io.github.novacrypto.base58;



public final class EncodeTargetCapacitySetTests {

    static class CapacityTargetSpy implements EncodeTargetCapacity, EncodeTarget {

        private boolean beforeAppend = true;
        int capacityOnFirstAppend;

        @Override
        public void setCapacity(final int characters) {
            assertTrue(beforeAppend);
            this.capacityOnFirstAppend = characters;
        }

        @Override
        public void append(final char c) {
            beforeAppend = false;
        }
    }

    static class CapacityTargetSpyFromCapacity implements EncodeTargetFromCapacity {

        int capacitySet;
        final StringBuilder sb = new StringBuilder();

        @Override
        public EncodeTarget withCapacity(final int characters) {
            capacitySet = characters;
            return sb::append;
        }
    }

    @Test
    public void sets_capacity_3bytes() {
        final CapacityTargetSpy spy = new CapacityTargetSpy();
        Base58.newSecureInstance().encode(getBytesWithMaxValue(3), spy, spy);