Beispiel #1
0
def test_convert_bool_list():
    bool_list = util.convert_bool_list(n=10, k=None)
    assert len(bool_list) == 10
    assert bool_list[0] == True

    bool_list = util.convert_bool_list(n=10, k=3)
    assert len(bool_list) == 10
    assert bool_list[3] is True
    assert bool_list[2] is False

    bool_list = util.convert_bool_list(n=10, k=[3, 7])
    assert len(bool_list) == 10
    assert bool_list[3] is True
    assert bool_list[7] is True
    assert bool_list[2] is False

    bool_list = util.convert_bool_list(n=3, k=[False, False, True])
    assert len(bool_list) == 3
    assert bool_list[0] is False
    assert bool_list[1] is False
    assert bool_list[2] is True

    bool_list = util.convert_bool_list(n=3, k=[])
    assert len(bool_list) == 3
    assert bool_list[0] is False
    def _bool_list(self, k=None):
        """
        returns a bool list of the length of the lens models
        if k = None: returns bool list with True's
        if k is int, returns bool list with False's but k'th is True
        if k is a list of int, e.g. [0, 3, 5], returns a bool list with True's in the integers listed and False elsewhere
        if k is a boolean list, checks for size to match the numbers of models and returns it

        :param k: None, int, or list of ints
        :return: bool list
        """
        return convert_bool_list(n=self._num_func, k=k)
Beispiel #3
0
 def test_raise(self):
     with self.assertRaises(ValueError):
         array = np.ones(5)
         util.array2image(array)
     with self.assertRaises(ValueError):
         array = np.ones((2, 2))
         util.array2cube(array, 2, 2)
     with self.assertRaises(ValueError):
         x, y = np.ones(6), np.ones(6)
         util.get_axes(x, y)
     with self.assertRaises(ValueError):
         util.selectBest(array=np.ones(6),
                         criteria=np.ones(5),
                         numSelect=1,
                         highest=True)
     with self.assertRaises(ValueError):
         util.select_best(array=np.ones(6),
                          criteria=np.ones(5),
                          num_select=1,
                          highest=True)
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=2, k=[3, 7])
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=3, k=[True, True])
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=2, k=[0.1, True])