"""
pytest 测试用例：用于对白盒测试示例程序 security_decision 进行逻辑覆盖分析。

设计思路：
- 使用 8 个核心用例穷举 three-factor 布尔组合，满足条件组合覆盖与路径覆盖；
- 补充 4 个冗余用例，突出可疑路径（仅 two_factor 为真）并满足“≥12 个用例”的实验要求。
"""

from __future__ import annotations

import pytest

from src.security_decision_program import security_decision


# 8 个核心用例：覆盖 3 个条件的全部 2^3 组合以及 5 条独立执行路径
@pytest.mark.parametrize(
    "two_factor,strong_password,trusted_device,expected",
    [
        # P1: two_factor=True 且 (strong_password or trusted_device)=True → 高安全等级
        (True, True, True, "High Security"),
        (True, True, False, "High Security"),
        (True, False, True, "High Security"),
        # P2: 可疑路径——仅 two_factor=True, 其它为 False
        # 按题意“既不使用强密码，也不在可信设备上登录”应拒绝登录，
        # 因此这里期望 "Access Denied"，用于暴露程序缺陷。
        (True, False, False, "Access Denied"),
        # P3: 无双因素，但使用强密码且在可信设备上登录 → 中安全等级
        (False, True, True, "Medium Security"),
        # P4: 无双因素，且仅使用强密码或仅在可信设备上登录 → 低安全等级
        (False, True, False, "Low Security"),
        (False, False, True, "Low Security"),
        # P5: 不使用强密码，也不在可信设备上登录 → 拒绝登录
        (False, False, False, "Access Denied"),
    ],
)
def test_security_decision_core_paths(two_factor, strong_password, trusted_device, expected):
    """核心用例集：覆盖全部布尔组合和独立路径。"""
    assert security_decision(two_factor, strong_password, trusted_device) == expected


# 4 个扩展用例：重复关键路径，用于观察覆盖工具统计与缺陷稳定复现
@pytest.mark.parametrize(
    "two_factor,strong_password,trusted_device,expected",
    [
        # 再次覆盖高安全路径
        (True, True, True, "High Security"),
        # 再次覆盖仅强密码的低安全路径
        (False, True, False, "Low Security"),
        # 再次覆盖仅可信设备的低安全路径
        (False, False, True, "Low Security"),
        # 再次覆盖中安全路径
        (False, True, True, "Medium Security"),
    ],
)
def test_security_decision_redundant_for_coverage(two_factor, strong_password, trusted_device, expected):
    """冗余用例：满足“≥12 个用例”要求，并用于稳定复现关键路径。"""
    assert security_decision(two_factor, strong_password, trusted_device) == expected


