package org.usi.sq.util.numbers;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class NumberCheckerBranchCoverageTest {
    INumberChecker nc = null;
    @BeforeEach
    public void createNumberChecker(){
        nc = NumberCheckerFactory.create();
    }

    @Test
    public void emptyStringNotHex() {
        assertFalse(nc.isHexNumber(""));
    }

    @Test
    public void plusNotHex() {
        assertFalse(nc.isHexNumber("+"));
    }

    @Test
    public void oneOneNotHex() {
        assertFalse(nc.isHexNumber("11"));
    }

    @Test
    public void zeroBNotHex() {
        assertFalse(nc.isHexNumber("0B"));
    }

    @Test
    public void zeroXNotHex() {
        assertFalse(nc.isHexNumber("0x"));
    }

    @Test
    public void zeroXGNotHex() {
        assertFalse(nc.isHexNumber("0xG"));
    }

    @Test
    public void zeroXZeroHex() {
        assertTrue(nc.isHexNumber("0x0"));
    }

    // NOTE: JaCoCo does not really measure branch coverage, but modified condition coverage (MCC). The following tests
    // are needed to satisfy MCC, remove them for a minimal 100% branch coverage test suite

    @Test
    public void nullIsNotHex() {
        assertFalse(nc.isHexNumber(null));
    }

    @Test
    public void offByOneNotHex() {
        assertFalse(nc.isHexNumber("-0X!"));
        assertFalse(nc.isHexNumber("-0Xg"));
    }

    @Test
    public void zeroXBIsHex() {
        assertTrue(nc.isHexNumber("0xB"));
        assertTrue(nc.isHexNumber("0xb"));
    }
}
