# Path: upho/irreps/irreps.py
# def find_rotation_type(rotation):
#     # https://doi.org/10.1107/S0108767398010186
#     tr = np.trace(rotation)
#     det = int(round(np.linalg.det(rotation)))
#     return {
#         (-2, -1): -6,
#         (-1, -1): -4,
#         ( 0, -1): -3,
#         (+1, -1): -2,
#         (-3, -1): -1,
#         (+3, +1): +1,
#         (-1, +1): +2,
#         ( 0, +1): +3,
#         (+1, +1): +4,
#         (+2, +1): +6,
#     }[(tr, det)]


import pytest
import numpy as np
from upho.irreps.irreps import find_rotation_type
from upho.irreps.character_tables import (
    character_tables, find_rotation_type_from_class_label)
    '-6m2', '6/mmm', '23'  , 'm-3'  , '432'  ,
    '-43m', 'm-3m' ,
)


class TestCharacterTables:
    def test_ir_labels_length(self):
        for pg in pointgroup_symbols:
            print("{:6s}:".format(pg), end=" ")
            current_max = 0
            if pg in character_tables:
                ir_labels = character_tables[pg]["ir_labels"]
                current_max = max(max(len(s) for s in ir_labels), current_max)
                print(ir_labels, current_max)

                is_orthogonal = self.is_orthogonal(
                    character_tables[pg]["character_table"])
                assert is_orthogonal
            else:
                print("Not implemented yet.")
        assert current_max == 3

    @staticmethod
    def is_orthogonal(character_table):
        character_table = np.array(character_table)
        for i0, v0 in enumerate(character_table.T):
            for i1, v1 in enumerate(character_table.T):
                if i0 != i1 and not np.isclose(np.dot(v0, np.conj(v1)), 0.0):
                    print(i0, i1, np.dot(v0, v1))
                    return False

# Path: upho/irreps/irreps.py
# def find_rotation_type(rotation):
#     # https://doi.org/10.1107/S0108767398010186
#     tr = np.trace(rotation)
#     det = int(round(np.linalg.det(rotation)))
#     return {
#         (-2, -1): -6,
#         (-1, -1): -4,
#         ( 0, -1): -3,
#         (+1, -1): -2,
#         (-3, -1): -1,
#         (+3, +1): +1,
#         (-1, +1): +2,
#         ( 0, +1): +3,
#         (+1, +1): +4,
#         (+2, +1): +6,
#     }[(tr, det)]


# Path: tests/irreps/test_character_tables.py
import pytest
import numpy as np
from upho.irreps.irreps import find_rotation_type
from upho.irreps.character_tables import (
    character_tables, find_rotation_type_from_class_label)

    '-6m2', '6/mmm', '23'  , 'm-3'  , '432'  ,
    '-43m', 'm-3m' ,
)


class TestCharacterTables:
    def test_ir_labels_length(self):
        for pg in pointgroup_symbols:
            print("{:6s}:".format(pg), end=" ")
            current_max = 0
            if pg in character_tables:
                ir_labels = character_tables[pg]["ir_labels"]
                current_max = max(max(len(s) for s in ir_labels), current_max)
                print(ir_labels, current_max)

                is_orthogonal = self.is_orthogonal(
                    character_tables[pg]["character_table"])
                assert is_orthogonal
            else:
                print("Not implemented yet.")
        assert current_max == 3

    @staticmethod
    def is_orthogonal(character_table):
        character_table = np.array(character_table)
        for i0, v0 in enumerate(character_table.T):
            for i1, v1 in enumerate(character_table.T):
                if i0 != i1 and not np.isclose(np.dot(v0, np.conj(v1)), 0.0):
                    print(i0, i1, np.dot(v0, v1))
                    return False

        return True