using RioJoy.Core.Mapping;
using Xunit;

namespace RioJoy.Core.Tests.Mapping;

public class RioAddressTests
{
    [Fact]
    public void Button_MapsDirectly()
    {
        Assert.Equal(0x00, RioAddress.FromButton(0x00));
        Assert.Equal(0x47, RioAddress.FromButton(0x47));
    }

    [Fact]
    public void Button_RejectsOutOfRange()
    {
        Assert.Throws<ArgumentOutOfRangeException>(() => RioAddress.FromButton(0x48));
    }

    [Theory]
    [InlineData(0, 0x00, 0x50)]
    [InlineData(0, 0x0F, 0x5F)]
    [InlineData(1, 0x00, 0x60)]
    [InlineData(1, 0x0F, 0x6F)]
    public void Keypad_AppliesOffset(byte pad, byte index, int expected)
    {
        Assert.Equal(expected, RioAddress.FromKeypad(pad, index));
    }

    [Fact]
    public void Keypad_RejectsBadPadOrIndex()
    {
        Assert.Throws<ArgumentOutOfRangeException>(() => RioAddress.FromKeypad(2, 0));
        Assert.Throws<ArgumentOutOfRangeException>(() => RioAddress.FromKeypad(0, 0x10));
    }

    [Fact]
    public void TableSize_Is112()
    {
        Assert.Equal(112, RioAddress.TableSize);
        Assert.Equal(0x6F, RioAddress.MaxAddress);
    }
}
