XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEEDToolBox.Core.Galaxy;
using XFEExtension.NetCore.XUnit.Attributes;

namespace XFEEDToolBox.Test;

[TestFixture]
public sealed class GalaxyViewportThrottleTests
{
    [Test] public void ContinuousInputPublishesProgressInsteadOfPostponingUntilRelease()
    {
        var throttle=new GalaxyViewportThrottle();var times=new List<double>();
        for(var t=0;t<=1000;t+=10){throttle.Changed();if(throttle.TryPublish(t))times.Add(t);}
        Check.Equal(6,times.Count);Check.Equal(0d,times[0]);Check.Equal(1000d,times[^1]);
        Check.That(times.Zip(times.Skip(1)).All(pair=>pair.Second-pair.First>=200));
    }
    [Test] public void EndingTheGesturePublishesTheLatestPoseImmediatelyAndIdleDoesNotRepeat()
    {
        var throttle=new GalaxyViewportThrottle();throttle.Changed();Check.That(throttle.TryPublish(0));
        throttle.Changed();Check.That(!throttle.TryPublish(45));Check.That(throttle.TryPublish(45,true));
        Check.That(!throttle.Pending&&!throttle.TryPublish(1000));
        throttle.Changed();Check.Equal(155d,throttle.Delay(90));
        throttle.Reset();Check.That(!throttle.Pending);throttle.Changed();Check.That(throttle.TryPublish(91));
    }
}