def test_variable_eq(self): main_v = Variable("z", 2) v = Variable("v") z = Variable("z") self.assertEqual(False, main_v == v) self.assertEqual(True, main_v == z) self.assertEqual(False, main_v == -z)
def test_root_to_factor(self): #y^2 + 2yz - x^2 y = Variable("y") x = Variable("x") p = Polynomial.root_to_factor(x, 3) p2 = Polynomial.root_to_factor(y, -3) self.assertEqual(p.latex(), "1x-3") self.assertEqual(p2.latex(), "1y+3")
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_poly_eq(self): x = Variable("x") main_poly = SimplePoly([1, 2, 3], x) a = Variable("a") p = SimplePoly([1, 2, 3], a) alt_x = SimplePoly([1, 2, 3], x) alt_x_2 = SimplePoly([1, 1, 3], x) self.assertEqual(False, main_poly == p) self.assertEqual(True, main_poly == alt_x) self.assertEqual(False, main_poly == alt_x_2)
def test_poly_eq(self): x = Variable("x", value=1) main_poly = SimplePoly([1, 2, 3], x) a = Variable("a", value=1) p = SimplePoly([1, 2, 3], a) result = main_poly + p result_latex = "1x^{2}+2x+3+1a^{2}+2a+3" result_value = 12 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
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)
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)
def test_number_add(self): x = Variable("x", value=1) main_poly = SimplePoly([1, 2, 3], x) n = Number(3) result = main_poly + n result_latex = "1x^{2}+2x+3+3" result_value = 9 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_chain_eq(self): x = Variable("x", value=1) main_poly = SimplePoly([1, 2, 3], x) alt_chain_b = Chain([1, 3, 2]) result = main_poly + alt_chain_b result_latex = "1x^{2}+2x+3+(1+3+2)" result_value = 12 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_basic_latex(self): n = Variable("x") self.assertEqual(n.latex(), "x") n2 = Variable("y", sign=False) self.assertEqual(n2.latex(), "-y")
def test_number_eq(self): main_v = Variable("z", 2) n = Number(3) self.assertEqual(False, main_v == n)
def test_number_eq(self): x = Variable("x") main_poly = SimplePoly([1, 2, 3], x) n = Number(3) self.assertEqual(False, main_poly == n)
def test_chain_eq(self): x = Variable("x") main_poly = SimplePoly([1, 2, 3], x) c = Chain([1, 3, 2]) self.assertEqual(False, main_poly == c)
def test_basic_latex(self): x = Variable("x") p = SimplePoly(coeffs=[1,-2,1], var=x) self.assertEqual(p.equiv_num(), False)
def test_basic_latex(self): x = Variable("x") p = SimplePoly(coeffs=[1, -2, 1], var=x) self.assertEqual(p.latex(), "1x^{2}-2x+1")
def test_basic_eval(self): x = Variable("x") p = SimplePoly(coeffs=[1, -2, 1], var=x) x.value = 2 self.assertEqual(p.evaluate(), 1)