code: def test_density(self):
      # Check that the integral of the density equals 1.
      n = 100
      v = np.random.rand(n)
      a, b = histogram(v, density=True)
      area = np.sum(a * np.diff(b))
      assert_almost_equal(area, 1)
  
      # Check with non-constant bin widths
      v = np.arange(10)
      bins = [0, 1, 3, 6, 10]
      a, b = histogram(v, bins, density=True)
      assert_array_equal(a, 0.1)
      assert_equal(np.sum(a * np.diff(b)), 1)
  
      # Test that passing False works too
      a, b = histogram(v, bins, density=False)
      assert_array_equal(a, [1, 2, 3, 4])
  
      # Variable bin widths are especially useful to deal with
      # infinities.
      v = np.arange(10)
      bins = [0, 1, 3, 6, np.inf]
      a, b = histogram(v, bins, density=True)
      assert_array_equal(a, [0.1, 0.1, 0.1, 0.0])
  
      # Taken from a bug report from N. Becker on the numpy-discussion
      # mailing list Aug. 6, 2010.
      counts, dmy = np.histogram(
          [1, 2, 3, 4], [0.5, 1.5, np.inf], density=True
      )
      assert_equal(counts, [0.25, 0])
  
imports: import numpy
  from numpy.lib.histograms import histogram, histogramdd, histogram_bin_edges
  from numpy.testing import assert_, assert_equal, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_array_max_ulp, assert_raises_regex, suppress_warnings
  from numpy.testing._private.utils import requires_memory
  import pytest
label_desc: Use image node_id 5 for calling the TestHistogram obj's underlying member method code with example usage: obj.test_density() without return types