package conversion

import "testing"

var binaryTestCases = map[string]int{
	"0": 0, "1": 1, "10": 2, "11": 3, "100": 4,
	"101": 5, "110": 6, "111": 7, "1000": 8, "1001": 9,
	"1010": 10, "1011": 11, "1100": 12, "1101": 13, "1110": 14,
	"1111": 15, "10000": 16, "10001": 17, "10010": 18, "10011": 19,
	"10100": 20, "10101": 21, "10110": 22, "10111": 23, "11000": 24,
	"11001": 25, "11010": 26, "11011": 27, "11100": 28, "11101": 29,
	"11110": 30, "11111": 31, "100000": 32, "100001": 33, "100010": 34,
	"100011": 35, "100100": 36, "100101": 37, "100110": 38, "100111": 39,
	"101000": 40, "101001": 41, "101010": 42, "101011": 43, "101100": 44,
	"101101": 45, "101110": 46, "101111": 47, "110000": 48, "110001": 49,
	"110010": 50, "110011": 51, "110100": 52, "110101": 53, "110110": 54,
	"110111": 55, "111000": 56, "111001": 57, "111010": 58, "111011": 59,
	"111100": 60, "111101": 61, "111110": 62, "111111": 63, "1000000": 64,
	"1000001": 65, "1000010": 66, "1000011": 67, "1000100": 68, "1000101": 69,
	"1000110": 70, "1000111": 71, "1001000": 72, "1001001": 73, "1001010": 74,
	"1001011": 75, "1001100": 76, "1001101": 77, "1001110": 78, "1001111": 79,
	"1010000": 80, "1010001": 81, "1010010": 82, "1010011": 83, "1010100": 84,
	"1010101": 85, "1010110": 86, "1010111": 87, "1011000": 88, "1011001": 89,
	"1011010": 90, "1011011": 91, "1011100": 92, "1011101": 93, "1011110": 94,
	"1011111": 95, "1100000": 96, "1100001": 97, "1100010": 98, "1100011": 99,
	"1100100": 100,
}

func TestBinaryToDecimal(t *testing.T) {
	for input, expected := range binaryTestCases {
		out, err := BinaryToDecimal(input)
		if err != nil {
			t.Errorf("BinaryToDecimal(%s) returned an error %s", input, err.Error())
		}
		if out != expected {
			t.Errorf("BinaryToDecimal(%s) = %d; want %d", input, out, expected)
		}
	}
}

func BenchmarkBinaryToDecimal(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		_, _ = BinaryToDecimal("1100100")
	}
}
