import unittest
from pathlib import Path

from policyfaultbench.mutations import OPERATORS, generate_first_order_mutants
from policyfaultbench.mutation_eval import evaluate_mutations
from policyfaultbench.policy import PolicySet


ROOT = Path(__file__).resolve().parents[1]


class MutationTests(unittest.TestCase):
    def test_all_first_order_mutants_are_generated_and_distinct(self):
        policy = PolicySet.load(ROOT / "policies/reference_policy.json")
        mutants = generate_first_order_mutants(policy)
        self.assertEqual(len(OPERATORS), 12)
        self.assertEqual(len(mutants), 12)
        self.assertEqual({m.mutation_id for m in mutants},
                         {f"M{i:02d}" for i in range(1, 13)})
        self.assertEqual(len({str(m.as_dict()) for m in mutants}), 12)

    def test_expanded_suite_kills_all_mutants_without_reference_failures(self):
        report = evaluate_mutations(ROOT)
        self.assertEqual(report["reference_failures"], [])
        self.assertEqual(report["core_killed"], 7)
        self.assertEqual(report["expanded_killed"], 12)
        self.assertEqual(report["expanded_mutation_score"], 1.0)


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