Beispiel #1
0
    def test_basic_eval(self):
        n = Variable("x")
        n.value = Fraction(25, 5)
        self.assertEqual(n.evaluate(), 5)

        n2 = Variable("y", sign=False)
        n2.value = Variable("a", 3)
        self.assertEqual(n2.evaluate(), -3)
    def test_basic_eval(self):
        n = Variable("x")
        n.value = 5
        self.assertEqual(n.evaluate(), 5)

        n2 = Variable("y", sign=False)
        n2.value = 3
        self.assertEqual(n2.evaluate(), -3)

        n3 = Variable("z", sign=False)
        # no value set -> error
        self.assertRaises(ValueError, n3.evaluate)
Beispiel #3
0
    def test_from_roots(self):
        y = Variable("y")
        x = Variable("x")

        p = Polynomial.from_roots([(x, -2), (x, 3), (y, -1), (y, 0)])

        y.value = -1
        x.value = 1
        self.assertEqual(p.evaluate(), 0)

        y.value = 1
        x.value = 3
        self.assertEqual((-p).evaluate(), 0)

        y.value = 1
        x.value = 1
        # (3)(-2)(2)(1)
        self.assertEqual(p.evaluate(), -12)
Beispiel #4
0
 def test_basic_eval(self):
     x = Variable("x")
     p = SimplePoly(coeffs=[1, -2, 1], var=x)
     x.value = 2
     self.assertEqual(p.evaluate(), 1)