import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))

from blooms import BLOOMS_VERBS, classify_blooms


def test_no_verb_appears_in_more_than_one_level():
    """Every verb in BLOOMS_VERBS must belong to exactly one Bloom's level.

    classify_blooms() walks BLOOMS_VERBS in dict-insertion order and returns
    the FIRST level whose verb set contains the matched verb. A verb listed
    in two levels is therefore silently pinned to whichever level happens to
    iterate first, regardless of which level is the "correct" one. See #218:
    compare/contrast/distinguish lived in both Understand and Analyze, so
    they always resolved to Understand even though differentiate (a synonym,
    Analyze-only) resolved to Analyze -- opposite verdicts for synonymous verbs.
    """
    levels = list(BLOOMS_VERBS.keys())
    duplicates = []
    for i, level_a in enumerate(levels):
        for level_b in levels[i + 1:]:
            overlap = BLOOMS_VERBS[level_a] & BLOOMS_VERBS[level_b]
            if overlap:
                duplicates.append((level_a, level_b, sorted(overlap)))
    assert not duplicates, f"Verbs appear in multiple Bloom's levels: {duplicates}"


def test_distinguish_classifies_as_analyze():
    verb, level = classify_blooms("Distinguish the holdings")
    assert level == "Analyze"


def test_contrast_classifies_as_analyze():
    verb, level = classify_blooms("Contrast the holdings")
    assert level == "Analyze"


def test_compare_classifies_as_analyze():
    verb, level = classify_blooms("Compare the holdings")
    assert level == "Analyze"
