import cupy as cp
import pytest
from numpy.testing import assert_almost_equal

from cucim.skimage import data


def test_binary_blobs():
    blobs = data.binary_blobs(length=128)
    assert_almost_equal(blobs.mean(), 0.5, decimal=1)
    blobs = data.binary_blobs(length=128, volume_fraction=0.25)
    assert_almost_equal(blobs.mean(), 0.25, decimal=1)
    blobs = data.binary_blobs(length=32, volume_fraction=0.25, n_dim=3)
    assert_almost_equal(blobs.mean(), 0.25, decimal=1)
    other_realization = data.binary_blobs(
        length=32, volume_fraction=0.25, n_dim=3
    )
    assert not cp.all(blobs == other_realization)


def test_binary_blobs_futurewarning():
    with pytest.warns(FutureWarning):
        data.binary_blobs(length=128, seed=5)
