Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
add implementation for set.intersection()
Browse files Browse the repository at this point in the history
  • Loading branch information
stummjr committed Nov 20, 2016
1 parent 2789885 commit 53dd179
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions python/common/org/python/types/Set.java
Expand Up @@ -380,10 +380,13 @@ public org.python.Object __iadd__(org.python.Object other) {
}

@org.python.Method(
__doc__ = ""
__doc__ = "Return the intersection of two sets as a new set.\n\n(i.e. all elements that are in both sets.)",
args = {"other"}
)
public org.python.Object intersection(org.python.Object other) {
throw new org.python.exceptions.NotImplementedError("intersection() has not been implemented.");
java.util.Set set = ((Set) this.copy()).value;
set.retainAll(((Set) other).value);
return new Set(set);
}

@org.python.Method(
Expand Down
8 changes: 7 additions & 1 deletion tests/datatypes/test_set.py
Expand Up @@ -100,7 +100,13 @@ def test_discard(self):
print(x)
""")


def test_intersection(self):
self.assertCodeExecution("""
x = {1, 2, 3}
y = {3, 4, 5}
z = x.intersection(y)
print(z)
""")


class UnarySetOperationTests(UnaryOperationTestCase, TranspileTestCase):
Expand Down

0 comments on commit 53dd179

Please sign in to comment.