Skip to content

Commit

Permalink
resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh--Kumar committed Apr 19, 2017
1 parent 6480e2f commit 257e9a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 66 deletions.
36 changes: 16 additions & 20 deletions python/common/org/python/types/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,39 +459,35 @@ public org.python.Object isdisjoint(org.python.Object other) {
default_args = {"other"}
)
public org.python.Object issubset(org.python.Object other) {
if (other == null) {
throw new org.python.exceptions.TypeError("issubset() takes exactly one argument (0 given)");
}
java.util.Set<org.python.Object> intersection = new java.util.HashSet<org.python.Object>(this.value);
try {
intersection.retainAll(((org.python.types.Set) other).value);
} catch (ClassCastException te) {
org.python.types.Set otherSet = null;
if (other instanceof org.python.types.Set) {
otherSet = (org.python.types.Set) other;
} else {
otherSet = new org.python.types.Set(new org.python.Object[] {other}, null);
}
return this.__le__(otherSet);
} catch (org.python.exceptions.AttributeError e) {
throw new org.python.exceptions.TypeError("'" + other.typeName() + "' object is not iterable");
}
if (intersection.size() == this.value.size()) {
return new org.python.types.Bool(true);
}
return new org.python.types.Bool(false);
}

@org.python.Method(
__doc__ = "Test whether every element in other is in the set.",
default_args = {"other"}
)
public org.python.Object issuperset(org.python.Object other) {
if (other == null) {
throw new org.python.exceptions.TypeError("issuperset() takes exactly one argument (0 given)");
}
java.util.Set<org.python.Object> intersection = new java.util.HashSet<org.python.Object>(this.value);
try {
intersection.retainAll(((org.python.types.Set) other).value);
} catch (ClassCastException te) {
org.python.types.Set otherSet = null;
if (other instanceof org.python.types.Set) {
otherSet = (org.python.types.Set) other;
} else {
otherSet = new org.python.types.Set(new org.python.Object[] {other}, null);
}
return this.__ge__(otherSet);
} catch (org.python.exceptions.AttributeError e) {
throw new org.python.exceptions.TypeError("'" + other.typeName() + "' object is not iterable");
}
if (intersection.size() == ((org.python.types.Set) other).value.size()) {
return new org.python.types.Bool(true);
}
return new org.python.types.Bool(false);
}

@org.python.Method(
Expand Down
66 changes: 20 additions & 46 deletions tests/datatypes/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,67 +218,41 @@ def test_isdisjoint(self):
""")

def test_issubset(self):
# successful
self.assertCodeExecution("""
x = set("hello World !")
y = set("hello")
z = set()
t = set()
print(x.issubset(y))
print(x.issubset(z))
print(t.issubset(z))
print(t.issubset(y))
a = set('abc')
b = set('abcde')
c = set()
print(a.issubset(b))
print(a.issubset('ab'))
print(a.issubset(a))
print(a.issubset(c))
""")

# unsuccessful
# not iterable test
self.assertCodeExecution("""
x = 9.3
y = 5
l = set("hello World !")
m = set("hello")
try:
print(l.issubset(y))
except TypeError as err:
print(err)
try:
print(l.issubset(x))
except TypeError as err:
print(err)
a = {1, 2, 3}
try:
print(l.issubset())
print(a.issubset(1))
except TypeError as err:
print(err)
""")

def test_issuperset(self):
# successful
self.assertCodeExecution("""
x = set("hello World !")
y = set("hello")
z = set()
t = set()
print(x.issuperset(y))
print(x.issuperset(z))
print(t.issuperset(z))
print(t.issuperset(y))
a = set('abcd')
b = set('ab')
c = set()
print(a.issuperset(b))
print(a.issuperset('ab1'))
print(a.issuperset(a))
print(a.issuperset(c))
""")

# unsuccessful
# not iterable test
self.assertCodeExecution("""
x = 9.3
y = 5
l = set("hello World !")
m = set("hello")
try:
print(l.issuperset(y))
except TypeError as err:
print(err)
try:
print(l.issuperset(x))
except TypeError as err:
print(err)
a = {1, 2, 3}
try:
print(l.issuperset())
print(a.issuperset(1))
except TypeError as err:
print(err)
""")
Expand Down

0 comments on commit 257e9a4

Please sign in to comment.