code: def test_limit_weights():
      w = {"a": 0.3, "b": 0.1, "c": 0.05, "d": 0.05, "e": 0.5}
      actual_exp = {"a": 0.3, "b": 0.2, "c": 0.1, "d": 0.1, "e": 0.3}
      actual = ffn.core.limit_weights(w, 0.3)
  
      assert actual.sum() == 1.0
      for k in actual_exp:
          assert actual[k] == actual_exp[k]
  
      w = pd.Series(w)
      actual = ffn.core.limit_weights(w, 0.3)
  
      assert actual.sum() == 1.0
      for k in actual_exp:
          assert actual[k] == actual_exp[k]
  
      w = pd.Series(
          {"a": 0.29, "b": 0.1, "c": 0.06, "d": 0.05, "e": 0.5}
      )
  
      assert w.sum() == 1.0
  
      actual = ffn.core.limit_weights(w, 0.3)
  
      assert actual.sum() == 1.0
  
      assert all(x <= 0.3 for x in actual)
  
      aae(actual["a"], 0.300, 3)
      aae(actual["b"], 0.190, 3)
      aae(actual["c"], 0.114, 3)
      aae(actual["d"], 0.095, 3)
      aae(actual["e"], 0.300, 3)
  
imports: import ffn
  import pandas
  import numpy
  from pytest import fixture
  from numpy.testing import assert_almost_equal
label_desc: Use image node_id 27 for calling a global function with example usage: test_limit_weights() without return types