package com.fusi24.entryPermitScanner;

import org.junit.Test;

import java.util.Locale;

import static org.junit.Assert.assertEquals;

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ScanResultUnitTest {

    private String numberRfid = "";

    @Test
    public void formatOneDigit() {
        numberRfid = addZeroToDigit(1);
        assertEquals("0000000001", numberRfid);
    }

    @Test
    public void formatTwoDigit() {
        numberRfid = addZeroToDigit(12);
        assertEquals("0000000012", numberRfid);
    }

    @Test
    public void formatThreeDigit() {
        numberRfid = addZeroToDigit(123);
        assertEquals("0000000123", numberRfid);
    }

    @Test
    public void formatFourDigit() {
        numberRfid = addZeroToDigit(1234);
        assertEquals("0000001234", numberRfid);
    }

    @Test
    public void formatFiveDigit() {
        numberRfid = addZeroToDigit(12345);
        assertEquals("0000012345", numberRfid);
    }

    @Test
    public void formatSixDigit() {
        numberRfid = addZeroToDigit(123456);
        assertEquals("0000123456", numberRfid);
    }

    @Test
    public void formatSevenDigit() {
        numberRfid = addZeroToDigit(1234567);
        assertEquals("0001234567", numberRfid);
    }

    @Test
    public void formatEightDigit() {
        numberRfid = addZeroToDigit(12345678);
        assertEquals("0012345678", numberRfid);
    }

    @Test
    public void formatNineDigit() {
        numberRfid = addZeroToDigit(123456789);
        assertEquals("0123456789", numberRfid);
    }

    // Call this method if digit < 10
    private String addZeroToDigit(Integer number){
        /* FORMAT "%010d"
         * % ==> used as formatter, 0 ==> used to pad with zeroes instead of spaces
         * 10 ==> maximum of 10 characters wide
         * d ==> as a decimal integer */
        return String.format(Locale.getDefault(), "%010d", number);
    }
}