CounterDroneBackend/test/unit/CounterDrone.Core.Tests/TestData.cs
tian d8470bad30 Phase 10: 探测实时链路开发 + planner 诊断 + 硬编码消除
- 3D球冠探测: IsInCoverage, DetectionEntity, Tick 第5步扫描
- 探测融合: EarliestDetection 采样法, break 修复
- planner 诊断: HasInterceptWindow 拦截窗口检查
- TryGenerateFireEvents 返回拒绝原因
- Summary 含失败原因+建议值(探测范围/弧长)
- PlanningFailed 事件: 引擎在规划失败时发出事件
- 硬编码消除: Phase2Duration→AmmunitionSpec
  ExpansionFactor/TimingSafetyMargin→PlannerConfig
  速度从 waypoint.Speed 读取(不用 TypicalSpeed)
- TestData 改为从 seeded 数据库读取(不再内嵌 JSON)
- 默认数据加 3D球冠参数,巡航导弹速度300→200
  空基航路10km→20km, 位置调整
- 222 测试全通过
2026-06-16 14:10:23 +08:00

59 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using CounterDrone.Core;
using CounterDrone.Core.Models;
using SQLite;
namespace CounterDrone.Core.Tests
{
/// <summary>测试辅助:从 seeded 数据库读取(与生产环境同源)</summary>
internal static class TestData
{
private static readonly string _tempDir;
private static readonly SQLiteConnection _db;
static TestData()
{
_tempDir = Path.Combine(Path.GetTempPath(), $"cd_td_{Guid.NewGuid():N}");
var paths = new TestPathProvider(_tempDir);
var dbm = new DatabaseManager(paths);
_db = dbm.OpenMainDb();
}
private static List<AmmunitionSpec>? _ammo;
public static List<AmmunitionSpec> Ammo =>
_ammo ??= new List<AmmunitionSpec>(_db.Table<AmmunitionSpec>());
private static DefaultData? _all;
public static DefaultData All
{
get
{
if (_all == null)
{
var dir = TestPathProvider.FindProjectDataDirectory()!;
_all = DefaultData.Load(new DirPathProvider(dir));
}
return _all;
}
}
private class DirPathProvider : IPathProvider
{
private readonly string _dir;
public DirPathProvider(string dir) => _dir = dir;
public string GetDataRoot() => _dir;
public string GetMainDbPath() => throw new NotImplementedException();
public string GetFramesDir() => throw new NotImplementedException();
public string GetModelsDir() => throw new NotImplementedException();
}
public static void Cleanup()
{
_db?.Close();
if (Directory.Exists(_tempDir)) Directory.Delete(_tempDir, true);
}
}
}