mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
Fix compare() for subset check (S.A ⊆ T.A) (#4978)
This commit is contained in:
@ -50,7 +50,7 @@ public class GSet<T> {
|
|||||||
* @return true if the current G-Set is a subset of the other, false otherwise
|
* @return true if the current G-Set is a subset of the other, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean compare(GSet<T> other) {
|
public boolean compare(GSet<T> other) {
|
||||||
return elements.containsAll(other.elements);
|
return other.elements.containsAll(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,20 +32,14 @@ class GSetTest {
|
|||||||
void testCompare() {
|
void testCompare() {
|
||||||
GSet<String> gSet1 = new GSet<>();
|
GSet<String> gSet1 = new GSet<>();
|
||||||
GSet<String> gSet2 = new GSet<>();
|
GSet<String> gSet2 = new GSet<>();
|
||||||
|
|
||||||
gSet1.addElement("apple");
|
gSet1.addElement("apple");
|
||||||
gSet1.addElement("orange");
|
gSet1.addElement("orange");
|
||||||
|
|
||||||
gSet2.addElement("orange");
|
gSet2.addElement("orange");
|
||||||
gSet2.addElement("banana");
|
|
||||||
|
|
||||||
assertFalse(gSet1.compare(gSet2));
|
assertFalse(gSet1.compare(gSet2));
|
||||||
|
gSet2.addElement("apple");
|
||||||
GSet<String> gSet3 = new GSet<>();
|
assertTrue(gSet1.compare(gSet2));
|
||||||
gSet3.addElement("apple");
|
gSet2.addElement("banana");
|
||||||
gSet3.addElement("orange");
|
assertTrue(gSet1.compare(gSet2));
|
||||||
|
|
||||||
assertTrue(gSet1.compare(gSet3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user