[pypy-commit] pypy set-strategies: added tests for setstrategies
l.diekmann
noreply at buildbot.pypy.org
Thu Nov 10 13:49:45 CET 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49160:a69405cd53ae
Date: 2011-05-17 13:41 +0200
http://bitbucket.org/pypy/pypy/changeset/a69405cd53ae/
Log: added tests for setstrategies
diff --git a/pypy/objspace/std/test/test_setstrategies.py b/pypy/objspace/std/test/test_setstrategies.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/std/test/test_setstrategies.py
@@ -0,0 +1,42 @@
+from pypy.objspace.std.setobject import W_SetObject
+from pypy.objspace.std.setobject import IntegerSetStrategy, ObjectSetStrategy, EmptySetStrategy
+
+class TestW_SetStrategies:
+
+ def wrapped(self, l):
+ return [self.space.wrap(x) for x in l]
+
+ def test_from_list(self):
+ s = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
+ assert s.strategy is self.space.fromcache(IntegerSetStrategy)
+
+ s = W_SetObject(self.space, self.wrapped([1,"two",3,"four",5]))
+ assert s.strategy is self.space.fromcache(ObjectSetStrategy)
+
+ s = W_SetObject(self.space)
+ assert s.strategy is self.space.fromcache(EmptySetStrategy)
+
+ s = W_SetObject(self.space, self.wrapped([]))
+ assert s.strategy is self.space.fromcache(EmptySetStrategy)
+
+ def test_switch_to_object(self):
+ s = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
+ s.add(self.space.wrap("six"))
+ assert s.strategy is self.space.fromcache(ObjectSetStrategy)
+
+ s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
+ s2 = W_SetObject(self.space, self.wrapped(["six", "seven"]))
+ s1.symmetric_difference_update(s2)
+ assert s1.strategy is self.space.fromcache(ObjectSetStrategy)
+
+ s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
+ s2 = W_SetObject(self.space, self.wrapped(["six", "seven"]))
+ s1.update(s2)
+ assert s1.strategy is self.space.fromcache(ObjectSetStrategy)
+
+ def test_intersection(self):
+ s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
+ s2 = W_SetObject(self.space, self.wrapped([4,5, "six", "seven"]))
+ s3 = s1.intersect(s2)
+ assert s3.strategy is self.space.fromcache(IntegerSetStrategy)
+
More information about the pypy-commit
mailing list