Example #1
0
    class TestNumericIntegral(tst.TestCase):
        x_squared = polynomial({1: 0, 2: 1})
        x_recip_sq = polynomial({-2: 1})
        x_root = polynomial({Fraction(1,2): 1})

        def test_squared(self):
            np.testing.assert_almost_equal(get_integral(self.x_squared)[0][3], Fraction(1,3), 0.001)
        def test_recip_sq(self):
            np.testing.assert_equal(get_integral(self.x_recip_sq)[0][-1], -1)
        def test_root(self):
            np.testing.assert_equal(get_integral(self.x_root)[0][Fraction(3,2)], Fraction(2,3))
Example #2
0
    class TestNumericDerivative(tst.TestCase):
        x_squared = polynomial({1: 0, 2: 1})
        x_recip = polynomial({-1: 1})
        x_root = polynomial({1/2: 1})

        def test_squared(self):
            np.testing.assert_equal(get_derivative(self.x_squared)[0][1], 2)
        def test_primes(self):
            np.testing.assert_equal(get_derivative(self.x_squared)[3], 1)
        def test_recip(self):
            np.testing.assert_equal(get_derivative(self.x_recip)[0][-2], -1)
        def test_root(self):
            np.testing.assert_equal(get_derivative(self.x_root)[0][-0.5], 0.5)