import pytest
from src.triangle_program4 import classify_triangle4


@pytest.mark.cause_effect
class TestCauseEffectTriangleProgram4:
    """
    因果图法测试集（被测程序：triangle_program4）

    原因（Causes）：
    - C1: a,b,c 均为整数类型
    - C2: a,b,c 均为正数
    - C3: 满足三角形不等式（a+b>c 且 a+c>b 且 b+c>a）
    - C4: 三边全相等（a==b==c）
    - C5: 任意两边相等（a==b 或 a==c 或 b==c）

    结果（Effects）：
    - E1: 无效输入
    - E2: 非三角形
    - E3: 等边三角形
    - E4: 等腰三角形
    - E5: 一般三角形

    约束：
    - 优先级：E1 > E2 > E3 > E4 > E5
    - C4 => C5（全相等蕴含两边相等）
    - not C3 -> 不能出现 E3/E4/E5

    根据因果路径覆盖生成至少 10 个测试。
    """

    @pytest.mark.parametrize(
        "a,b,c,expected",
        [
            # 路径：not C1 -> E1
            (1.2, 2, 3, "无效输入"),
            ("x", 2, 3, "无效输入"),

            # 路径：C1 & not C2 -> E1
            (0, 2, 3, "无效输入"),
            (1, -2, 3, "无效输入"),

            # 路径：C1 & C2 & not C3 -> E2
            (1, 2, 3, "非三角形"),
            (3, 1, 5, "非三角形"),

            # 路径：C1 & C2 & C3 & C4 -> E3
            (7, 7, 7, "等边三角形"),

            # 路径：C1 & C2 & C3 & not C4 & C5 -> E4
            (6, 6, 7, "等腰三角形"),
            (6, 7, 6, "等腰三角形"),
            (7, 6, 6, "等腰三角形"),

            # 路径：C1 & C2 & C3 & not C4 & not C5 -> E5
            (5, 6, 7, "一般三角形"),
        ],
    )
    def test_cause_effect_core(self, a, b, c, expected):
        assert classify_triangle4(a, b, c) == expected

    @pytest.mark.parametrize(
        "a,b,c",
        [
            (2, 2, 4),  # not C3 & C5 -> 应为 E2
            (2, 5, 2),  # not C3 & C5 -> 应为 E2
        ],
    )
    def test_cause_effect_isosceles_not_triangle(self, a, b, c):
        assert classify_triangle4(a, b, c) == "非三角形"

    # 额外增强：一般三角形的排列不变性
    @pytest.mark.parametrize(
        "a,b,c",
        [
            (3, 4, 5),
            (4, 5, 3),
            (5, 3, 4),
        ],
        ids=["3-4-5", "4-5-3", "5-3-4"],
    )
    def test_permutation_invariance_general_triangle(self, a, b, c):
        assert classify_triangle4(a, b, c) == "一般三角形"

    # 仅依据题目文档的“正整数”与 src 行为进行测试，不引入额外规范假设
