summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-11-08 15:05:21 (GMT)
committerGuido van Rossum <guido@python.org>1993-11-08 15:05:21 (GMT)
commite65cce5eec23812d77a54095209c923937cc3c92 (patch)
treeed0b87870ad9c6278e43acf63685b8823cce018c /Lib/test
parentdb65a6ce556b1e311d03837fbf85ca52ef2c5d07 (diff)
downloadcpython-e65cce5eec23812d77a54095209c923937cc3c92.zip
cpython-e65cce5eec23812d77a54095209c923937cc3c92.tar.gz
cpython-e65cce5eec23812d77a54095209c923937cc3c92.tar.bz2
* string.py: added rindex(), rfind(); changed index() to interpret
negative start indices starting from the right. * ftplib.py: debug() -> set_debuglevel(); change demo to use __init__(). * os.py: added execl, execlp, and execvp. * lambda.py: removed (now that we have built-in map, reduce, bagof, lambda) * test_b{1,2}.py, testall.out: added tests for bagof, lambda, map, reduce * commands.py: use os, not posix * test_grammar.py: make it easy to disable non-portable int overflow tests * dis.py: don't abuse range()
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_b1.py39
-rw-r--r--Lib/test/test_b2.py10
-rw-r--r--Lib/test/test_grammar.py23
-rw-r--r--Lib/test/testall.out4
4 files changed, 66 insertions, 10 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py
index c258fd7..396c5c2 100644
--- a/Lib/test/test_b1.py
+++ b/Lib/test/test_b1.py
@@ -90,6 +90,14 @@ f.close()
execfile(TESTFN)
unlink(TESTFN)
+print 'filter'
+if filter("c: 'a' <= c <= 'z'", 'Hello World') <> 'elloorld':
+ raise TestFailed, 'filter (filter a string)'
+if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]:
+ raise TestFailed, 'filter (remove false values)'
+if filter('x: x > 0', [1, -3, 9, 0, 2]) <> [1, 9, 2]:
+ raise TestFailed, 'filter (keep positives)'
+
print 'float'
if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'
if float(314) <> 314.0: raise TestFailed, 'float(314)'
@@ -112,6 +120,11 @@ if int(314) <> 314: raise TestFailed, 'int(314)'
if int(3.14) <> 3: raise TestFailed, 'int(3.14)'
if int(314L) <> 314: raise TestFailed, 'int(314L)'
+print 'lambda'
+binary_plus = lambda('x, y: x+y')
+if binary_plus(2, 10) <> 12:
+ raise TestFailed, 'binary_plus(2, 10)'
+
print 'len'
if len('123') <> 3: raise TestFailed, 'len(\'123\')'
if len(()) <> 0: raise TestFailed, 'len(())'
@@ -125,6 +138,32 @@ if long(314) <> 314L: raise TestFailed, 'long(314)'
if long(3.14) <> 3L: raise TestFailed, 'long(3.14)'
if long(314L) <> 314L: raise TestFailed, 'long(314L)'
+print 'map'
+if map(None, 'hello world') <> ['h','e','l','l','o',' ','w','o','r','l','d']:
+ raise TestFailed, 'map(None, \'hello world\')'
+if map(None, 'abcd', 'efg') <> \
+ [('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
+ raise TestFailed, 'map(None, \'abcd\', \'efg\')'
+if map(None, range(10)) <> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
+ raise TestFailed, 'map(None, range(10))'
+if map('x: x*x', range(1,4)) <> [1, 4, 9]:
+ raise TestFailed, 'map(\'x: x*x\', range(1,4))'
+from math import sqrt
+if map('x: map(sqrt,x)', [[16, 4], [81, 9]]) <> [[4.0, 2.0], [9.0, 3.0]]:
+ raise TestFailed, map('x: map(sqrt,x)', [[16, 4], [81, 9]])
+if map('x,y: x+y', [1,3,2], [9,1,4]) <> [10, 4, 6]:
+ raise TestFailed, 'map(\'x,y: x+y\', [1,3,2], [9,1,4])'
+def plus(*v):
+ accu = 0
+ for i in v: accu = accu + i
+ return accu
+if map(plus, [1, 3, 7]) <> [1, 3, 7]:
+ raise TestFailed, 'map(plus, [1, 3, 7])'
+if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]:
+ raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
+if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]:
+ raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
+
print 'max'
if max('123123') <> '3': raise TestFailed, 'max(\'123123\')'
if max(1, 2, 3) <> 3: raise TestFailed, 'max(1, 2, 3)'
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index ca06049..037955e 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -111,6 +111,16 @@ finally:
sys.stdin = savestdin
fp.close()
+print 'reduce'
+if reduce('x,y:x+y', ['a', 'b', 'c'], '') <> 'abc':
+ raise TestFailed, 'reduce(): implode a string'
+if reduce('x,y:x+y', [['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']:
+ raise TestFailed, 'reduce(): append'
+if reduce('x,y: x*y', range(2,8), 1) <> 5040:
+ raise TestFailed, 'reduce(): compute 7!'
+if reduce('x,y:x*y', range(2,21), 1L) <> 2432902008176640000L:
+ raise TestFailed, 'reduce(): compute 20!, use long'
+
print 'reload'
import string
reload(string)
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index f07f75b..4c9e7b0 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -24,16 +24,19 @@ print '1.1.2.1 Plain integers'
if 0xff <> 255: raise TestFailed, 'hex int'
if 0377 <> 255: raise TestFailed, 'octal int'
if 2147483647 != 017777777777: raise TestFailed, 'max positive int'
-if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
-# XXX -2147483648
-if 037777777777 != -1: raise TestFailed, 'oct -1'
-if 0xffffffff != -1: raise TestFailed, 'hex -1'
-for s in '2147483648', '040000000000', '0x100000000':
- try:
- x = eval(s)
- except OverflowError:
- continue
- raise TestFailed, 'No OverflowError on huge integer literal ' + `s`
+# Change the following line to "if 0:" if you have 64-bit integers
+if 1:
+ if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
+ # XXX -2147483648
+ if 037777777777 != -1: raise TestFailed, 'oct -1'
+ if 0xffffffff != -1: raise TestFailed, 'hex -1'
+ for s in '2147483648', '040000000000', '0x100000000':
+ try:
+ x = eval(s)
+ except OverflowError:
+ continue
+ raise TestFailed, \
+ 'No OverflowError on huge integer literal ' + `s`
print '1.1.2.2 Long integers'
x = 0L
diff --git a/Lib/test/testall.out b/Lib/test/testall.out
index e1ee9da..1dbb42a 100644
--- a/Lib/test/testall.out
+++ b/Lib/test/testall.out
@@ -73,12 +73,15 @@ dir
divmod
eval
execfile
+filter
float
getattr
hex
int
+lambda
len
long
+map
max
min
test_b2
@@ -90,6 +93,7 @@ range
input and raw_input
testing
testing
+reduce
reload
repr
round