def test_map_large_input(self):
        func = lambda x: x / 2
        lst = random.sample(xrange(10 ** 6), 10 ** 5)
        exp = map(func, lst)

        res = paralleltools.map(func, lst)
        assert set(res) == set(exp)
    def test_map_one_thread(self):
        # running one thread shouldn't affect ordering

        lst = [1, 2, 3, 4, 5]
        exp = [2, 3, 4, 5, 6]

        res = paralleltools.map(lambda x: x + 1, lst, threads=1)
        assert res == exp, res
    def test_map_dying_thread(self):
        def dying(el):
            if el == 3:
                raise Exception("This exception shouldn't fail the tests")

            return func(el)

        func = lambda x: x * 2
        lst = [1, 2, 3, 4]
        exp = [2, 4, 8]

        res = paralleltools.map(dying, lst)
        assert set(res) == set(exp), res
    def test_map_many_threads(self):
        lst = [1, 2, 3, 4, 5]
        exp = [2, 3, 4, 5, 6]

        res = paralleltools.map(lambda x: x + 1, lst, threads=20)
        assert set(res) == set(exp), res
 def test_map_zero_threads(self):
     test_func = lambda: paralleltools.map(lambda x: x, [], threads=0)
     self.assertRaises(ValueError, test_func)
    def test_map_empty(self):
        res = paralleltools.map(lambda x: x, [])

        assert len(res) == 0, res
    def test_sync_map(self):
        lst = [1, 3, 3, 7]
        exp = [1, 9, 9, 49]

        res = paralleltools.map(lambda x: x * x, lst)
        assert set(res) == set(exp), res