from PyARTS.general import *
import unittest

class multi_thread_test(unittest.TestCase):
    """This test performs 20 tasks that each take a random amount of time
    The tests makes sure the output is there and in the right order"""
    def test(self):
        """Testing multi_thread"""
        import random
        import time
        inarglist=[]
        g=random.Random()
        for i in range(20):
            inarglist.append([i])
        def func(x):
            time.sleep(g.random())
            return x**2
        outlist=multi_thread(func,inarglist,2,0)
        for i in range(20):
            assert outlist[i]==i**2

class multi_thread2_test(unittest.TestCase):
    """This test performs 20 tasks that each take a random amount of time
    The tests makes sure the output is there and in the right order"""
    def test(self):
        """testing multi_thread2"""
        import random
        import time
        inarglist=[]
        g=random.Random()
        for i in range(20):
            inarglist.append([i])
        def func(x):
            time.sleep(g.random())
            return x**2
        outlist=multi_thread2(func,inarglist,2,0)
        for i in range(20):
            assert outlist[i]==i**2

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