def test_ne(self): u, v = [3, -1 + 1j], [2, 1 + 2j] v_dif = [2, 1 + 1j] self.assertNotEqual(core.RationalFunction(u, v), core.RationalFunction(u, v_dif)) self.assertNotEqual(core.RationalFunction(u, v), core.RationalFunction(v, u))
def test_neg(self): u, v = np.array([3, -1 + 1j]), np.array([2, 1 + 2j]) self.assertEqual(-core.RationalFunction(u, v), core.RationalFunction(-u, v)) self.assertEqual(-core.RationalFunction(u, v), core.RationalFunction(u, -v))
def test_pos(self): u, v = [3, -1 + 1j], [2, 1 + 2j] self.assertEqual(+core.RationalFunction(u, v), core.RationalFunction(u, v))
def test_init(self): for u, v in [[[1], [1]], [1, [1]], [[1], 1], [[1, 1], [1]], [[1j + 1], [-1j, 3]], [[3, 3, 3], [1, 1]]]: core.RationalFunction(u, v)
def test_eq(self): u, v = np.array([3, -1 + 1j]), np.array([2, 1 + 1j]) self.assertEqual(core.RationalFunction(u, v), core.RationalFunction(u, v)) self.assertEqual(core.RationalFunction(u, v), core.RationalFunction(-3 * u, -3 * v))
def test_deriv(self): u, v = [7, 1], [11, 1] self.assertEqual( core.RationalFunction(u, v).deriv(), core.RationalFunction([4], [11**2, 22, 1]))
def test_repr_str(self): u = [-2 + 6j, -7 + 9j, -3 + 3j] v = [4 - 4j, 22 + 2j, 6 + 24j] str(core.RationalFunction(u, v)) repr(core.RationalFunction(u, v))
def test_call(self): u = [-2 + 6j, -7 + 9j, -3 + 3j] v = [4 - 4j, 22 + 2j, 6 + 24j] self.assertRelativelyClose( core.RationalFunction(u, v)(5 + 13j), 77855 / 651946 + (193209j) / 1303892)
def test_pow(self): u, v = np.array([-1 + 1j, 1]), np.array([1 + 2j, 1]) r = core.RationalFunction(u, v) self.assertEqual(r * r, r**2) self.assertEqual(r * r * r, r**3) self.assertEqual(r * r * r * r, r**4)
def test_add_sub_mul_div(self): v = core.Polynomial([1, 1]) u1 = core.Polynomial([3, 5, 1]) u2 = core.Polynomial([1j - 1, 32e-15, 1]) self.assertEqual( core.RationalFunction(u1, v) + core.RationalFunction(u2, v), core.RationalFunction(u1 + u2, v)) self.assertEqual( core.RationalFunction(u1, v) - core.RationalFunction(u2, v), core.RationalFunction(u1 - u2, v)) self.assertEqual( core.RationalFunction(u1, v) * core.RationalFunction(u2, v), core.RationalFunction(u1 * u2, v * v)) self.assertEqual( core.RationalFunction(u1, v) / core.RationalFunction(u2, v), core.RationalFunction(u1, u2)) u1, v1 = [1, 1], [2, 1] u2, v2 = [7, 1], [11, 1] u3, v3 = [25, 21, 2], [22, 13, 1] self.assertEqual( core.RationalFunction(u1, v1) + core.RationalFunction(u2, v2), core.RationalFunction(u3, v3)) u3, v3 = [-3, 3], [22, 13, 1] self.assertEqual( core.RationalFunction(u1, v1) - core.RationalFunction(u2, v2), core.RationalFunction(u3, v3)) u3, v3 = [7, 8, 1], [22, 13, 1] self.assertEqual( core.RationalFunction(u1, v1) * core.RationalFunction(u2, v2), core.RationalFunction(u3, v3)) u3, v3 = [11, 12, 1], [14, 9, 1] self.assertEqual( core.RationalFunction(u1, v1) / core.RationalFunction(u2, v2), core.RationalFunction(u3, v3))