示例#1
0
 def test_mod(self):
     str1, str2 = "1010110101011", "1010101011"
     p1, p2 = Polynome(value=str1), Polynome(value=str2)
     p = p1 % p2
     self.assertEqual(p2 % p1, p1)
     print p1.order, p2.order
     print p1.printf(), p2.printf(), p.printf()
示例#2
0
 def test_add(self):
     str1, str2 = "1010110101011", "1010101011"
     p1, p2 = Polynome(value=str1), Polynome(value=str2)
     p = p1 + p2
     print p1.order, p2.order, p.order
     self.assertEqual(p.order, len(str1))
     self.assertEqual((p1+p1).order, 0)
     print p1.printf(), p2.printf(), p.printf()
示例#3
0
    def test_printf(self):
        value = "1010110101011"
        polynome = "x^12+x^10+x^8+x^7+x^5+x^3+x^1+x^0"

        p = Polynome(value=value)
        self.assertEqual(value, p.printf())
        self.assertEqual(value, p.printf(binary=True))
        self.assertEqual(polynome, p.printf(polynome=True))
        self.assertEqual(value, p.printf(polynome=True, binary=True))
        self.assertEqual(value[::-1], p.printf(binary=True, desc=True))
        self.assertEqual(value[::-1], p.printf(desc=True))
        self.assertEqual("+".join(polynome.split("+")[::-1]), p.printf(polynome=True, desc=True))

        p = Polynome(order=12)
        value = "0"*12
        polynome = ""

        self.assertEqual(value, p.printf())
        self.assertEqual(value, p.printf(binary=True))
        self.assertEqual(polynome, p.printf(polynome=True))
        self.assertEqual(value, p.printf(polynome=True, binary=True))
        self.assertEqual(value[::-1], p.printf(binary=True, desc=True))
        self.assertEqual(value[::-1], p.printf(desc=True))
        self.assertEqual("+".join(polynome.split("+")[::-1]), p.printf(polynome=True, desc=True))
示例#4
0
 def test_mul(self):
     p1, p2 = Polynome(value="1010110101011"), Polynome(value="1010101011")
     p = p1 * p2
     print p1.order, p2.order
     print p1.printf(), p2.printf(), p.printf()