def test_sawtooth(self): """Test sawtooth wave.""" amp = 0.5 freq = 0.2 samples = 101 times, dt = np.linspace(0, 10, samples, retstep=True) sawtooth_arr = continuous.sawtooth(times, amp=amp, freq=freq) # with new phase sawtooth_arr_phased = continuous.sawtooth(times, amp=amp, freq=freq, phase=np.pi / 2) self.assertEqual(sawtooth_arr.dtype, np.complex_) self.assertAlmostEqual(sawtooth_arr[0], 0.0) # test slope self.assertAlmostEqual((sawtooth_arr[1] - sawtooth_arr[0]) / dt, 2 * amp * freq) self.assertAlmostEqual(sawtooth_arr[24], 0.48) self.assertAlmostEqual(sawtooth_arr[50], 0.) self.assertAlmostEqual(sawtooth_arr[75], -amp) self.assertAlmostEqual(sawtooth_arr_phased[0], -amp) # Assert bounded between -amp and amp self.assertTrue(np.all((-amp <= sawtooth_arr) & (sawtooth_arr <= amp))) self.assertEqual(len(sawtooth_arr), samples)
def test_sawtooth(self): """Test discrete sampled sawtooth wave.""" amp = 0.5 period = 5 duration = 10 times = np.arange(0, duration) sawtooth_ref = continuous.sawtooth(times, amp=amp, period=period) sawtooth_pulse = pulse_lib.sawtooth(duration, amp=amp, period=period) self.assertIsInstance(sawtooth_pulse, SamplePulse) np.testing.assert_array_equal(sawtooth_pulse.samples, sawtooth_ref) # test single cycle cycle_period = duration sawtooth_cycle_ref = continuous.sawtooth(times, amp=amp, period=cycle_period) sawtooth_cycle_pulse = pulse_lib.sawtooth(duration, amp=amp) np.testing.assert_array_almost_equal(sawtooth_cycle_pulse.samples, sawtooth_cycle_ref)
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))