Esempio n. 1
0
 def test_to_tuple(self):
     for i in xrange(50):
         t = rand_int_tuple(40, 14)
         m = PackedPowers(t, bits=4)
         tt = m.to_tuple()
         self.assert_(type(tt) == tuple)
         self.assert_(t == tt)
Esempio n. 2
0
 def test_call_all_zero(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         zero = (0.0,)*len(eg)
         if p.degree()==0:
             self.assertEquals(p(zero), 1.0)
         else:
             self.assertEquals(p(zero), 0.0)
Esempio n. 3
0
 def test_pow(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         for i in xrange(10):
             eg10 = tuple([i*j for j in eg])
             try:
                 self.assertEquals(p**i, PackedPowers(eg10))
             except InsufficientBitsError:
                 pass
Esempio n. 4
0
 def test_diff(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         for var in xrange(len(eg)):
             coeff, q = p.diff(var)
             self.assertEquals(coeff, eg[var])
             msg = repr(eg)+' -> '+repr(q)
             for j in xrange(len(eg)):
                 if j==var:
                     if eg[j]==0:
                         self.assertEquals(q[j], 0, msg)
                     else:
                         self.assertEquals(q[j], eg[j]-1, msg)
                 else:
                     self.assertEquals(q[j], eg[j], msg)
Esempio n. 5
0
 def test_call_wrong_len(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         for l in xrange(0, len(eg)*2):
             x = rand_int_tuple(l, 10)
             if not l==len(eg):
                 self.assertRaises(IndexError, p.__call__, x)
Esempio n. 6
0
 def test_dict(self):
     t = (1, 2, 3)
     p = PackedPowers(t, bits=3)
     d = {}
     d[t] = -99.0
     self.assert_(d.has_key(p))
     self.assert_(d[p] == d[t])
Esempio n. 7
0
 def test_mul(self):
     lengths = 50
     cases = 20
     bits = 25
     max_val = int((1<<bits)-1)/2
     for length in xrange(lengths):
         for case in xrange(cases):
             pt = rand_int_tuple(length, max_val)
             p = PackedPowers(pt, bits)
             qt = rand_int_tuple(length, max_val)
             q = PackedPowers(qt, bits)
             rt = tuple([a+b for a,b in zip(pt, qt)])
             r = PackedPowers(rt, bits)
             self.assertEquals(p*q, r)
             self.assertEquals(repr(p*q),
                               'PackedPowers(%s, bits=%d)'%(repr(rt),
                                                              bits))
Esempio n. 8
0
 def test_call_negative_counts(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         deg = sum(eg)
         neg = sum([1 for i in eg if i%2])%2
         eno = (-1.0,)*len(eg)
         r = p(eno)
         if deg==0:
             self.assert_(r==1.0)
         if neg:
             self.assert_(r==-1.0)
         else:
             self.assert_(r==1.0)
Esempio n. 9
0
 def test_call_any_zero(self):
     """any monomial (no coeff) evaluated at (1.0,)*len gives 1.0"""
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         for var in range(len(eg)):
             x = [float(i+1) for i in rand_int_tuple(len(eg), 3)]
             x[var] = 0.0
             if p[var]==0:
                 self.assert_(not p(x)==0.0)
             else:
                 # test for NaN, doubles may/will overflow
                 px = p(x)
                 if px==px:
                     self.assertEquals(px, 0.0)
Esempio n. 10
0
 def test_negative_index(self):
     for i in xrange(-10, 0):
         m = PackedPowers()
         self.assertRaises(IndexError, m.diff, i)
Esempio n. 11
0
 def test_call_all_one(self):
     """any monomial (no coeff) evaluated at (1.0,)*len gives 1.0"""
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         one = (1.0,)*len(eg)
         self.assertEquals(p(one), 1.0)
Esempio n. 12
0
 def test_equal_other_same(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p, PackedPowers(eg, bits))
Esempio n. 13
0
 def test_number_of_variables(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p.number_of_variables(), len(eg))
Esempio n. 14
0
 def test_not_eq(self):
     t = ()
     p = PackedPowers(t, bits=4)
     self.assert_(not ((1,) == p))
Esempio n. 15
0
 def test_empty(self):
     t = ()
     m = TuplePowers(t)
     p = PackedPowers(t, bits=4)
     self.assert_(t == p)
     self.assert_(m == p)
Esempio n. 16
0
 def test_negative_pow(self):
     for i in xrange(-10, 0):
         m = PackedPowers()
         self.assertRaises(ValueError, m.__pow__, i)
Esempio n. 17
0
 def test_repr(self):
     m = PackedPowers()
     self.assertEquals(repr(m), 'PackedPowers((1,), bits=4)')
Esempio n. 18
0
 def test_pow_one_is_same(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p**1, p)
Esempio n. 19
0
 def test_pow_zero_is_one(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p**0, PackedPowers((0,)*len(eg)))
Esempio n. 20
0
 def test_repr(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(repr(p), 'PackedPowers(%s, bits=%d)'%(repr(eg),
                                                                   bits))
Esempio n. 21
0
 def test_degree(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p.degree(), sum(eg))
Esempio n. 22
0
 def test_bad_index(self):
     for i in xrange(1, 10):
         m = PackedPowers()
         self.assertRaises(IndexError, m.diff, i)
Esempio n. 23
0
 def test_diff_powers(self):
     m = PackedPowers()
     c, d = m.diff(0)
     self.assertEquals(repr(d), 'PackedPowers((0,), bits=4)')
Esempio n. 24
0
 def test_equal_self(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assertEquals(p, p)
Esempio n. 25
0
 def test_pows(self):
     p = PackedPowers()
     for i in xrange(10):
         self.assertEquals(p**i, PackedPowers((i,)))
Esempio n. 26
0
 def test_less_equal_self(self):
     for eg, bits in self.examples:
         p = PackedPowers(eg, bits)
         self.assert_(p<=p)
Esempio n. 27
0
 def test_empty(self):
     t = ()
     p = PackedPowers(t, bits=4)
     self.assert_(t == p)
Esempio n. 28
0
 def test_diff_coeff(self):
     m = PackedPowers()
     c, d = m.diff(0)
     self.assertEquals(c, 1)
Esempio n. 29
0
 def test_example(self):
     t = (1, 2, 3)
     p = PackedPowers(t, bits=3)
     self.assert_(t == p)
Esempio n. 30
0
 def test_degree(self):
     m = PackedPowers()
     self.assertEquals(m.degree(), 1)