예제 #1
0
 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)")
예제 #2
0
    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())
예제 #3
0
    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())
예제 #4
0
 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}")
예제 #5
0
    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}")
예제 #6
0
    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())
예제 #7
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)
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
    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}")
예제 #13
0
    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))")
예제 #14
0
    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)
예제 #15
0
 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)}")
예제 #16
0
 def test_block_eval(self):
     fr = Fraction(Chain([2,2]),Product([2,2], sign=False))
     self.assertEqual(fr.evaluate(), -1)
예제 #17
0
 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)
예제 #18
0
 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}")
예제 #19
0
 def test_number_eq(self):
     main_fr = Fraction(1, 2)
     n = Number(3)
     self.assertEqual(False, main_fr == n)
예제 #20
0
    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)