def test_complex_split(self): ch = ComplexNumber(3,2, sign=False) # -(3+2i) f = Fraction(ch, 2, False) # -(-(3+2i)/2) split = f.split() # -((-3/2)-(2/2)i) self.assertEqual(split.latex(), "-((-\\frac{3}{2})+(-\\frac{2}{2})i)")
def test_fraction_collapse(self): ch = Fraction(3, 2, sign=False) col = ch.to_number() self.assertEqual(col.latex(), "-1.5") self.assertEqual(ch.evaluate(), col.evaluate())
def test_advanced_chain_collapse(self): f = Fraction(Fraction(4, 2), 2) # 1 ch = Chain([Chain([3, 2]), f], sign=False) # -(5+1) = -6 col = ch.to_number() self.assertEqual(col.latex(), "-6.0") self.assertEqual(ch.evaluate(), col.evaluate())
def test_product_split(self): ch = Product([3,2], sign=False) f = Fraction(ch, 2, False) split = f.split() self.assertEqual(split.latex(), "-(-\\frac{3}{2} \\cdot -\\frac{2}{2})") split = (-f).split() self.assertEqual(split.latex(), "-\\frac{3}{2} \\cdot -\\frac{2}{2}")
def test_chain_split(self): ch = Chain([3,2], sign=False) f = Fraction(ch, 2, False) split = f.split() self.assertEqual(split.latex(), "-(-\\frac{3}{2}-\\frac{2}{2})") split2 = (-f).split() self.assertEqual(split2.latex(), "-\\frac{3}{2}-\\frac{2}{2}") self.assertEqual(split.ripple_sign().latex(), "\\frac{3}{2}+\\frac{2}{2}")
def test_chain_ripple(self): ch = Chain([3, Fraction(4, 2)], sign=False) ripped = ch.ripple_sign() self.assertEqual(ripped.latex(), "-3-\\frac{4}{2}") self.assertEqual(ch.evaluate(), ripped.evaluate())
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_number_mul(self): main_fr = Fraction(12, 2) n = Number(3) result = main_fr * n result_latex = "\\frac{12}{2} \\cdot 3" result_value = 18 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_fraction_mul(self): main_fr = Fraction(12, 2) alt_fr = Fraction(12, 2) result = main_fr * alt_fr result_latex = "\\frac{12 \\cdot 12}{2 \\cdot 2}" result_value = 36 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value) result = main_fr * -alt_fr result_latex = "-\\frac{12 \\cdot 12}{2 \\cdot 2}" result_value = -36 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_number_add(self): main_fr = Fraction(12,2) n = Number(3) result = main_fr + n result_latex = "\\frac{12}{2}+3" result_value = 9 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_fraction_add(self): main_fr = Fraction(12,2) alt_fr = Fraction(12,2) result = main_fr + alt_fr result_latex = "\\frac{12+12}{2}" result_value = 12 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value) result = main_fr - alt_fr result_latex = "\\frac{12-12}{2}" result_value = 0 self.assertEqual(result.latex(), result_latex) self.assertEqual(result.evaluate(), result_value)
def test_frac_inv(self): f = Fraction(4, 2, False) inv = f.inverse() self.assertEqual(inv.latex(), "-\\frac{2}{4}") f = Fraction(4, 2, True) inv = f.inverse() self.assertEqual(inv.latex(), "\\frac{2}{4}")
def test_block_latex(self): ch = Chain([Number(3), -Fraction(3, 2), Product([2, 2])]) self.assertEqual(ch.latex(), "3-\\frac{3}{2}+(2 \\cdot 2)") ch2 = -ch self.assertEqual(ch2.latex(), "-(3-\\frac{3}{2}+(2 \\cdot 2))")
def test_block_eval(self): ch = Chain([Number(3), -Fraction(3, 2), Product([2, 2])]) self.assertEqual(ch.evaluate(), 5.5) ch2 = -ch self.assertEqual(ch2.evaluate(), -5.5)
def test_block_latex(self): # test the latex expression for fractions with numbers only fr = Fraction(Chain([2,2]),Product([2,2], sign=False)) self.assertEqual(fr.latex(), "\\frac{2+2}{-(2 \\cdot 2)}")
def test_block_eval(self): fr = Fraction(Chain([2,2]),Product([2,2], sign=False)) self.assertEqual(fr.evaluate(), -1)
def test_basic_eval(self): fr = Fraction(3, 2) self.assertEqual(fr.evaluate(), 1.5) fr2 = Fraction(-2, 2, sign=False) self.assertEqual(fr2.evaluate(), 1)
def test_basic_latex(self): # test the latex expression for fractions with numbers only fr = Fraction(3, 2) self.assertEqual(fr.latex(), "\\frac{3}{2}") fr2 = Fraction(-2, 2, sign=False) self.assertEqual(fr2.latex(), "-\\frac{-2}{2}")
def test_number_eq(self): main_fr = Fraction(1, 2) n = Number(3) self.assertEqual(False, main_fr == n)
def test_fraction_eq(self): main_fr = Fraction(1, 2) alt_fr = Fraction(1, 2, sign=False) self.assertEqual(False, main_fr == alt_fr) self.assertEqual(True, main_fr == -alt_fr)