# Path: upho/api_unfolding.py
# def calculate_average_masses(masses, symmetry):
#     """Calculate avearge masses from the ideal structure
# 
#     Parameters
#     ----------
#     masses : list-like object containing atomic masses
#     symmetry : Symmetry obtained from unitcell_ideal
#     """
#     masses_average = calculate_average_atomic_property(masses, symmetry)
#     return masses_average
# 
# def calculate_mass_variances(masses, symmetry):
#     masses = np.array(masses)
#     masses_average = calculate_average_atomic_property(
#         masses, symmetry)
#     masses_squared_average = calculate_average_atomic_property(
#         masses ** 2, symmetry)
#     mass_variances = masses_squared_average - masses_average ** 2
#     return mass_variances


import unittest
import os
import numpy as np
from phonopy.interface.vasp import read_vasp
from phonopy.structure.symmetry import Symmetry
from upho.api_unfolding import (
    calculate_average_masses, calculate_mass_variances)
        msg += '\n{:12.6f}{:12.6f}'.format(x1, x2)
    return msg


class TestAverageMasses(unittest.TestCase):
    def setUp(self):
        unitcell_ideal = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_ideal'))
        self._symmetry = Symmetry(unitcell_ideal)
        self._prec = 1e-12

    def test_1(self):
        unitcell = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_disordered_1'))
        masses = unitcell.get_masses()

        masses_average = calculate_average_masses(masses, self._symmetry)
        masses_expected = np.array([47.867, 91.224, 91.224])
        is_same = (np.abs(masses_average - masses_expected) < self._prec).all()
        msg = create_msg(masses_average, masses_expected)
        self.assertTrue(is_same, msg=msg)

        mass_variances = calculate_mass_variances(masses, self._symmetry)
        mass_variances_expected = np.array([0.0, 0.0, 0.0])
        is_same = (np.abs(mass_variances - mass_variances_expected) < self._prec).all()
        msg = create_msg(mass_variances, mass_variances_expected)
        self.assertTrue(is_same, msg=msg)

    def test_2(self):
        unitcell = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_disordered_2'))
        masses = unitcell.get_masses()


# Path: upho/api_unfolding.py
# def calculate_average_masses(masses, symmetry):
#     """Calculate avearge masses from the ideal structure
# 
#     Parameters
#     ----------
#     masses : list-like object containing atomic masses
#     symmetry : Symmetry obtained from unitcell_ideal
#     """
#     masses_average = calculate_average_atomic_property(masses, symmetry)
#     return masses_average
# 
# def calculate_mass_variances(masses, symmetry):
#     masses = np.array(masses)
#     masses_average = calculate_average_atomic_property(
#         masses, symmetry)
#     masses_squared_average = calculate_average_atomic_property(
#         masses ** 2, symmetry)
#     mass_variances = masses_squared_average - masses_average ** 2
#     return mass_variances


# Path: tests/test_average_masses.py
import unittest
import os
import numpy as np
from phonopy.interface.vasp import read_vasp
from phonopy.structure.symmetry import Symmetry
from upho.api_unfolding import (
    calculate_average_masses, calculate_mass_variances)

        msg += '\n{:12.6f}{:12.6f}'.format(x1, x2)
    return msg


class TestAverageMasses(unittest.TestCase):
    def setUp(self):
        unitcell_ideal = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_ideal'))
        self._symmetry = Symmetry(unitcell_ideal)
        self._prec = 1e-12

    def test_1(self):
        unitcell = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_disordered_1'))
        masses = unitcell.get_masses()

        masses_average = calculate_average_masses(masses, self._symmetry)
        masses_expected = np.array([47.867, 91.224, 91.224])
        is_same = (np.abs(masses_average - masses_expected) < self._prec).all()
        msg = create_msg(masses_average, masses_expected)
        self.assertTrue(is_same, msg=msg)

        mass_variances = calculate_mass_variances(masses, self._symmetry)
        mass_variances_expected = np.array([0.0, 0.0, 0.0])
        is_same = (np.abs(mass_variances - mass_variances_expected) < self._prec).all()
        msg = create_msg(mass_variances, mass_variances_expected)
        self.assertTrue(is_same, msg=msg)

    def test_2(self):
        unitcell = read_vasp(os.path.join(POSCAR_DIR, 'POSCAR_omega_disordered_2'))
        masses = unitcell.get_masses()


        masses_average = calculate_average_masses(masses, self._symmetry)