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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

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

namespace XFEEDToolBox.Test;

[TestFixture]
public sealed class TradeSearchRegionTests
{
    [Test]public void NewDefaultsAndLegacyDefaultRadiusBecome500WhileCustomValuesPersist()
    {
        Check.Equal(500d,new ToolboxSettings().MarketCacheRadiusLy);Check.Equal(500d,new PlannerRequest().SearchRadiusLy);
        using var temporary=new TemporaryDirectory();var path=temporary.File("settings.json");
        File.WriteAllText(path,"{\"planner\":{\"searchRadiusLy\":150}}");
        var migrated=ToolboxSettings.Load(path);Check.Equal(500d,migrated.MarketCacheRadiusLy);Check.Equal(500d,migrated.Planner.SearchRadiusLy);
        File.WriteAllText(path,"{\"planner\":{\"searchRadiusLy\":275}}");
        var customised=ToolboxSettings.Load(path);Check.Equal(275d,customised.MarketCacheRadiusLy);Check.Equal(275d,customised.Planner.SearchRadiusLy);
        var settings=customised with{MarketCacheRadiusLy=150,MarketCacheCenterName="Selected",MarketCacheCenterPosition=new(1000,2,3)};
        settings.Save(path);var reopened=ToolboxSettings.Load(path);
        Check.Equal(150d,reopened.MarketCacheRadiusLy);Check.Equal("Selected",reopened.MarketCacheCenterName);Check.Equal(settings.MarketCacheCenterPosition,reopened.MarketCacheCenterPosition);
        Check.Throws<ArgumentException>(()=>(settings with{MarketCacheRadiusLy=0}).Save(path));
    }

    [Test]public void SelectedCacheCenterDoesNotMoveThePlayerOrOpenUnknownGlobalData()
    {
        var player=new PlayerState{Position=new(0,0,0),SystemName="Real ship",MarketId=1};var center=new Coordinates(10000,0,0);
        Check.That(NearbyMarketCachePolicy.Accepts(player,Check.Station(2,10499),center:center,radius:500,centerName:"Selected"));
        Check.That(!NearbyMarketCachePolicy.Accepts(player,Check.Station(2,10501),center:center,radius:500,centerName:"Selected"));
        Check.That(!NearbyMarketCachePolicy.Accepts(player,Check.Station(2,1),center:center,radius:500,centerName:"Selected"));
        Check.That(NearbyMarketCachePolicy.Accepts(player,Check.Station(1,1),center:center,radius:500,centerName:"Selected"));
        Check.That(!NearbyMarketCachePolicy.Accepts(player,Check.Station(2) with{Position=null,SystemName="Unknown"},center:center,radius:500,centerName:"Selected"));
        Check.Equal(new Coordinates(0,0,0),player.Position!);
    }

    [Test]public void PlannerFiltersAroundTheSelectedCenterAndChargesTravelFromTheRealShip()
    {
        var book=new MarketBook([Check.Station(1,100),Check.Station(2,130),Check.Station(3,80)],
            [Check.Quote(1,"water",100,90),Check.Quote(2,"water",0,180),Check.Quote(3,"water",0,1000)]);
        var request=Check.Request with{SearchCenterPosition=new(120,0,0),SearchCenterName="Selected",SearchRadiusLy=20,
            CurrentPosition=new(0,0,0),CurrentSystemName="Real ship",CurrentMarketId=9,Loop=false,MaxLegs=1};
        var plan=new TradeRoutePlanner().Calculate(book,request);
        Check.Equal(2L,plan.Legs.Single().To.MarketId);Check.Equal(100d,plan.DeadheadDistanceLy);
        Check.Equal(new Coordinates(0,0,0),plan.Request.CurrentPosition!);Check.Equal(new Coordinates(120,0,0),plan.Request.SearchCenterPosition!);
        Check.Throws<ArgumentException>(()=>new TradeRoutePlanner().Calculate(book,request with{SearchCenterPosition=new(150,0,0)}));
        Check.Throws<ArgumentException>(()=>(request with{SearchCenterPosition=new(double.NaN,0,0)}).Validate());
    }
}