tests / test_tutorial.py
# -*- coding: utf-8 -*-
"""测试:教程系统 tutorial.py
验证:
1. TutorialScene 初始化
2. 第0天场景数量(6个)
3. 第1天核爆场景数量(3个)
4. TutorialManager 初始化和运行
5. 教程完成标志
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + "/..")
from src.tutorial import (
TutorialScene,
TutorialManager,
TUTORIAL_DAY0_SCENES,
NUCLEAR_DAY1_SCENES,
start_tutorial,
)
def test_tutorial_scene_init():
"""测试 TutorialScene 初始化。"""
scene = TutorialScene(
name="测试场景",
description="这是一个测试场景",
location="测试地点",
teaching_points=[("点1", "描述1"), ("点2", "描述2")]
)
assert scene.name == "测试场景"
assert scene.description == "这是一个测试场景"
assert scene.location == "测试地点"
assert len(scene.teaching_points) == 2
print("[OK] TutorialScene init")
def test_day0_scenes_count():
"""测试第0天场景数量为6个。"""
assert len(TUTORIAL_DAY0_SCENES) == 6, f"期望6个第0天场景,实际{len(TUTORIAL_DAY0_SCENES)}个"
print(f"[OK] Day0 scenes count: {len(TUTORIAL_DAY0_SCENES)}")
def test_nuclear_day1_scenes_count():
"""测试第1天核爆场景数量为3个。"""
assert len(NUCLEAR_DAY1_SCENES) == 3, f"期望3个核爆场景,实际{len(NUCLEAR_DAY1_SCENES)}个"
print(f"[OK] Nuclear day1 scenes count: {len(NUCLEAR_DAY1_SCENES)}")
def test_day0_scene_names():
"""测试第0天场景名称正确。"""
expected_names = [
"早晨·宿舍",
"上午·无线电实验室",
"中午·食堂",
"下午·校园探索",
"晚上·校园散步",
"夜晚·宿舍",
]
actual_names = [s.name for s in TUTORIAL_DAY0_SCENES]
assert actual_names == expected_names, f"场景名称不匹配\n期望: {expected_names}\n实际: {actual_names}"
print("[OK] Day0 scene names correct")
def test_nuclear_day1_scene_names():
"""测试第1天核爆场景名称正确。"""
expected_names = [
"次日早晨·核爆",
"中午·山洞",
"下午·逃出大连",
]
actual_names = [s.name for s in NUCLEAR_DAY1_SCENES]
assert actual_names == expected_names, f"场景名称不匹配\n期望: {expected_names}\n实际: {actual_names}"
print("[OK] Nuclear day1 scene names correct")
def test_tutorial_manager_init():
"""测试 TutorialManager 初始化。"""
mgr = TutorialManager()
assert mgr.tutorial_complete is False
assert mgr.current_scene_idx == 0
assert len(mgr.day0_scenes) == 6
assert len(mgr.nuclear_day1_scenes) == 3
print("[OK] TutorialManager init")
def test_tutorial_manager_skip():
"""测试 TutorialManager.skip_tutorial。"""
mgr = TutorialManager()
assert mgr.tutorial_complete is False
mgr.skip_tutorial()
assert mgr.tutorial_complete is True
print("[OK] TutorialManager skip_tutorial")
def test_start_tutorial():
"""测试 start_tutorial 入口函数。"""
tutorial = start_tutorial()
assert isinstance(tutorial, TutorialManager)
assert tutorial.tutorial_complete is False
print("[OK] start_tutorial returns TutorialManager")
def test_scene_teaching_points():
"""测试场景教学点内容不为空。"""
for i, scene in enumerate(TUTORIAL_DAY0_SCENES):
assert len(scene.teaching_points) > 0, f"第{i}个场景 '{scene.name}' 没有教学点"
for i, scene in enumerate(NUCLEAR_DAY1_SCENES):
assert len(scene.teaching_points) > 0, f"核爆第{i}个场景 '{scene.name}' 没有教学点"
print("[OK] All scenes have teaching points")
def test_scene_locations():
"""测试场景地点不为空。"""
for scene in TUTORIAL_DAY0_SCENES:
assert scene.location, f"场景 '{scene.name}' 地点为空"
for scene in NUCLEAR_DAY1_SCENES:
assert scene.location, f"场景 '{scene.name}' 地点为空"
print("[OK] All scenes have locations")
if __name__ == "__main__":
test_tutorial_scene_init()
test_day0_scenes_count()
test_nuclear_day1_scenes_count()
test_day0_scene_names()
test_nuclear_day1_scene_names()
test_tutorial_manager_init()
test_tutorial_manager_skip()
test_start_tutorial()
test_scene_teaching_points()
test_scene_locations()
print("\n[ALL PASSED] All tests passed.")