Exemplo n.º 1
0
 def testDiv(self):
     zero = FinitePrimeFieldElement(0, 5)
     one = FinitePrimeFieldElement(1, 5)
     self.failUnless(isinstance(zero.__div__(one), FinitePrimeFieldElement))
     self.failUnless(
         isinstance(zero.__truediv__(one), FinitePrimeFieldElement))
     self.assertEqual(zero, zero / one)
Exemplo n.º 2
0
 def testSub(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     residue2 = FinitePrimeFieldElement(2, 151)
     self.failUnless(
         isinstance(residue1 - residue2, FinitePrimeFieldElement))
     # the followings are possible now. are they correct?
     self.failUnless(isinstance(residue1 - 2, FinitePrimeFieldElement))
     self.failUnless(isinstance(1 - residue2, FinitePrimeFieldElement))
Exemplo n.º 3
0
 def testOrder(self):
     zero = FinitePrimeFieldElement(0, 5)
     one = FinitePrimeFieldElement(1, 541)
     minusone = FinitePrimeFieldElement(3910, 3911)
     elem = FinitePrimeFieldElement(12, 17)
     self.assertRaises(ValueError, zero.order)
     self.assertEqual(1, one.order())
     self.assertEqual(2, minusone.order())
     self.assertEqual(16, elem.order())
Exemplo n.º 4
0
 def testInit(self):
     elem = FinitePrimeFieldElement(12, 17)
     self.failUnless(elem)
     self.assertEqual(12, elem.toInteger())
     self.assertEqual(17, elem.getModulus())
     residue = FinitePrimeFieldElement(Rational(8, 15), 11)
     self.failUnless(residue)
     self.assertEqual(2, residue.toInteger())
     self.assertEqual(11, residue.getModulus())
Exemplo n.º 5
0
 def testMul(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     residue2 = FinitePrimeFieldElement(2, 151)
     self.failUnless(residue1 * residue2)
     self.failUnless(
         isinstance(residue1 * residue2, FinitePrimeFieldElement))
     self.assertEqual(16, (residue1 * residue2).toInteger())
     self.assertEqual(151, (residue1 * residue2).getModulus())
     self.failUnless(residue1 * 2)
     self.assertEqual(16, (residue1 * 2).toInteger())
     self.assertEqual(151, (residue1 * 2).getModulus())
     self.failUnless(2 * residue1)
     self.assertEqual(16, (2 * residue1).toInteger())
     self.assertEqual(151, (2 * residue1).getModulus())
     self.failUnless(residue1 * Rational(1, 76))
     self.assertEqual(16, (residue1 * Rational(1, 76)).toInteger())
     self.assertEqual(151, (residue1 * Rational(1, 76)).getModulus())
     self.failUnless(Rational(1, 76) * residue1)
     self.assertEqual(16, (Rational(1, 76) * residue1).toInteger())
     self.assertEqual(151, (Rational(1, 76) * residue1).getModulus())
Exemplo n.º 6
0
 def testContains(self):
     # elements of the field
     F125 = FiniteExtendedField(5, 3)
     self.assert_(F125.one in F125)
     self.assert_(F125.createElement(17) in F125)
     # elements of prime fields
     self.assert_(FinitePrimeField.getInstance(5).one in F125)
     # different characteristic
     self.failIf(FinitePrimeFieldElement(3, 7) in F125)
     # elements of disjoint fields
     F25 = FiniteExtendedField(5, 2)
     self.failIf(F25.one in F125)
     self.failIf(F25.createElement(17) in F125)
     F625 = FiniteExtendedField(5, 4)
     self.failIf(F625.one in F125)
     self.failIf(F625.createElement(17) in F125)
     # we don't expect an element of extended fields be in the field
     # even if it actually is.
     F15625 = FiniteExtendedField(5, 6)
     self.failIf(F15625.one in F125)
Exemplo n.º 7
0
 def testNonzero(self):
     self.failUnless(FinitePrimeFieldElement(12, 17))
     self.failIf(FinitePrimeFieldElement(0, 17))
Exemplo n.º 8
0
 def testGetRing(self):
     elem = FinitePrimeFieldElement(12, 17)
     f17 = elem.getRing()
     self.failUnless(isinstance(f17, FinitePrimeField))
     self.failUnless(elem in f17)
Exemplo n.º 9
0
 def testInverse(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     self.failUnless(isinstance(residue1.inverse(),
                                FinitePrimeFieldElement))
Exemplo n.º 10
0
 def testAdd(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     residue2 = FinitePrimeFieldElement(2, 151)
     self.failUnless(
         isinstance(residue1 + residue2, FinitePrimeFieldElement))
Exemplo n.º 11
0
 def testConst(self):
     self.assertEqual(FinitePrimeFieldElement(1, 17), self.F17.one)
     self.assertEqual(FinitePrimeFieldElement(0, 17), self.F17.zero)
     self.assertEqual(self.F17.one, self.F17.one * self.F17.one)
     self.assertEqual(self.F17.one, self.F17.one + self.F17.zero)
     self.assertEqual(self.F17.zero, self.F17.zero * self.F17.zero)
Exemplo n.º 12
0
 def testNonzero(self):
     self.assertTrue(FinitePrimeFieldElement(12, 17))
     self.assertFalse(FinitePrimeFieldElement(0, 17))
Exemplo n.º 13
0
 def testGetRing(self):
     elem = FinitePrimeFieldElement(12, 17)
     f17 = elem.getRing()
     self.assertTrue(isinstance(f17, FinitePrimeField))
     self.assertTrue(elem in f17)
Exemplo n.º 14
0
 def testInverse(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     self.assertTrue(isinstance(residue1.inverse(),
                                FinitePrimeFieldElement))
Exemplo n.º 15
0
 def testAdd(self):
     residue1 = FinitePrimeFieldElement(8, 151)
     residue2 = FinitePrimeFieldElement(2, 151)
     self.assertTrue(
         isinstance(residue1 + residue2, FinitePrimeFieldElement))