def test_div_fast(self): one = Polynomial(map(GF2int, [8, 3, 5, 1])) two = Polynomial(map(GF2int, [5, 3, 1, 1, 6, 8])) q, r = two._fastdivmod(one) self.assertEqual(list(q.coefficients), [101, 152, 11]) self.assertEqual(list(r.coefficients), [183, 185, 3]) # Make sure they multiply back out okay self.assertEqual(q * one + r, two)
def test_div_fast(self): one = Polynomial(map(GF2int, [8,3,5,1])) two = Polynomial(map(GF2int, [5,3,1,1,6,8])) q, r = two._fastdivmod(one) self.assertEqual(list(q.coefficients), [101, 152, 11]) self.assertEqual(list(r.coefficients), [183, 185, 3]) # Make sure they multiply back out okay self.assertEqual(q*one + r, two)
def test_div_fast_1(self): # no remander one = Polynomial([1, 0, 0, 2, 2, 0, 1, -2, -4]) two = Polynomial([1, 0, -1]) q, r = one._fastdivmod(two) self.assertEqual(q, one._fastfloordiv(two)) self.assertEqual(r, one._fastmod(two)) self.assertEqual(list(q.coefficients), [1, 0, 1, 2, 3, 2, 4]) self.assertEqual(list(r.coefficients), [0])
def test_div_fast_1(self): # no remander one = Polynomial([1,0,0,2,2,0,1,-2,-4]) two = Polynomial([1,0,-1]) q, r = one._fastdivmod(two) self.assertEqual(q, one._fastfloordiv(two)) self.assertEqual(r, one._fastmod(two)) self.assertEqual(list(q.coefficients), [1,0,1,2,3,2,4]) self.assertEqual(list(r.coefficients), [0])
def test_div_gffast(self): one = Polynomial(map(GF2int, [1,3,5,1])) # must be monic! (because the function is optimized for monic divisor polynomial) two = Polynomial(map(GF2int, [5,3,1,1,6,8])) q, r = two._gffastdivmod(one) # optimized for monic divisor polynomial q2, r2 = two._fastdivmod(one) self.assertEqual(q, q2) self.assertEqual(r, r2) self.assertEqual(list(q.coefficients), [5, 12, 4]) self.assertEqual(list(r.coefficients), [52, 30, 12]) # Make sure they multiply back out okay self.assertEqual(q*one + r, two)
def test_div_gffast(self): one = Polynomial( map(GF2int, [1, 3, 5, 1]) ) # must be monic! (because the function is optimized for monic divisor polynomial) two = Polynomial(map(GF2int, [5, 3, 1, 1, 6, 8])) q, r = two._gffastdivmod(one) # optimized for monic divisor polynomial q2, r2 = two._fastdivmod(one) self.assertEqual(q, q2) self.assertEqual(r, r2) self.assertEqual(list(q.coefficients), [5, 12, 4]) self.assertEqual(list(r.coefficients), [52, 30, 12]) # Make sure they multiply back out okay self.assertEqual(q * one + r, two)