def test_square(self):
        """Test discrete sampled square wave."""
        amp = 0.5
        period = 5
        duration = 10
        times = np.arange(0, duration)
        square_ref = continuous.square(times, amp=amp, period=period)
        square_pulse = pulse_lib.square(duration, amp=amp, period=period)
        self.assertIsInstance(square_pulse, SamplePulse)
        np.testing.assert_array_almost_equal(square_pulse.samples, square_ref)

        # test single cycle
        cycle_period = duration
        square_cycle_ref = continuous.square(times, amp=amp, period=cycle_period)
        square_cycle_pulse = pulse_lib.square(duration, amp=amp)
        np.testing.assert_array_almost_equal(square_cycle_pulse.samples, square_cycle_ref)
    def test_square(self):
        """Test square wave."""
        amp = 0.5
        period = 5
        samples = 100
        times = np.linspace(0, 10, samples)
        square_arr = continuous.square(times, amp=amp, period=period)
        # with new phase
        square_arr_phased = continuous.square(times, amp=amp, period=period, phase=np.pi/2)

        self.assertEqual(square_arr.dtype, np.complex_)

        self.assertAlmostEqual(square_arr[0], amp)
        # test constant
        self.assertAlmostEqual(square_arr[1]-square_arr[0], 0.0)
        self.assertAlmostEqual(square_arr[25], -amp)
        self.assertAlmostEqual(square_arr_phased[0], -amp)
        # Assert bounded between -amp and amp
        self.assertTrue(np.all((-amp <= square_arr) & (square_arr <= amp)))
        self.assertEqual(len(square_arr), samples)
Exemple #3
0
 def test_period_deprecation_warning(self):
     """Tests for DeprecationWarning"""
     amp = 0.5
     period = 5.
     samples = 101
     times, _ = np.linspace(0, 10, samples, retstep=True)
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.triangle(times, amp=amp, period=period))
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.sawtooth(times, amp=amp, period=period))
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.square(times, amp=amp, period=period))