import unittest
import numpy as N
import scipy

from neuroimaging.fmri.utils import CutPoly, WaveFunction

class utilTest(unittest.TestCase):
    
    def test_CutPoly(self):
        f = CutPoly(2.0)
        t = N.arange(0, 10.0, 0.1)
        y = f(t)
        scipy.testing.assert_almost_equal(y, [x*x for x in t])

        f = CutPoly(2.0, (5, 7))
        y = f(t)
        scipy.testing.assert_almost_equal(y, [x*x*(x >= 5 and x < 7) for x in t])

        f = CutPoly(2.0, (None, 7))
        y = f(t)
        scipy.testing.assert_almost_equal(y, [x*x*(x < 7) for x in t])

        f = CutPoly(2.0, (5, None))
        y = f(t)
        scipy.testing.assert_almost_equal(y, [x*x*(x >= 5) for x in t])


    def test_WaveFunction(self):
        start = 5.0
        duration = 2.0
        height = 3.0
        f = WaveFunction(5, 2, 3)
        t = N.arange(0, 10.0, 0.1)
        y = f(t)
        scipy.testing.assert_almost_equal(y, [height*(x >= start and x < start + duration) for x in t])


if __name__ == '__main__':
    unittest.main()

@@ -98,16 +98,35 @@
 Function
+, ConvolveFunctions
 %0A%0Aclass 
@@ -1002,16 +1002,572 @@
 n t%5D)%0A%0A%0A
+    def test_ConvolveFunctions(self):%0A        %22%22%22%0A        The integral of the normalised convolution should be equal%0A        to the product of the integrals of the original functions.%0A        %22%22%22%0A        dt = 0.01%0A        t = N.arange(0, 10.0, dt)%0A        f1 = WaveFunction(2, 1, 1)%0A        f2 = WaveFunction(4, 1, 1)%0A        fa = ConvolveFunctions(f1, f2, %5Bt%5B0%5D, t%5B-1%5D%5D, dt, normalize=%5B1,1%5D)%0A        int_f1 = dt*f1(t).sum()%0A        int_f2 = dt*f2(t).sum()%0A        int_fa = dt*fa(t).sum()%0A        scipy.testing.assert_approx_equal(int_f1*int_f2, int_fa)%0A%0A%0A
 if __nam

add a unit test for ConvolveFunctions