#!/usr/bin/env python3
import numpy as np
from nose.tools import assert_equal, assert_true, raises
from numpy.testing import assert_allclose
from UliEngineering.SignalProcessing.Resampling import *


class TestResampling(object):
    def __init__(self):
        self.x = np.arange(100)
        self.y = np.square(self.x)

    def testDiscard(self):
        x = np.arange(10)
        assert_allclose(resample_discard(x, 2), [0, 2, 4, 6, 8])
        assert_allclose(resample_discard(x, 3), [0, 3, 6, 9])

    def testBSplineResampler(self):
        y2 = BSplineResampler(self.x, self.y, time_factor=1).resample_to(1)

    def testResampledFilteredXYView(self):
        # TODO improve test
        y2 = ResampledFilteredXYView(self.x, self.y, 1.0, 1.0)[30:80]

    def testResampledFilteredView(self):
        # TODO improve test
        y2 = ResampledFilteredView(self.x, self.y, 1.0, 1.0)[30:50]

    def testResampledFilteredView(self):
        # TODO improve test
        y2 = ResampledFilteredView(self.x, self.y, 1.0, 1.0)[30:50]

    @raises(TypeError)
    def testResampledFilteredXYViewInvalidArgs(self):
        rv = ResampledFilteredXYView(self.x, self.y, 100.)
        rv[1]

    @raises(TypeError)
    def testResampledFilteredXYViewInvalidArgs2(self):
        rv = ResampledFilteredXYView(self.x, self.y, 100.)
        rv[self]

@@ -746,153 +746,71 @@
 1.0)
-%5B30:80%5D%0A%0A    def testResampledFilteredView(self):%0A        # TODO improve test%0A        y2 = ResampledFilteredView(self.x, self.y, 1.0, 1.0)%5B30:50%5D
+%0A        y2%5B30:80%5D%0A        assert_equal(y2.shape, self.y.shape)
 %0A%0A  
@@ -940,15 +940,71 @@
 1.0)
-%5B30:50%5D
+%0A        y2%5B30:50%5D%0A        assert_equal(y2.shape, self.y.shape)
 %0A%0A  

Test resampled views shape property