1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| """ FP400风格的多目标追踪测试 """
import numpy as np
def test_point_cloud_generation(): """测试点云生成""" adc = np.random.randn(4, 64, 256, 4) * 0.1 + 1j * np.random.randn(4, 64, 256, 4) * 0.1 adc[:, 32, 100, :] += 10 processor = FP400PointCloudProcessor(num_tx=4, num_rx=4) points = processor.generate_point_cloud(adc) assert points.shape[1] == 4, "点云格式错误" print(f"✓ 生成 {len(points)} 个点")
def test_multi_target_tracking(): """测试多目标追踪""" tracker = MultiTargetTracker(max_targets=5, cluster_eps=0.3) np.random.seed(42) t1 = np.random.randn(20, 4) * 0.1 + [1.0, 0.5, 0.5, 5] t2 = np.random.randn(15, 4) * 0.1 + [2.0, -0.5, 0.5, 5] t3 = np.random.randn(10, 4) * 0.1 + [0.5, 1.5, 0.5, 5] points = np.vstack([t1, t2, t3]) tracks = tracker.update(points) assert len(tracks) == 3, f"Expected 3 tracks, got {len(tracks)}" print(f"✓ 追踪到 {len(tracks)} 个目标")
def test_seat_assignment(): """测试座椅分配""" tracker = CabinOccupantTracker() tracks = [ {'id': 0, 'position': np.array([0.35, -0.42, 0.5]), 'intensity': 5}, {'id': 1, 'position': np.array([0.28, 0.38, 0.5]), 'intensity': 5}, ] result = tracker.assign_to_seats(tracks) assert result['driver'] is not None, "驾驶员未检测到" assert result['passenger'] is not None, "副驾未检测到" print(f"✓ 座椅分配: driver={result['driver']['track_id']}, " f"passenger={result['passenger']['track_id']}")
def test_ai_anti_interference(): """测试AI抗干扰""" classifier = AIAntiInterference() np.random.seed(42) history = [] for i in range(30): history.append({ 'position': np.array([1.0 + np.sin(i*0.1)*0.01, 0.5, 0.5]), 'velocity': np.array([np.cos(i*0.1)*0.001, 0, 0]), 'intensity': 5 + np.sin(i*0.3) * 0.5 }) result = classifier.classify_target(history) assert result == 'human', f"Expected 'human', got '{result}'" print(f"✓ 分类结果: {result}")
if __name__ == "__main__": print("=" * 60) print("FP400 多目标追踪测试套件") print("=" * 60) test_point_cloud_generation() test_multi_target_tracking() test_seat_assignment() test_ai_anti_interference() print("=" * 60) print("所有测试通过 ✓") print("=" * 60)
|