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.Galaxy;
using XFEEDToolBox.Core.Models;

namespace XFEEDToolBox.Test;

[TestFixture]
public class GalaxyOriginalConstellationsTests
{
    static void Near(double expected, double actual) => Check.That(Math.Abs(expected - actual) < 1e-10,
        $"Expected {expected}, actual {actual}");

    [Test]
    public void ResourcePreservesExactOriginalGraphAndAuthoredOrder()
    {
        var groups = GalaxyOriginalConstellations.Definitions;
        Check.That(groups.Count == 16 && groups.Sum(g => g.Edges.Count) == 206);
        Check.That(groups[0].Name == "Aries" && groups[0].Edges.SequenceEqual(new[] {
            new GalaxyConstellationEdge("Hamal", "Sheratan"), new GalaxyConstellationEdge("Sheratan", "Mesarthim") }));
        Check.That(groups[9].Name == "Capricorn" && groups[15].Name == "Southern Cross");
        Check.That(groups[15].Edges.SequenceEqual(new[] { new GalaxyConstellationEdge("Acrux", "Gacrux"),
            new GalaxyConstellationEdge("Becrux", "Delta Crucis") }));
    }

    [Test]
    public void ReadyGroupsUseActualCoordinatesAndMissingEndpointNeverFabricatesPartialShape()
    {
        var facts = new Dictionary<string, Coordinates>(StringComparer.OrdinalIgnoreCase) {
            ["Hamal"] = new(17.125, -33.0625, 81.75), ["Sheratan"] = new(-14.75, 6, 120.125),
            ["Mesarthim"] = new(41.5, -72, 8.03125) };
        var calls = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
        var ready = GalaxyOriginalConstellations.Resolve(name => {
            calls[name] = calls.GetValueOrDefault(name) + 1; return facts.GetValueOrDefault(name); });
        Check.That(calls.Values.All(c => c == 1));
        Check.That(ready.Groups.Count == 1 && ready.Groups[0].Name == "Aries" && !ready.IsComplete);
        Check.That(ready.Groups[0].Lines[0].From == facts["Hamal"] && ready.Groups[0].Lines[1].To == facts["Mesarthim"]);
        facts.Remove("Mesarthim");
        var waiting = GalaxyOriginalConstellations.Resolve(facts.GetValueOrDefault);
        Check.That(waiting.Groups.Count == 0 && waiting.PendingGroupCount == 16 && waiting.MissingEndpointNames.Contains("Mesarthim"));
        facts["Mesarthim"] = new(double.NaN, 0, 0);
        Check.That(GalaxyOriginalConstellations.Resolve(facts.GetValueOrDefault).Groups.Count == 0);
    }

    [Test]
    public void OriginalFadeUsesEyeDistanceFromSolAndSquaredViewCosine()
    {
        var group = new GalaxyResolvedConstellation("fixture", new[] {
            new GalaxyConstellationLine("a", "b", new(0, 0, 100), new(40, 50, 60)) });
        Near(1, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 8), new(0, 0, 9)));
        Near(.5, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 16), new(0, 0, 17)));
        Near(0, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 24), new(0, 0, 25)));
        Near(0, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 0), new(0, 0, -1)));
        Near(.5, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 0), new(1, 0, 1)));
        var cutoffEye = new Coordinates(0, 0, 22.4);
        Check.That(GalaxyOriginalConstellations.Alpha(group, cutoffEye, new(0, 0, 23.4)) <= GalaxyOriginalConstellations.SubmissionAlpha);
    }

    [Test]
    public void DirectionMeanCountsOnlyFirstEndpointsAndDegenerateDirectionUsesOriginalPositiveZ()
    {
        var group = new GalaxyResolvedConstellation("fixture", new[] {
            new GalaxyConstellationLine("a", "z", new(1, 0, 0), new(-1000, 1000, 1000)),
            new GalaxyConstellationLine("a", "y", new(1, 0, 0), new(-1000, 1000, 1000)),
            new GalaxyConstellationLine("b", "x", new(0, 0, 2), new(-1000, 1000, 1000)) });
        Near(.5, GalaxyOriginalConstellations.Alpha(group, new(0, 0, 0), new(0, 0, 1)));
        var zero = new GalaxyResolvedConstellation("zero", new[] {
            new GalaxyConstellationLine("a", "b", new(0, 0, 0), new(1, 2, 3)) });
        Near(1, GalaxyOriginalConstellations.Alpha(zero, new(0, 0, 0), new(0, 0, 1)));
        Near(1, GalaxyOriginalConstellations.Alpha(zero, new(1, 0, 0), new(1, 0, 0)));
    }
}