Commit 33443390 authored by Tim Peters's avatar Tim Peters

nextKeyAsSet(): Simplified the code. Added a new test to exercise it.

parent 199bf595
......@@ -16,7 +16,7 @@
Set operations
****************************************************************************/
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.18 2002/06/03 17:21:55 tim_one Exp $\n"
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.19 2002/06/03 17:45:08 tim_one Exp $\n"
#ifdef INTSET_H
static int
......@@ -49,18 +49,7 @@ nextIntSet(SetIteration *i)
static int
nextKeyAsSet(SetIteration *i)
{
/* XXX Looks like this block could be replaced by
* XXX i->position = i->position == 0 ? 1 : -1;
*/
if (i->position >= 0)
{
if (i->position < 1)
{
i->position ++;
}
else
i->position = -1;
}
i->position = i->position == 0 ? 1 : -1;
return 0;
}
#endif
......
......@@ -69,6 +69,19 @@ class TestMultiUnion(TestCase):
self.assertEqual(len(output), N*4)
self.assertEqual(list(output), range(-N, 3*N))
def testFunkyKeyIteration(self):
# The internal set iteration protocol allows "iterating over" a
# a single key as if it were a set.
N = 100
slow = IISet()
for i in range(N):
slow = union(slow, IISet([i]))
fast = multiunion(range(N)) # acts like N distinct singleton sets
self.assertEqual(len(slow), N)
self.assertEqual(len(fast), N)
self.assertEqual(list(slow.keys()), list(fast.keys()))
self.assertEqual(list(fast.keys()), range(N))
def test_suite():
return makeSuite(TestMultiUnion, 'test')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment