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

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWarframe.Loadouts;
using Xunit;

namespace XFEWarframe.Client.Tests;

public sealed class ModSearchTests
{
    private static ModCard Card(string key, string name, string text) => new(key, "/Lotus/Upgrades/Mods/" + key, name,
        "PRIMARY", key, 5, 5, 9, "AP_ATTACK", "RARE", "", "{\"lvl\":5}", 1, [0], text);
    private static readonly ModCard Cold = Card("WeaponFreezeDamageMod", "Cryo Rounds", "+90% <DT_FREEZE_COLOR>Cold\n冰冻伤害");
    private static readonly ModCard Toxin = Card("WeaponToxinDamageMod", "Infected Clip", "+90% <DT_POISON_COLOR>Toxin\n毒素伤害");
    private static readonly ModCard Heat = Card("WeaponFireDamageMod", "Hellfire", "+90% <DT_FIRE_COLOR>Heat\n火焰伤害");
    private static readonly ModCard Electric = Card("WeaponElectricityDamageMod", "Stormbringer", "+90% <DT_ELECTRICITY_COLOR>Electricity");
    private static readonly ModCard Viral = Card("Combined", "Combined", "+90% <DT_VIRAL_COLOR>Viral");

    [Theory]
    [InlineData("病毒")]
    [InlineData("viral")]
    [InlineData("  VIRAL  ")]
    [InlineData("病毒伤害")]
    public void ViralFindsBothIngredientsAndExistingViralWithoutHeatOrFireRate(string query)
    {
        var fireRate = Card("WeaponFireRateMod", "Speed Trigger", "+60% Fire Rate");
        var index = new ModSearchIndex([Cold, Toxin, Heat, Electric, Viral, fireRate]);
        Assert.Equal([Cold.Key, Toxin.Key, Viral.Key], index.Search(query).Select(x => x.Key));
        Assert.False(ModSearch.Matches(fireRate, "火"));
    }
    [Theory]
    [InlineData("腐蚀", "WeaponToxinDamageMod", "WeaponElectricityDamageMod")]
    [InlineData("磁力", "WeaponFreezeDamageMod", "WeaponElectricityDamageMod")]
    [InlineData("辐射", "WeaponFireDamageMod", "WeaponElectricityDamageMod")]
    [InlineData("爆炸", "WeaponFreezeDamageMod", "WeaponFireDamageMod")]
    [InlineData("毒气", "WeaponToxinDamageMod", "WeaponFireDamageMod")]
    public void OtherCombinedElementsFindTheirIngredients(string query, string first, string second)
    {
        var matches = new ModSearchIndex([Cold, Toxin, Heat, Electric]).Search(query).Select(x => x.Key).ToHashSet();
        Assert.Equal(2, matches.Count); Assert.Contains(first, matches); Assert.Contains(second, matches);
    }
    [Fact] public void EffectTextAndSeparateKeywordsDriveTheWholeCollectionSearch()
    {
        var criticalToxin = Toxin with { Key = "riven", Name = "Braton Acri", SearchText = "毒素伤害 <DT_POISON_COLOR> +120% Critical Chance 暴击几率" };
        var cards = Enumerable.Range(0, 130).Select(i => Card("filler" + i, "Filler", "无匹配内容"))
            .Append(criticalToxin).Append(Cold).ToArray();
        var index = new ModSearchIndex(cards);
        Assert.Equal(criticalToxin.Key, Assert.Single(index.Search("病毒 暴击")).Key);
        Assert.Equal(criticalToxin.Key, Assert.Single(index.Search("viral critical")).Key);
        Assert.Equal(criticalToxin.Key, Assert.Single(index.Search("120%" )).Key);
        Assert.Empty(index.Search("病毒 护甲"));
        Assert.Equal(cards.Length, index.Search(" \t ").Length);
        Assert.Equal(Cold.Key, Assert.Single(index.Search("/Lotus/Upgrades/Mods/WeaponFreezeDamageMod")).Key);
        Assert.Equal(criticalToxin.Key, Assert.Single(index.Search("病毒,暴击")).Key);
    }
    [Fact] public void ExplicitInstanceElementsDoNotIntroduceOtherRivenPossibilities()
    {
        var card = Toxin with { Type = "/Lotus/Upgrades/Mods/Randomized/RawRifleRandomMod", Elements = ["Toxin"], SearchText = "+90% 毒素伤害" };
        Assert.True(ModSearch.Matches(card, "病毒")); Assert.False(ModSearch.Matches(card, "冰"));
    }
    [Fact] public void CancellationStopsTheFullInventoryScan()
    {
        using var cancellation = new CancellationTokenSource(); cancellation.Cancel();
        Assert.Throws<OperationCanceledException>(() => new ModSearchIndex([Cold, Toxin]).Search("病毒", cancellation.Token));
    }
}