##// END OF EJS Templates
smartset: add some doctests...
Jun Wu -
r31019:74f77f1c default
parent child Browse files
Show More
@@ -158,6 +158,51 b' class baseset(abstractsmartset):'
158 operation that it should be able to perform.
158 operation that it should be able to perform.
159
159
160 Every method in this class should be implemented by any smartset class.
160 Every method in this class should be implemented by any smartset class.
161
162 This class could be constructed by an (unordered) set, or an (ordered)
163 list-like object. If a set is provided, it'll be sorted lazily.
164
165 >>> x = [4, 0, 7, 6]
166 >>> y = [5, 6, 7, 3]
167
168 Construct by a set:
169 >>> xs = baseset(set(x))
170 >>> ys = baseset(set(y))
171 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
172 [[0, 4, 6, 7, 3, 5], [6, 7], [0, 4]]
173 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
174 ['addset', 'filteredset', 'filteredset']
175
176 Construct by a list-like:
177 >>> xs = baseset(x)
178 >>> ys = baseset(i for i in y)
179 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
180 [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]]
181 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
182 ['addset', 'filteredset', 'filteredset']
183
184 Populate "_set" fields in the lists so set optimization may be used:
185 >>> [1 in xs, 3 in ys]
186 [False, True]
187
188 Without sort(), results won't be changed:
189 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
190 [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]]
191 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
192 ['addset', 'filteredset', 'filteredset']
193
194 With sort():
195 >>> xs.sort(reverse=True)
196 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
197 [[7, 6, 4, 0, 5, 3], [7, 6], [4, 0]]
198 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
199 ['addset', 'filteredset', 'filteredset']
200
201 >>> ys.sort()
202 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
203 [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]]
204 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
205 ['addset', 'filteredset', 'filteredset']
161 """
206 """
162 def __init__(self, data=(), datarepr=None, istopo=False):
207 def __init__(self, data=(), datarepr=None, istopo=False):
163 """
208 """
General Comments 0
You need to be logged in to leave comments. Login now