code: def test_insert_tone_trigger(art_warning):
      try:
          # test single example
          trigger = CacheToneTrigger(sampling_rate=16000)
          audio = trigger.insert(x=np.zeros(3200))
          assert audio.shape == (3200,)
          assert np.max(audio) != 0
          assert np.max(np.abs(audio)) <= 1.0
  
          # test single example with differet duration, frequency, and scale
          trigger = CacheToneTrigger(
              sampling_rate=16000,
              frequency=16000,
              duration=0.2,
              scale=0.5,
          )
          audio = trigger.insert(x=np.zeros(3200))
          assert audio.shape == (3200,)
          assert np.max(audio) != 0
  
          # test a batch of examples
          audio = trigger.insert(x=np.zeros((10, 3200)))
          assert audio.shape == (10, 3200)
          assert np.max(audio) != 0
  
          # test single example with shift
          trigger = CacheToneTrigger(sampling_rate=16000, shift=10)
          audio = trigger.insert(x=np.zeros(3200))
          assert audio.shape == (3200,)
          assert np.max(audio) != 0
          assert np.sum(audio[:10]) == 0
  
          # test a batch of examples with random shift
          trigger = CacheToneTrigger(sampling_rate=16000, random=True)
          audio = trigger.insert(x=np.zeros((10, 3200)))
          assert audio.shape == (10, 3200)
          assert np.max(audio) != 0
  
          # test when length of backdoor is larger than that of audio signal
          with pytest.raises(ValueError):
              trigger = CacheToneTrigger(
                  sampling_rate=16000, duration=0.3
              )
              _ = trigger.insert(x=np.zeros(3200))
  
          # test when shift + backdoor is larger than that of audio signal
          with pytest.raises(ValueError):
              trigger = CacheToneTrigger(
                  sampling_rate=16000, duration=0.2, shift=5
              )
              _ = trigger.insert(x=np.zeros(3200))
  
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/poison/test_audio_perturbations.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import numpy
  import pytest
  import os
  from art.attacks.poisoning.perturbations.audio_perturbations import CacheToneTrigger, CacheAudioTrigger
  from tests.utils import ARTTestException
label_desc: Use image node_id 1 for calling a global function with example usage: test_insert_tone_trigger(art_warning) without return types