summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_b1.py
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/test_b1.py
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/test_b1.py')
-rw-r--r--Lib/test/test_b1.py39
1 files changed, 39 insertions, 0 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)'