summaryrefslogtreecommitdiff
path: root/python/mpw
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-05-10 19:23:57 +0000
committerjbj <devnull@localhost>2003-05-10 19:23:57 +0000
commitf1d3267c1545146aec53c87662204f7422f400a3 (patch)
treeb15019c502b0e62333b6b55e735e71a09d9e2dd3 /python/mpw
parent728df698b6de1fe03ce3f8925e53e5a91340d61f (diff)
downloadrpm-f1d3267c1545146aec53c87662204f7422f400a3.tar.gz
rpm-f1d3267c1545146aec53c87662204f7422f400a3.tar.bz2
rpm-f1d3267c1545146aec53c87662204f7422f400a3.zip
Add coercion-on-the-fly.
Rename to python function, not tp_foo member, names. Tests for Knuth polynomial in base, iterativepowers. CVS patchset: 6830 CVS date: 2003/05/10 19:23:57
Diffstat (limited to 'python/mpw')
-rw-r--r--python/mpw/test/Makefile.am3
-rw-r--r--python/mpw/test/test_methods.py85
2 files changed, 81 insertions, 7 deletions
diff --git a/python/mpw/test/Makefile.am b/python/mpw/test/Makefile.am
index e9c22d8c7..a6cbc75e8 100644
--- a/python/mpw/test/Makefile.am
+++ b/python/mpw/test/Makefile.am
@@ -5,6 +5,7 @@ AUTOMAKE_OPTIONS = 1.4 foreign
PYVER= @WITH_PYTHON_VERSION@
pylibdir = $(shell python -c 'import sys; print sys.path[1]')
+VALGRIND = # valgrind --verbose --leak-check=yes
EXTRA_DIST = \
test_all.py test_methods.py \
@@ -13,4 +14,4 @@ EXTRA_DIST = \
all:
check:
- python test_all.py verbose
+ $(VALGRIND) python test_all.py verbose
diff --git a/python/mpw/test/test_methods.py b/python/mpw/test/test_methods.py
index 068019ded..9ec3f31bc 100644
--- a/python/mpw/test/test_methods.py
+++ b/python/mpw/test/test_methods.py
@@ -25,6 +25,9 @@ class BasicTestCase(unittest.TestCase):
a = 0x0000000987654321L
b = 0x0000000000000010L
c = 0x0fedcba000000000L
+ lo = 2
+ hi = 200
+ t = 10
def setUp(self):
rpm.mpw().Debug(0)
@@ -48,23 +51,21 @@ class BasicTestCase(unittest.TestCase):
wa = rpm.mpw(self.a)
wb = rpm.mpw(self.b)
wc = rpm.mpw(self.c)
- za = mpz.mpz(self.a)
- zb = mpz.mpz(self.b)
- zc = mpz.mpz(self.c)
+ za = long(self.a)
+ zb = long(self.b)
+ zc = long(self.c)
print "__int__:\t", int(wb), "\t", int(zb)
assert int(wb) == int(zb)
print "__long__:\t", long(wa), "\t", long(za)
-# assert str(long(wb)) == str(long(zb))
+ assert long(wb) == long(zb)
print "__float__:\t", float(wa), "\t", float(za)
assert float(wb) == float(zb)
zs = hex(za)
- zs = zs[4:len(zs)-1]
print "__hex__:\t", hex(wa), "\t", zs
assert hex(wa) == zs
zs = oct(za)
- zs = zs[4:len(zs)-1]
print "__oct__:\t", oct(wa), "\t", zs
assert oct(wa) == zs
@@ -104,6 +105,78 @@ class BasicTestCase(unittest.TestCase):
pass
#----------------------------------------
+ def test02_KnuthPoly(self):
+ self.t = 8
+ tfmt = "%o"
+ if verbose:
+ print '\n', '-=' * 30
+ print "Running %s.test02_KnuthPoly..." % \
+ self.__class__.__name__
+ print "\t(%d**m - 1) * (%d**n - 1), m,n in [%d,%d)" % (self.t,self.t,self.lo,self.hi)
+ tm1 = tfmt % (self.t - 1)
+ tm2 = tfmt % (self.t - 2)
+ for m in range(self.lo,self.hi):
+ for n in range(m+1,self.hi+1):
+ wt = rpm.mpw(self.t)
+ wa = (wt**m - 1) * (wt**n - 1)
+ ws = tfmt % long(wa)
+ zs = tm1 * (m - 1) + tm2 + tm1 * (n - m) + "0" * (m - 1) + "1"
+ if ws != zs:
+ print "(%d**%d - 1) * (%d**%d - 1)\t%s" % (self.t,m,self.t,n,ws)
+ assert ws == zs
+
+ self.t = 10
+ tfmt = "%d"
+ if verbose:
+ print "\t(%d**m - 1) * (%d**n - 1), m,n in [%d,%d)" % (self.t,self.t,self.lo,self.hi)
+ tm1 = tfmt % (self.t - 1)
+ tm2 = tfmt % (self.t - 2)
+ for m in range(self.lo,self.hi):
+ for n in range(m+1,self.hi+1):
+ wt = rpm.mpw(self.t)
+ wa = (wt**m - 1) * (wt**n - 1)
+ ws = tfmt % long(wa)
+ zs = tm1 * (m - 1) + tm2 + tm1 * (n - m) + "0" * (m - 1) + "1"
+ if ws != zs:
+ print "(%d**%d - 1) * (%d**%d - 1)\t%s" % (self.t,m,self.t,n,ws)
+ assert ws == zs
+
+ self.t = 16
+ tfmt = "%x"
+ if verbose:
+ print "\t(%d**m - 1) * (%d**n - 1), m,n in [%d,%d)" % (self.t,self.t,self.lo,self.hi)
+ tm1 = tfmt % (self.t - 1)
+ tm2 = tfmt % (self.t - 2)
+ for m in range(self.lo,self.hi):
+ for n in range(m+1,self.hi+1):
+ wt = rpm.mpw(self.t)
+ wa = (wt**m - 1) * (wt**n - 1)
+ ws = tfmt % long(wa)
+ zs = tm1 * (m - 1) + tm2 + tm1 * (n - m) + "0" * (m - 1) + "1"
+ if ws != zs:
+ print "(%d**%d - 1) * (%d**%d - 1)\t%s" % (self.t,m,self.t,n,ws)
+ assert ws == zs
+ pass
+
+ #----------------------------------------
+ def test03_IterativePowers(self):
+ if verbose:
+ print '\n', '-=' * 30
+ print "Running %s.test03_IterativePowers..." % \
+ self.__class__.__name__
+ print "\t(m**n)/(m**(n-1)) == m for m,n in [%d,%d)" % (self.lo,self.hi)
+ for m in range(self.lo,self.hi):
+ wa = rpm.mpw(m)
+ wd = wa
+ for n in range(self.lo,self.hi):
+ wc = wa**n
+ we = wc/wd
+ if we != m:
+ print m, '^', n, '=', we
+ assert we == m
+ if wc != 0:
+ wd = wc
+ pass
#----------------------------------------------------------------------
#----------------------------------------------------------------------