def test_square(self): """Test discrete sampled square wave.""" amp = 0.5 freq = 0.2 duration = 10 times = np.arange(0, duration) + 0.5 square_ref = continuous.square(times, amp=amp, freq=freq) square_pulse = library.square(duration, amp=amp, freq=freq) self.assertIsInstance(square_pulse, Waveform) np.testing.assert_array_almost_equal(square_pulse.samples, square_ref) # test single cycle cycle_freq = 1./duration square_cycle_ref = continuous.square(times, amp=amp, freq=cycle_freq) square_cycle_pulse = library.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 freq = 0.2 samples = 100 times = np.linspace(0, 10, samples) square_arr = continuous.square(times, amp=amp, freq=freq) # with new phase square_arr_phased = continuous.square(times, amp=amp, freq=freq, 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)
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))