using System.Collections; using Xunit; using ytLive.Helpers; namespace ytLive.Tests; /// /// The layer-list drag arithmetic, tested without a mouse. It replaced a test that injected REAL /// cursor movement into the desktop — which hijacked the machine and failed whenever it was busy /// (deleted 2026-11-05). Same behaviour covered here, in microseconds, with no input device. /// public class DragReorderMathTests { [Theory] [InlineData(0, 0, false)] // a click, not a drag [InlineData(3, 2, false)] // inside both thresholds (4 px is WPF's default) [InlineData(4, 0, true)] // exactly the threshold counts — WPF's own rule [InlineData(0, 4, true)] [InlineData(-9, 1, true)] // direction is irrelevant public void Threshold_DecidesDragVersusClick(double dx, double dy, bool dragging) => Assert.Equal(dragging, DragReorderMath.ExceededThreshold(dx, dy, 4, 4)); [Fact] public void MovingDown_LandsOnTheTargetsIndex() { var items = new ArrayList { "A", "B", "C" }; var landed = DragReorderMath.TryMove(items, 0, 2); Assert.Equal(2, landed); Assert.Equal(new[] { "B", "C", "A" }, items.Cast()); } [Fact] public void MovingUp_LandsOnTheTargetsIndex() { var items = new ArrayList { "A", "B", "C" }; var landed = DragReorderMath.TryMove(items, 2, 0); Assert.Equal(0, landed); Assert.Equal(new[] { "C", "A", "B" }, items.Cast()); } [Fact] public void DraggingOntoItself_IsANoOp() { var items = new ArrayList { "A", "B", "C" }; Assert.Equal(-1, DragReorderMath.TryMove(items, 1, 1)); Assert.Equal(new[] { "A", "B", "C" }, items.Cast()); } [Theory] [InlineData(-1, 0)] [InlineData(0, -1)] [InlineData(3, 0)] [InlineData(0, 3)] public void OutOfRangeIndices_ChangeNothing(int from, int to) { var items = new ArrayList { "A", "B", "C" }; Assert.Equal(-1, DragReorderMath.TryMove(items, from, to)); Assert.Equal(new[] { "A", "B", "C" }, items.Cast()); } [Fact] public void EmptyList_IsSafe() => Assert.Equal(-1, DragReorderMath.TryMove(new ArrayList(), 0, 0)); }