Exemplo n.º 1
0
 def test_pterm_equalityfalse(self):
     """Test that pterm equality checking fails when it should."""
     p1 = func.PolynomialTerm((3, 7))
     p2 = func.PolynomialTerm((3, 8))
     p3 = func.PolynomialTerm((4, 7))
     p4 = func.PolynomialTerm((4, 8))
     self.assertNotEqual(p1, p2)
     self.assertNotEqual(p1, p3)
     self.assertNotEqual(p1, p4)
Exemplo n.º 2
0
def d_dx(f):
    """Diferentiate a Pterm, f with respect to it's input variable, x."""
    assert isinstance(f,
                      func.PolynomialTerm), "Input must be of type func.Pterm."

    # Grab current terms.
    c_old, p_old = f.c, f.p

    # Calculate new terms.
    p_new = p_old - 1 if p_old != 0 else 0
    c_new = c_old * p_old

    # Construct a new func.Pterm object.
    return func.PolynomialTerm((p_new, c_new))
Exemplo n.º 3
0
 def test_pterm_zero(self):
     """Test the construction of a zero-th order polynomial term."""
     pt_zero = func.PolynomialTerm((0, 3))
     self.assertEqual(pt_zero(0), 3)
     self.assertEqual(pt_zero(1), 3)
     self.assertEqual(pt_zero(-1), 3)
Exemplo n.º 4
0
 def test_pterm_equalitytrue(self):
     """Test that pterm equality checking succeeds when it should."""
     p1 = func.PolynomialTerm((2, -5))
     p2 = func.PolynomialTerm((2, -5))
     self.assertEqual(p1, p2)
Exemplo n.º 5
0
 def test_pterm_first(self):
     """Test the construction of a first-order polynomial term."""
     pt_first = func.PolynomialTerm((1, 7.5))
     self.assertEqual(pt_first(0), 0)
     self.assertEqual(pt_first(1), 7.5)
     self.assertEqual(pt_first(-1), -7.5)
Exemplo n.º 6
0
 def test_ddx_basic(self):
     """Test the proper behavior of differentiation for a basic case."""
     f_x = func.PolynomialTerm((4, 5))
     df_dx = func.PolynomialTerm((3, 20))
     self.assertEqual(d_dx(f_x), df_dx)
Exemplo n.º 7
0
 def test_ddx_const(self):
     """Test that the d_dx function returns a Pterm that is equal to 0*x^0 when
     operating on a Pterm equal to c*x^0."""
     f_const = func.PolynomialTerm((0, 11))
     df_const_dx = func.PolynomialTerm((0, 0))
     self.assertEqual(d_dx(f_const), df_const_dx)