# Path: cosmoHammer/util/MpiUtil.py
#     MPI = MPI
#     MPI = None
# class MpiPool(object):
#     def __init__(self, mapFunction):
#     def map(self, function, sequence):
#     def isMaster(self):
# def mpiBCast(value):
# def splitList(list, n):
# def mergeList(lists):


import numpy as np
from mock import patch
from cosmoHammer.util import MpiUtil
class TestMpiUtil(object):

    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_1(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 1
        sList = MpiUtil.splitList(sequence, n)
        assert len(sList) == n
        for i in range(len(sequence)):
            assert np.all(sList[0][i] == sequence[i])
            
    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_2(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 2
        sList = MpiUtil.splitList(sequence, n)
        assert len(sList) == n

        assert len(sList[0]) == 4
        for i in range(4):
            assert np.all(sList[0][i] == sequence[0+i])
            
        assert len(sList[1]) == 3
        for i in range(3):
            assert np.all(sList[1][i] == sequence[4+i])
            
    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_3(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 3

# Path: cosmoHammer/util/MpiUtil.py
#     MPI = MPI
#     MPI = None
# class MpiPool(object):
#     def __init__(self, mapFunction):
#     def map(self, function, sequence):
#     def isMaster(self):
# def mpiBCast(value):
# def splitList(list, n):
# def mergeList(lists):


# Path: Tests/test_MpiUtil.py
import numpy as np
from mock import patch
from cosmoHammer.util import MpiUtil

class TestMpiUtil(object):

    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_1(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 1
        sList = MpiUtil.splitList(sequence, n)
        assert len(sList) == n
        for i in range(len(sequence)):
            assert np.all(sList[0][i] == sequence[i])
            
    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_2(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 2
        sList = MpiUtil.splitList(sequence, n)
        assert len(sList) == n

        assert len(sList[0]) == 4
        for i in range(4):
            assert np.all(sList[0][i] == sequence[0+i])
            
        assert len(sList[1]) == 3
        for i in range(3):
            assert np.all(sList[1][i] == sequence[4+i])
            
    @patch("cosmoHammer.util.MpiUtil.MPI")
    def test_splitlist_3(self, mpi_mock):
        sequence = self._get_sequence(7)
        n = 3

        sList = MpiUtil.splitList(sequence, n)