Esempio n. 1
0
    def test_input_shape(self):
        """Test that only allows for 2D."""

        shape_wrong = (40, 30, 10)
        shape_correct = (40, 30)

        with pytest.raises(ValueError):
            rectangles(100, shape_wrong, 10, 20)

        rectangles(100, shape_correct, 10, 20)
Esempio n. 2
0
    def test_full_intensity(self):
        """ Test that there exists a pixel with a full intensity = 1."""

        shape = (50, 100)
        res = rectangles(10, shape, (20, 30), (10, 50), n_levels=4)

        for row in res:
            assert np.any(row == 1)
Esempio n. 3
0
    def test_correct_number_of_intensities(self, n_levels):
        """Test whether n_unique_intensities = n_levels + 1"""

        res = rectangles(10, (200, 220), (40, 50), (50, 100),
                         n_levels=n_levels)

        for row in res:
            assert len(np.unique(row) == n_levels +
                       1)  # also count black background
Esempio n. 4
0
    def test_correct_dtype(self):
        """Test that float32 ndarray is returned."""

        shape = (50, 100)
        res = rectangles(10, shape, (20, 30), (10, 50), n_levels=4)

        assert res.min() >= 0
        assert res.max() <= 1
        assert res.dtype == np.float32
Esempio n. 5
0
    def test_no_empty_images(self, random_state):
        """Test that no empty images."""

        shape = (100, 120)
        res = rectangles(10,
                         shape, (20, 30), (10, 50),
                         n_levels=4,
                         random_state=random_state)

        zeros = np.zeros(shape)
        for row in res:
            assert not np.all(row == zeros)
Esempio n. 6
0
    def test_wrong_type(self):
        """Test that height, width and n_levels only work with integers."""

        shape = (40, 50)
        with pytest.raises(TypeError):
            rectangles(100, shape, 10.1, 20)

        with pytest.raises(TypeError):
            rectangles(100, shape, 10, 20.3)

        with pytest.raises(TypeError):
            rectangles(100, shape, (10, 20), 20, n_levels=3.4)

        rectangles(10, shape, 10, 20, n_levels=2)
Esempio n. 7
0
    def test_wrong_rectangle_size(self):
        """Test that rectangle needs to fit the image."""

        shape = (img_h, img_w) = (40, 50)

        with pytest.raises(ValueError):
            rectangles(100, shape, img_h + 1, img_w - 1)

        with pytest.raises(ValueError):
            rectangles(100, shape, img_h - 1, img_w + 1)

        with pytest.raises(ValueError):
            rectangles(100, shape, img_h + 1, img_w + 1)

        rectangles(100, shape, img_h - 1, img_w - 1)
Esempio n. 8
0
    def test_reproducible(self):
        """Test that random_state works."""

        res_1 = rectangles(10, (100, 120), (20, 30), (10, 40),
                           n_levels=(1, 4),
                           random_state=None)
        res_2 = rectangles(10, (100, 120), (20, 30), (10, 40),
                           n_levels=(1, 4),
                           random_state=1)
        res_3 = rectangles(10, (100, 120), (20, 30), (10, 40),
                           n_levels=(1, 4),
                           random_state=2)
        res_4 = rectangles(10, (100, 120), (20, 30), (10, 40),
                           n_levels=(1, 4),
                           random_state=1)
        res_5 = rectangles(10, (100, 120), (20, 30), (10, 40),
                           n_levels=(1, 4),
                           random_state=None)

        assert np.all(res_2 == res_4)
        assert not np.all(res_2 == res_3)
        assert not np.all(res_2 == res_1)
        assert not np.all(res_3 == res_1)
        assert not np.all(res_1 == res_5)
Esempio n. 9
0
    def test_wrong_n_levels(self):
        """Test that n_levels needs to be correct."""

        with pytest.raises(ValueError):
            rectangles(5, (100, 120), 20, 10, n_levels=14)

        with pytest.raises(ValueError):
            rectangles(5, (100, 120), 10, 20, n_levels=14)

        rectangles(5, (100, 120), 20, 20, n_levels=14)
Esempio n. 10
0
    def test_output_shape(self):
        """Test that the shape of the output is correct."""
        shape = (50, 100)
        res = rectangles(10, shape, (20, 30), (10, 50), n_levels=4)

        assert res.shape == (10, *shape, 1)