Initial Commit
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
using System.Numerics;
|
||||
using TuneBoss.Core.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace TuneBoss.Core.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// These are the high-value regression tests: they tie the bit-editor specs to the
|
||||
/// field registry and validate every mask. The "spec key exists" test is exactly what
|
||||
/// would have caught the ShiftBoss byte-84 mislabel and the Core_25/31/33/120 key drift.
|
||||
/// </summary>
|
||||
public class MiscBitSpecTests
|
||||
{
|
||||
[Fact]
|
||||
public void Every_spec_key_resolves_to_a_field()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
{
|
||||
bool found = MiscFieldRegistry.All.Any(
|
||||
f => f.Block == spec.Block && f.Label == spec.FieldLabel);
|
||||
|
||||
Assert.True(found,
|
||||
$"Spec '{spec.FieldLabel}' ({spec.Block}) has no matching MiscField — " +
|
||||
"the bit editor will silently fail to attach.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_returns_spec_by_key()
|
||||
{
|
||||
var s = MiscBitSpecRegistry.Find(MiscBlock.Core, "ShiftBoss_Enable");
|
||||
Assert.NotNull(s);
|
||||
Assert.Equal("ShiftBoss_Enable", s!.FieldLabel);
|
||||
|
||||
Assert.Null(MiscBitSpecRegistry.Find(MiscBlock.Core, "does_not_exist"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void All_masks_are_within_a_byte_and_nonzero()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
foreach (var f in spec.Fields)
|
||||
Assert.InRange(f.Mask, 1, 255);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Flag_fields_are_a_single_bit()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
foreach (var f in spec.Fields)
|
||||
if (f.Kind == MiscEditorKind.Flag)
|
||||
Assert.Equal(1, BitOperations.PopCount((uint)f.Mask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Enum_options_fit_the_mask_range()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
foreach (var f in spec.Fields)
|
||||
{
|
||||
if (f.Kind != MiscEditorKind.Enum) continue;
|
||||
Assert.NotNull(f.Options);
|
||||
int shift = BitOperations.TrailingZeroCount((uint)f.Mask);
|
||||
int maxVal = f.Mask >> shift; // e.g. 0x06 -> 3
|
||||
Assert.True(f.Options!.Length >= 2,
|
||||
$"{spec.FieldLabel}/{f.Label}: enum needs >= 2 options");
|
||||
Assert.True(f.Options.Length <= maxVal + 1,
|
||||
$"{spec.FieldLabel}/{f.Label}: {f.Options.Length} options exceed mask range {maxVal + 1}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fields_within_a_spec_do_not_overlap_bits()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
{
|
||||
int used = 0;
|
||||
foreach (var f in spec.Fields)
|
||||
{
|
||||
Assert.True((used & f.Mask) == 0,
|
||||
$"{spec.FieldLabel}: field '{f.Label}' mask 0x{f.Mask:X2} overlaps another field");
|
||||
used |= f.Mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constraint_indices_are_valid_bit_positions()
|
||||
{
|
||||
foreach (var spec in MiscBitSpecRegistry.All)
|
||||
{
|
||||
foreach (var (a, b) in spec.MutualExclusive ?? Enumerable.Empty<(int, int)>())
|
||||
{
|
||||
Assert.InRange(a, 0, 7);
|
||||
Assert.InRange(b, 0, 7);
|
||||
}
|
||||
foreach (var (a, b) in spec.Linked ?? Enumerable.Empty<(int, int)>())
|
||||
{
|
||||
Assert.InRange(a, 0, 7);
|
||||
Assert.InRange(b, 0, 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user