code: def test_mix_colormaps(rng):
      n = 100
  
      # Mixin map's shape should be equal to that of
      # the foreground and background maps
      foreground_map = rng.random((n, 4))
      background_map = rng.random((n, 4))
      mix_map = mix_colormaps(foreground_map, background_map)
      assert mix_map.shape == (n, 4)
      # Transparency of mixin map should be higher
      # than that of both the background and the foreground maps
      assert np.all(mix_map[:, 3] >= foreground_map[:, 3])
      assert np.all(mix_map[:, 3] >= background_map[:, 3])
  
      # If foreground and background maps' shapes are different,
      # an Exception should be raised
      background_map = rng.random((n - 1, 4))
      with pytest.raises(Exception):
          mix_colormaps(foreground_map, background_map)
  
      # If foreground map is transparent,
      # mixin should be equal to background map
      foreground_map = rng.random((n, 4))
      background_map = rng.random((n, 4))
      foreground_map[:, 3] = 0
      mix_map = mix_colormaps(foreground_map, background_map)
      assert np.allclose(mix_map, background_map)
  
      # If background map is transparent,
      # mixin should be equal to foreground map
      foreground_map = rng.random((n, 4))
      background_map = rng.random((n, 4))
      background_map[:, 3] = 0
      mix_map = mix_colormaps(foreground_map, background_map)
      assert np.allclose(mix_map, foreground_map)
  
      # If foreground and background maps are equal,
      # RBG values of the mixin map should be equal
      # to that of the foreground and background maps
      foreground_map = rng.random((n, 4))
      background_map = foreground_map
      mix_map = mix_colormaps(foreground_map, background_map)
      assert np.allclose(mix_map[:, :3], foreground_map[:, :3])
  
file_path: nilearn/nilearn/plotting/tests/test_cm.py
imports: import matplotlib.pyplot
  import numpy
  import pytest
  from nilearn.plotting.cm import dim_cmap, mix_colormaps, replace_inside
label_desc: Use image node_id 4 for calling a global function with example usage: test_mix_colormaps(rng) without return types