<commit_before>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()<commit_msg>add a unit test for ConvolveFunctions<commit_after>import unittest
import numpy as N
import scipy

from neuroimaging.fmri.utils import CutPoly, WaveFunction, ConvolveFunctions

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])


    def test_ConvolveFunctions(self):
        """
        The integral of the normalised convolution should be equal
        to the product of the integrals of the original functions.
        """
        dt = 0.01
        t = N.arange(0, 10.0, dt)
        f1 = WaveFunction(2, 1, 1)
        f2 = WaveFunction(4, 1, 1)
        fa = ConvolveFunctions(f1, f2, [t[0], t[-1]], dt, normalize=[1,1])
        int_f1 = dt*f1(t).sum()
        int_f2 = dt*f2(t).sum()
        int_fa = dt*fa(t).sum()
        scipy.testing.assert_approx_equal(int_f1*int_f2, int_fa)


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.141651376146789, 'fraction_numerical': 0.03706422018348624, 'mean_word_length': 2.136939010356732, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4216879', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1036, 'n_words': 267}