def testNumdeg(self): "numdeg argument follows docs" # trivialish - interface check, not math check T = 1 dendeg = 5 ref = [pade(T, dendeg, numdeg) for numdeg in range(0, dendeg + 1)] testneg = [pade(T, dendeg, numdeg) for numdeg in range(-dendeg, 0)] assert ref[:-1] == testneg assert ref[-1] == pade(T, dendeg, dendeg) assert ref[-1] == pade(T, dendeg, None) assert ref[-1] == pade(T, dendeg)
def testNumdeg(self): "numdeg argument follows docs" # trivialish - interface check, not math check T = 1 dendeg = 5 ref = [pade(T,dendeg,numdeg) for numdeg in range(0,dendeg+1)] testneg = [pade(T,dendeg,numdeg) for numdeg in range(-dendeg,0)] self.assertEqual(ref[:-1],testneg) self.assertEqual(ref[-1], pade(T,dendeg,dendeg)) self.assertEqual(ref[-1], pade(T,dendeg,None)) self.assertEqual(ref[-1], pade(T,dendeg))
def testRefs(self): "test reference cases for T=1" T = 1 for dendeg, numdeg, refden, refnum in self.ref: num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp(np.array(refden), den, nulp=2) np.testing.assert_array_almost_equal_nulp(np.array(refnum), num, nulp=2)
def testRefs(self, dendeg, numdeg, refden, refnum): "test reference cases for T=1" T = 1 num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp( np.array(refden), den, nulp=2) np.testing.assert_array_almost_equal_nulp( np.array(refnum), num, nulp=2)
def testErrors(self): "ValueError raised for invalid arguments" with pytest.raises(ValueError): pade(-1, 1) # T<0 with pytest.raises(ValueError): pade(1, -1) # dendeg < 0 with pytest.raises(ValueError): pade(1, 2, -3) # numdeg < 0 with pytest.raises(ValueError): pade(1, 2, 3) # numdeg > dendeg
def testTvalues(self, T, dendeg, numdeg, baseden, basenum): "test reference cases for T!=1" refden = T**np.arange(dendeg, -1, -1) * baseden refnum = T**np.arange(numdeg, -1, -1) * basenum refnum /= refden[0] refden /= refden[0] num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp(refden, den, nulp=2) np.testing.assert_array_almost_equal_nulp(refnum, num, nulp=2)
def testT0(self): "T=0 always returns [1],[1]" T = 0 refnum = [1.0] refden = [1.0] for dendeg in range(1, 6): for numdeg in range(0, dendeg+1): num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp(np.array(refnum), np.array(num)) np.testing.assert_array_almost_equal_nulp(np.array(refden), np.array(den))
def testTvalues(self): "test reference cases for T!=1" Ts = [1/53, 21.95] for dendeg, numdeg, baseden, basenum in self.ref: for T in Ts: refden = T**np.arange(dendeg, -1, -1)*baseden refnum = T**np.arange(numdeg, -1, -1)*basenum refnum /= refden[0] refden /= refden[0] num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp(refden, den, nulp=2) np.testing.assert_array_almost_equal_nulp(refnum, num, nulp=2)
def testT0(self): "T=0 always returns [1],[1]" T = 0 refnum = [1.0] refden = [1.0] for dendeg in range(1, 6): for numdeg in range(0, dendeg + 1): num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp( np.array(refnum), np.array(num)) np.testing.assert_array_almost_equal_nulp( np.array(refden), np.array(den))
def testTvalues(self): "test reference cases for T!=1" Ts = [1 / 53, 21.95] for dendeg, numdeg, baseden, basenum in self.ref: for T in Ts: refden = T**np.arange(dendeg, -1, -1) * baseden refnum = T**np.arange(numdeg, -1, -1) * basenum refnum /= refden[0] refden /= refden[0] num, den = pade(T, dendeg, numdeg) np.testing.assert_array_almost_equal_nulp(refden, den, nulp=2) np.testing.assert_array_almost_equal_nulp(refnum, num, nulp=2)