# Path: vasppy/optics.py
# def matrix_eigvals(matrix):
#     """
#     Calculate the eigenvalues of a matrix.
# 
#     Args:
#         matrix (np.array): The matrix to diagonalise.
# 
#     Returns:
#         (np.array): Array of the matrix eigenvalues.
#     """
#     eigvals, eigvecs = np.linalg.eig(matrix)
#     return eigvals
# 
# def to_matrix( xx, yy, zz, xy, yz, xz ):
#     """
#     Convert a list of matrix components to a symmetric 3x3 matrix.
#     Inputs should be in the order xx, yy, zz, xy, yz, xz.
# 
#     Args:
#         xx (float): xx component of the matrix.
#         yy (float): yy component of the matrix.
#         zz (float): zz component of the matrix.
#         xy (float): xy component of the matrix.
#         yz (float): yz component of the matrix.
#         xz (float): xz component of the matrix.
# 
#     Returns:
#         (np.array): The matrix, as a 3x3 numpy array.
#     """
#     matrix = np.array( [[xx, xy, xz], [xy, yy, yz], [xz, yz, zz]] )
#     return matrix
# 
# def parse_dielectric_data( data ):
#     """
#     Convert a set of 2D vasprun formatted dielectric data to
#     the eigenvalues of each corresponding 3x3 symmetric numpy matrices.
# 
#     Args:
#         data (list): length N list of dielectric data. Each entry should be
#                      a list of ``[xx, yy, zz, xy, xz, yz ]`` dielectric
#                      tensor elements.
# 
#     Returns:
#         (np.array):  a Nx3 numpy array. Each row contains the eigenvalues
#                      for the corresponding row in `data`.
#     """ 
#     return np.array( [ matrix_eigvals( to_matrix( *e ) ) for e in data ] )


import unittest
import numpy as np
from vasppy.optics import matrix_eigvals, to_matrix, parse_dielectric_data
from unittest.mock import Mock, patch, call

class Test_Optics(unittest.TestCase):

    def test_matrix_eigvals(self):
        matrix = np.array( [ [ 2, 0, 3 ],
                             [ 0, 3, 0 ],
                             [ 0, 0, 3 ] ] )
        expected_eigenvalues = np.array( [ 2, 3, 3 ] )
        np.testing.assert_array_equal( matrix_eigvals( matrix ), expected_eigenvalues )

    def test_to_matrix(self):
        expected_matrix = np.array( [ [ 1, 2, 3 ],
                                      [ 2, 4, 5 ],
                                      [ 3, 5, 6 ] ] )
        np.testing.assert_array_equal( to_matrix( xx=1, yy=4, zz=6, xy=2, yz=5, xz=3 ),
                                       expected_matrix )

    @patch('vasppy.optics.to_matrix')
    @patch('vasppy.optics.matrix_eigvals')
    def test_parse_dielectric_data(self, mock_matrix_eigvals, mock_to_matrix):
        input_data = [ [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 ],
                       [ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 ] ]

# Path: vasppy/optics.py
# def matrix_eigvals(matrix):
#     """
#     Calculate the eigenvalues of a matrix.
# 
#     Args:
#         matrix (np.array): The matrix to diagonalise.
# 
#     Returns:
#         (np.array): Array of the matrix eigenvalues.
#     """
#     eigvals, eigvecs = np.linalg.eig(matrix)
#     return eigvals
# 
# def to_matrix( xx, yy, zz, xy, yz, xz ):
#     """
#     Convert a list of matrix components to a symmetric 3x3 matrix.
#     Inputs should be in the order xx, yy, zz, xy, yz, xz.
# 
#     Args:
#         xx (float): xx component of the matrix.
#         yy (float): yy component of the matrix.
#         zz (float): zz component of the matrix.
#         xy (float): xy component of the matrix.
#         yz (float): yz component of the matrix.
#         xz (float): xz component of the matrix.
# 
#     Returns:
#         (np.array): The matrix, as a 3x3 numpy array.
#     """
#     matrix = np.array( [[xx, xy, xz], [xy, yy, yz], [xz, yz, zz]] )
#     return matrix
# 
# def parse_dielectric_data( data ):
#     """
#     Convert a set of 2D vasprun formatted dielectric data to
#     the eigenvalues of each corresponding 3x3 symmetric numpy matrices.
# 
#     Args:
#         data (list): length N list of dielectric data. Each entry should be
#                      a list of ``[xx, yy, zz, xy, xz, yz ]`` dielectric
#                      tensor elements.
# 
#     Returns:
#         (np.array):  a Nx3 numpy array. Each row contains the eigenvalues
#                      for the corresponding row in `data`.
#     """ 
#     return np.array( [ matrix_eigvals( to_matrix( *e ) ) for e in data ] )


# Path: tests/test_optics.py
import unittest
import numpy as np
from vasppy.optics import matrix_eigvals, to_matrix, parse_dielectric_data
from unittest.mock import Mock, patch, call


class Test_Optics(unittest.TestCase):

    def test_matrix_eigvals(self):
        matrix = np.array( [ [ 2, 0, 3 ],
                             [ 0, 3, 0 ],
                             [ 0, 0, 3 ] ] )
        expected_eigenvalues = np.array( [ 2, 3, 3 ] )
        np.testing.assert_array_equal( matrix_eigvals( matrix ), expected_eigenvalues )

    def test_to_matrix(self):
        expected_matrix = np.array( [ [ 1, 2, 3 ],
                                      [ 2, 4, 5 ],
                                      [ 3, 5, 6 ] ] )
        np.testing.assert_array_equal( to_matrix( xx=1, yy=4, zz=6, xy=2, yz=5, xz=3 ),
                                       expected_matrix )

    @patch('vasppy.optics.to_matrix')
    @patch('vasppy.optics.matrix_eigvals')
    def test_parse_dielectric_data(self, mock_matrix_eigvals, mock_to_matrix):
        input_data = [ [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 ],
                       [ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 ] ]

        matrix_a = np.array( [ [ 0.1, 0.4, 0.6 ], [ 0.4, 0.2, 0.5 ], [ 0.6, 0.5, 0.3 ] ] )