import numpy as np

from tslearn.piecewise import OneD_SymbolicAggregateApproximation, \
    SymbolicAggregateApproximation, PiecewiseAggregateApproximation
from sklearn.exceptions import NotFittedError

__author__ = 'Romain Tavenard romain.tavenard[at]univ-rennes2.fr'


def test_paa():
    unfitted_paa = PiecewiseAggregateApproximation(n_segments=3)
    data = [[-1., 2., 0.1, -1., 1., -1.], [1., 3.2, -1., -3., 1., -1.]]
    np.testing.assert_raises(NotFittedError, unfitted_paa.distance,
                             data[0], data[1])


def test_sax():
    unfitted_sax = SymbolicAggregateApproximation(n_segments=3,
                                                  alphabet_size_avg=2)
    data = [[-1., 2., 0.1, -1., 1., -1.], [1., 3.2, -1., -3., 1., -1.]]
    np.testing.assert_raises(NotFittedError, unfitted_sax.distance,
                             data[0], data[1])


def test_1dsax():
    unfitted_1dsax = OneD_SymbolicAggregateApproximation(n_segments=3,
                                                         alphabet_size_avg=2,
                                                         alphabet_size_slope=2)
    data = [[-1., 2., 0.1, -1., 1., -1.], [1., 3.2, -1., -3., 1., -1.]]
    np.testing.assert_raises(NotFittedError, unfitted_1dsax.distance,
                             data[0], data[1])

@@ -526,32 +526,327 @@
 a%5B0%5D, data%5B1%5D)%0A%0A
+    paa_est = unfitted_paa%0A    n, sz, d = 2, 10, 3%0A    rng = np.random.RandomState(0)%0A    X = rng.randn(n, sz, d)%0A    paa_repr = paa_est.fit_transform(X)%0A    np.testing.assert_allclose(paa_est.distance(X%5B0%5D, X%5B1%5D),%0A                               paa_est.distance_paa(paa_repr%5B0%5D, paa_repr%5B1%5D))%0A%0A
 %0Adef test_sax():
@@ -1169,16 +1169,311 @@
 ta%5B1%5D)%0A%0A
+    sax_est = unfitted_sax%0A    n, sz, d = 2, 10, 3%0A    rng = np.random.RandomState(0)%0A    X = rng.randn(n, sz, d)%0A    sax_repr = sax_est.fit_transform(X)%0A    np.testing.assert_allclose(sax_est.distance(X%5B0%5D, X%5B1%5D),%0A                               sax_est.distance_sax(sax_repr%5B0%5D, sax_repr%5B1%5D))%0A%0A
 %0Adef tes
@@ -1846,32 +1846,32 @@
 1dsax.distance,%0A
-
                 
@@ -1881,28 +1881,318 @@
           data%5B0%5D, data%5B1%5D)%0A
+%0A    sax1d_est = unfitted_1dsax%0A    n, sz, d = 2, 10, 3%0A    rng = np.random.RandomState(0)%0A    X = rng.randn(n, sz, d)%0A    sax1d = sax1d_est.fit_transform(X)%0A    np.testing.assert_allclose(%0A        sax1d_est.distance(X%5B0%5D, X%5B1%5D),%0A        sax1d_est.distance_1d_sax(sax1d%5B0%5D, sax1d%5B1%5D)%0A    )%0A

Test that paired distance functions return the same value