code: def test_trunc_exp():
      x = np.linspace(0, 10, 100)
      k = 0.25
      xlim = [3, 5]
      # replaced with from astroML.stats.random import trunc_exp
      # trunc_exp = trunc_exp_gen(name="trunc_exp", shapes='a, b, k')
      myfunc = trunc_exp(xlim[0], xlim[1], k)
      y = myfunc.pdf(x)
      zeros = np.zeros(len(y))
  
      # Test that the function is zero outside of defined limits
      assert_array_equal(y[x < xlim[0]], zeros[x < xlim[0]])
      assert_array_equal(y[x > xlim[1]], zeros[x > xlim[1]])
      inlims = (x < xlim[1]) & (x > xlim[0])
      C = k / (np.exp(k * xlim[1]) - np.exp(k * xlim[0]))
  
      # Test that within defined limits, function is exponential
      assert_array_equal(y[inlims], C * np.exp(k * x[inlims]))
  
      # Test that the PDF integrates to just about 1
      dx = x[1] - x[0]
      integral = np.sum(y * dx)
      assert np.round(integral, 1) == 1
  
file_path: astroML/astroML/stats/tests/test_stats.py
imports: import pytest
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_allclose
  from astroML.stats import mean_sigma, median_sigmaG, sigmaG, fit_bivariate_normal
  from astroML.stats.random import bivariate_normal, trunc_exp, linear
label_desc: Use image node_id 7 for calling a global function with example usage: test_trunc_exp() without return types