Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_operator.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | b8a97ad5f7ce |
| children | aedd2d0dcb31 |
| rev | line source |
|---|---|
| 4777 | 1 import operator |
| 2 import sys | |
| 3 | |
| 4 def test(name, input, output, *args): | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4777
diff
changeset
|
5 print 'testing:', name |
| 4777 | 6 f = getattr(operator, name) |
| 7 params = (input,) + args | |
| 8 try: | |
| 9 val = apply(f, params) | |
| 10 except: | |
| 11 val = sys.exc_type | |
| 12 if val <> output: | |
| 13 print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`) | |
| 14 | |
| 15 test('abs', -1, 1) | |
| 16 test('add', 3, 7, 4) | |
| 17 test('and_', 0xf, 0xa, 0xa) | |
| 18 test('concat', 'py', 'python', 'thon') | |
| 19 | |
| 20 test('countOf', [1, 2, 1, 3, 1, 4], 1, 3) | |
| 21 | |
| 22 a = [4, 3, 2, 1] | |
| 23 test('delitem', a, None, 1) | |
| 24 if a <> [4, 2, 1]: | |
| 25 print 'delitem() failed' | |
| 26 | |
| 27 a = range(10) | |
| 28 test('delslice', a, None, 2, 8) | |
| 29 if a <> [0, 1, 8, 9]: | |
| 30 print 'delslice() failed' | |
| 31 | |
| 32 a = range(10) | |
| 33 test('div', 5, 2, 2) | |
| 34 test('getitem', a, 2, 2) | |
| 35 test('getslice', a, [4, 5], 4, 6) | |
| 36 test('indexOf', [4, 3, 2, 1], 1, 3) | |
| 37 test('inv', 4, -5) | |
| 38 test('isCallable', 4, 0) | |
| 39 test('isCallable', operator.isCallable, 1) | |
| 40 test('isMappingType', operator.isMappingType, 0) | |
| 41 test('isMappingType', operator.__dict__, 1) | |
| 42 test('isNumberType', 8.3, 1) | |
| 43 test('isNumberType', dir(), 0) | |
| 44 test('isSequenceType', dir(), 1) | |
| 45 test('isSequenceType', 'yeahbuddy', 1) | |
| 46 test('isSequenceType', 3, 0) | |
| 47 test('lshift', 5, 10, 1) | |
| 48 test('mod', 5, 1, 2) | |
| 49 test('mul', 5, 10, 2) | |
| 50 test('neg', 5, -5) | |
| 51 test('or_', 0xa, 0xf, 0x5) | |
| 52 test('pos', -5, -5) | |
| 53 | |
| 54 a = range(3) | |
| 55 test('repeat', a, a+a, 2) | |
| 56 test('rshift', 5, 2, 1) | |
| 57 | |
| 58 test('sequenceIncludes', range(4), 1, 2) | |
| 59 test('sequenceIncludes', range(4), 0, 5) | |
| 60 | |
| 61 test('setitem', a, None, 0, 2) | |
| 62 if a <> [2, 1, 2]: | |
| 63 print 'setitem() failed' | |
| 64 | |
| 65 a = range(4) | |
| 66 test('setslice', a, None, 1, 3, [2, 1]) | |
| 67 if a <> [0, 2, 1, 3]: | |
| 68 print 'setslice() failed:', a | |
| 69 | |
| 70 test('sub', 5, 2, 3) | |
| 71 test('truth', 5, 1) | |
| 72 test('truth', [], 0) | |
| 73 test('xor', 0xb, 0x7, 0xc) | |
| 74 | |
| 75 | |
| 76 # some negative tests | |
| 77 test('indexOf', [4, 3, 2, 1], ValueError, 9) |
