"""test_qubo_modules.py — QUBO pipeline module tests."""

from __future__ import annotations

import sys
import unittest
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "qubo"))


class TestFinslerMetric(unittest.TestCase):
    """finsler_metric: Hachimoji state + Finsler distance computation."""

    def test_import(self):
        import finsler_metric
        self.assertTrue(hasattr(finsler_metric, "make_uniform_hachimoji_states"))
        self.assertTrue(hasattr(finsler_metric, "compute_finsler_distance_matrix"))

    def test_states_are_8(self):
        from finsler_metric import make_uniform_hachimoji_states
        states = make_uniform_hachimoji_states()
        self.assertEqual(len(states), 8)

    def test_greek_states_are_8(self):
        from finsler_metric import GREEK_STATES
        self.assertEqual(len(GREEK_STATES), 8)


class TestQuboBuilder(unittest.TestCase):
    """qubo_builder: QUBO matrix construction."""

    def test_import(self):
        import qubo_builder
        self.assertTrue(hasattr(qubo_builder, "QUBO"))
        self.assertTrue(hasattr(qubo_builder, "build_equation_qubo"))

    def test_qubo_has_8_vars(self):
        from qubo_builder import QUBO
        q = QUBO(n=8)
        self.assertEqual(q.n, 8)

    def test_brute_force(self):
        from qubo_builder import QUBO, brute_force_qubo
        q = QUBO(n=4, matrix={(0, 0): -1.0, (1, 1): -2.0})
        result = brute_force_qubo(q)
        self.assertIn("solution", result)
        self.assertIn("energy", result)


class TestQaoaCircuit(unittest.TestCase):
    """qaoa_circuit: QAOA circuit description."""

    def test_import(self):
        import qaoa_circuit
        self.assertTrue(hasattr(qaoa_circuit, "build_qaoa_circuit_description"))


class TestClassicalSolver(unittest.TestCase):
    """classical_solver: classical optimization solvers."""

    def test_import(self):
        import classical_solver
        self.assertTrue(hasattr(classical_solver, "solve_classical"))


class TestConflictSweep(unittest.TestCase):
    """conflict_sweep: CONFLICT_PENALTY sweep analysis."""

    def test_import(self):
        import conflict_sweep
        self.assertTrue(hasattr(conflict_sweep, "run_sweep"))
        self.assertTrue(hasattr(conflict_sweep, "analyze_sweep"))

        import fsr_validation
        self.assertTrue(hasattr(fsr_validation, "sweep_k"))
        self.assertTrue(hasattr(fsr_validation, "detect_critical_k"))


if __name__ == "__main__":
    unittest.main()
