# Licensed under an MIT open source license - see LICENSE


'''
Test functions for Tsallis
'''

from unittest import TestCase

import numpy as np
import numpy.testing as npt

from ..statistics import Tsallis, Tsallis_Distance
from ._testing_data import \
    dataset1, dataset2, computed_data, computed_distances


class testTsallis(TestCase):

    def setUp(self):
        self.dataset1 = dataset1
        self.dataset2 = dataset2

    def test_Tsallis_method(self):
        self.tester = Tsallis(dataset1["moment0"],
                              lags=[1, 2, 4, 8, 16], num_bins=100)
        self.tester.run()
        npt.assert_allclose(self.tester.tsallis_fits,
                            computed_data['tsallis_val'], atol=0.01)

    def test_Tsallis_distance(self):
        self.tester_dist = \
            Tsallis_Distance(dataset1["moment0"],
                             dataset2["moment0"],
                             lags=[1, 2, 4, 8, 16],
                             num_bins=100).distance_metric()
        npt.assert_almost_equal(self.tester_dist.distance,
                                computed_distances['tsallis_distance'],
                                decimal=4)

# Licensed under an MIT open source license - see LICENSE


'''
Test functions for Tsallis
'''

import pytest

import numpy as np
import numpy.testing as npt
import astropy.units as u

from ..statistics import Tsallis, Tsallis_Distance
from ._testing_data import \
    dataset1, dataset2, computed_data, computed_distances


def test_Tsallis():
    tester = Tsallis(dataset1["moment0"],
                     lags=[1, 2, 4, 8, 16] * u.pix)
    tester.run(num_bins=100, periodic=False)
    npt.assert_allclose(tester.tsallis_params,
                        computed_data['tsallis_val'][:, :3], atol=0.01)

    # Ensure that the output table matched the right inputs by checking a
    # couple columns
    npt.assert_allclose(tester.tsallis_table['logA'],
                        computed_data['tsallis_val'][:, 0])
    npt.assert_allclose(tester.tsallis_table['logA_stderr'],
                        computed_data['tsallis_stderrs'][:, 0])


def test_Tsallis_lagunits():

    pix_lags = [1, 2, 4, 8, 16] * u.pix

    ang_conv = np.abs(dataset1['moment0'][1]["CDELT2"]) * u.deg
    ang_lags = pix_lags.value * ang_conv

    distance = 250 * u.pc
    phys_conv = ang_conv.to(u.rad).value * distance
    phys_lags = pix_lags.value * phys_conv

    tester = Tsallis(dataset1["moment0"],
                     lags=ang_lags)
    tester.run(num_bins=100, periodic=False)
    npt.assert_allclose(tester.tsallis_params,
                        computed_data['tsallis_val'][:, :3], atol=0.01)

    tester = Tsallis(dataset1["moment0"],
                     lags=phys_lags, distance=distance)
    tester.run(num_bins=100, periodic=False)
    npt.assert_allclose(tester.tsallis_params,
                        computed_data['tsallis_val'][:, :3], atol=0.01)


def test_Tsallis_distance():
    kwarg_dict = dict(num_bins=100, periodic=False)
    tester_dist = \
        Tsallis_Distance(dataset1["moment0"],
                         dataset2["moment0"],
                         lags=[1, 2, 4, 8, 16] * u.pix,
                         tsallis1_kwargs=kwarg_dict,
                         tsallis2_kwargs=kwarg_dict).distance_metric()
    npt.assert_almost_equal(tester_dist.distance,
                            computed_distances['tsallis_distance'],
                            decimal=4)

Update tsallis tests and add test using ang and phys lags (Not passing until unit test values are updated!)