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.union()
Browse files Browse the repository at this point in the history
  • Loading branch information
stummjr committed Nov 20, 2016
1 parent ccb1c34 commit d905db7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/common/org/python/types/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,13 @@ public org.python.Object symmetric_difference_update(org.python.Object other) {
}

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

@org.python.Method(
Expand Down
8 changes: 8 additions & 0 deletions tests/datatypes/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def test_remove(self):
print(x)
""")

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


class UnarySetOperationTests(UnaryOperationTestCase, TranspileTestCase):
data_type = 'set'
Expand Down

0 comments on commit d905db7

Please sign in to comment.