Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Lib / test / test_contains.py
blob2bc284bd312d441c242d3acfbeb65f7f7548e9c3
1 from test_support import TestFailed
3 class base_set:
5 def __init__(self, el):
6 self.el = el
8 class set(base_set):
10 def __contains__(self, el):
11 return self.el == el
13 class seq(base_set):
15 def __getitem__(self, n):
16 return [self.el][n]
18 def check(ok, *args):
19 if not ok:
20 raise TestFailed, join(map(str, args), " ")
22 a = base_set(1)
23 b = set(1)
24 c = seq(1)
26 check(1 in b, "1 not in set(1)")
27 check(0 not in b, "0 in set(1)")
28 check(1 in c, "1 not in seq(1)")
29 check(0 not in c, "0 in seq(1)")
31 try:
32 1 in a
33 check(0, "in base_set did not raise error")
34 except AttributeError:
35 pass
37 try:
38 1 not in a
39 check(0, "not in base_set did not raise error")
40 except AttributeError:
41 pass
43 # Test char in string
45 check('c' in 'abc', "'c' not in 'abc'")
46 check('d' not in 'abc', "'d' in 'abc'")
48 try:
49 '' in 'abc'
50 check(0, "'' in 'abc' did not raise error")
51 except TypeError:
52 pass
54 try:
55 'ab' in 'abc'
56 check(0, "'ab' in 'abc' did not raise error")
57 except TypeError:
58 pass
60 try:
61 None in 'abc'
62 check(0, "None in 'abc' did not raise error")
63 except TypeError:
64 pass