kards-env/tests
lsamc 019cbed375 now add card and battle system. 2025-09-05 17:05:43 +08:00
..
__pycache__ now add card and battle system. 2025-09-05 17:05:43 +08:00
examples now add card and battle system. 2025-09-05 17:05:43 +08:00
integration now add card and battle system. 2025-09-05 17:05:43 +08:00
unit now add card and battle system. 2025-09-05 17:05:43 +08:00
README.md now add card and battle system. 2025-09-05 17:05:43 +08:00
__init__.py now add card and battle system. 2025-09-05 17:05:43 +08:00
run_tests.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_api_consistency.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_attack_count_limit.py.needs_fixing now add card and battle system. 2025-09-05 17:05:43 +08:00
test_card_loader.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_card_params.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_card_system.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_comprehensive_movement.py.disabled now add card and battle system. 2025-09-05 17:05:43 +08:00
test_event_system.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_interactive_attack.py.disabled now add card and battle system. 2025-09-05 17:05:43 +08:00
test_smokescreen_rules.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_turn_and_resources.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_turn_restrictions.py now add card and battle system. 2025-09-05 17:05:43 +08:00
test_yaml_unit_loader.py.disabled now add card and battle system. 2025-09-05 17:05:43 +08:00

README.md

KARDS Battle System 测试套件

这里包含了KARDS战斗系统的所有测试代码。

📁 测试结构

tests/
├── unit/                      # 单元测试
│   ├── test_unit_type_rules.py  # 单位类型战斗规则测试
│   └── test_artillery_simple.py # 火炮攻击测试
├── integration/               # 集成测试
│   ├── test_drag_system.py      # 拖拽操作系统测试
│   ├── test_corrected_battlefield.py # 战场系统测试
│   └── test_*.py               # 其他集成测试
├── examples/                  # 示例测试
│   └── test_readme_example.py   # README示例代码测试
└── run_tests.py               # 测试运行器

🚀 运行测试

运行所有测试

# 使用Shell脚本推荐
./run_tests.sh

# 使用Python测试运行器
python3 tests/run_tests.py

运行特定类型的测试

# 单元测试
python3 tests/unit/test_unit_type_rules.py
python3 tests/unit/test_artillery_simple.py

# 集成测试
python3 tests/integration/test_drag_system.py

# 示例测试
python3 tests/examples/test_readme_example.py

📋 测试内容

🔧 单元测试

  • test_unit_type_rules.py: 全面测试各兵种的战斗规则

    • 步兵攻击相邻战线规则
    • 火炮无视距离和守护,不受反击
    • 战斗机保护机制
    • 轰炸机不受反击规则
  • test_artillery_simple.py: 专门测试火炮不受反击机制

🔗 集成测试

  • test_drag_system.py: 测试真实的拖拽操作系统

    • 拖拽到空位 = 移动
    • 拖拽到敌方 = 攻击
    • 指挥点和激活成本管理
  • test_corrected_battlefield.py: 测试3线战场系统

    • 战场布局和控制权
    • 单位部署和移动

📖 示例测试

  • test_readme_example.py: 验证README中的示例代码正确工作

测试验证的功能

  • 真实的3条战线布局
  • 两种玩家操作:使用卡牌、拖动单位
  • 拖拽统一移动/攻击操作
  • 指挥点资源管理
  • 激活点数(油费)系统
  • 单位类型特殊规则
  • 战斗伤害和反击计算
  • 前线控制权机制
  • 挤位置移动规则

🎯 测试原则

  1. 不要防御式编程: 如果期望没达到就直接报错,不掩盖问题
  2. 完整性测试: 每个功能都要有对应的测试
  3. 真实场景: 测试要模拟真实的游戏使用场景
  4. 清晰输出: 测试结果要清晰显示通过/失败状态

🔧 添加新测试

  1. 在相应目录创建 test_*.py 文件
  2. 添加适当的路径设置:
    import sys
    import os
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
    
  3. 更新 run_tests.sh 包含新测试
  4. 确保测试输出清晰的通过/失败信息