code: def testImpulse(self):
      # Given an impulse should return its position
      dur = 2
      size = int(dur * sr)
      signal = ones(size) * 0.1
      for i in range(size):
          signal[i] += random.rand(1) * 0.01
      expectedTimes = [0.01, 0.17, 0.73, 0.99]
      for i in range(len(expectedTimes)):
          expectedTimes[i] *= dur
          self.makeImpulse(signal, int(expectedTimes[i] * 44100.0))
      expectedRate = float(len(expectedTimes)) / float(dur)
      times, rate = OnsetRate()(signal)
      self.assertAlmostEqual(rate, expectedRate)
      # to compare seconds it is better to compare the difference, such as
      # if is less than 50ms
      diff = abs(times - expectedTimes)
      self.assertAlmostEqualVector(diff, zeros(len(times)), 0.05)
  
file_path: essentia/test/src/unittests/rhythm/test_onsetrate.py
imports: from essentia_test import *
  from numpy import random
label_desc: Use image node_id 5 for calling the TestOnsetRate obj's underlying member method code with example usage: obj.testImpulse() without return types