55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using TuneBoss.Core.Models;
|
||
using Xunit;
|
||
|
||
namespace TuneBoss.Core.Tests;
|
||
|
||
public class OneDimDisplayTests
|
||
{
|
||
[Theory]
|
||
[InlineData(0, 1)]
|
||
[InlineData(1, 1)]
|
||
[InlineData(100, 100)]
|
||
[InlineData(50, 50)]
|
||
public void Multiplier_0_or_1_is_unscaled(int mult, int expected)
|
||
=> Assert.Equal(expected, OneDimDisplay.EffectiveMultiplier(mult));
|
||
|
||
[Theory]
|
||
[InlineData(130, 100, 13000)] // RPM
|
||
[InlineData(45, 1, 45)] // unscaled
|
||
[InlineData(7, 0, 7)] // mult 0 -> ×1
|
||
[InlineData(-5, 2, -10)] // signed
|
||
public void ToDisplay_scales(int raw, int mult, long expected)
|
||
=> Assert.Equal(expected, OneDimDisplay.ToDisplay(raw, mult));
|
||
|
||
[Theory]
|
||
[InlineData(13000, 100, 130)]
|
||
[InlineData(13100, 100, 131)]
|
||
[InlineData(42, 1, 42)]
|
||
[InlineData(-10, 2, -5)]
|
||
public void TryFromDisplay_accepts_multiples(double display, int mult, int expectedRaw)
|
||
{
|
||
Assert.True(OneDimDisplay.TryFromDisplay(display, mult, out int raw));
|
||
Assert.Equal(expectedRaw, raw);
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData(13050, 100)] // not a multiple of 100
|
||
[InlineData(42.5, 1)] // not a whole number
|
||
[InlineData(13, 5)] // not a multiple of 5
|
||
public void TryFromDisplay_rejects_non_multiples(double display, int mult)
|
||
{
|
||
Assert.False(OneDimDisplay.TryFromDisplay(display, mult, out _));
|
||
}
|
||
|
||
[Fact]
|
||
public void Round_trips_display_then_raw()
|
||
{
|
||
for (int raw = -120; raw <= 120; raw += 7)
|
||
{
|
||
long disp = OneDimDisplay.ToDisplay(raw, 100);
|
||
Assert.True(OneDimDisplay.TryFromDisplay(disp, 100, out int back));
|
||
Assert.Equal(raw, back);
|
||
}
|
||
}
|
||
}
|