import pytest

from genesis.persona.mbti import mbti_to_behavior, normalize_mbti


def test_normalize_valid():
    assert normalize_mbti(" intp ") == "INTP"


@pytest.mark.parametrize("bad", ["INT", "INTPX", "XNTP", "1234", "", "INTX"])
def test_normalize_invalid(bad):
    with pytest.raises(ValueError):
        normalize_mbti(bad)


def test_extravert_more_social_than_introvert():
    assert mbti_to_behavior("ENTP").social_initiative > mbti_to_behavior("INTP").social_initiative


def test_intuitive_more_novelty_than_sensing():
    assert mbti_to_behavior("INTP").novelty_seeking > mbti_to_behavior("ISTP").novelty_seeking


def test_feeler_more_agreeable_than_thinker():
    assert mbti_to_behavior("INFP").agreeableness > mbti_to_behavior("INTP").agreeableness


def test_judger_more_routine_than_perceiver():
    assert mbti_to_behavior("ESTJ").routine_strictness > mbti_to_behavior("ESTP").routine_strictness


def test_thinker_more_assertive_than_feeler():
    assert mbti_to_behavior("INTJ").assertiveness > mbti_to_behavior("INFJ").assertiveness


def test_young_more_night_owl_than_old():
    assert mbti_to_behavior("INTP", age=20).night_owl > mbti_to_behavior("INTP", age=70).night_owl


def test_all_knobs_in_unit_range():
    for mbti in ("INTP", "ESFJ", "ENTP", "ISTJ", "INFP", "ESTP"):
        for age in (18, 30, 80):
            for value in mbti_to_behavior(mbti, age).to_dict().values():
                assert 0.0 <= value <= 1.0
