Skip to content

Commit 92131de

Browse files
authored
Fix compare() for subset check (S.A ⊆ T.A) (TheAlgorithms#4978)
1 parent 249ee1d commit 92131de

File tree

2 files changed

+5
-11
lines changed
  • src
    • main/java/com/thealgorithms/datastructures/crdt
    • test/java/com/thealgorithms/datastructures/crdt

2 files changed

+5
-11
lines changed

src/main/java/com/thealgorithms/datastructures/crdt/GSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean lookup(T e) {
5050
* @return true if the current G-Set is a subset of the other, false otherwise
5151
*/
5252
public boolean compare(GSet<T> other) {
53-
return elements.containsAll(other.elements);
53+
return other.elements.containsAll(elements);
5454
}
5555

5656
/**

src/test/java/com/thealgorithms/datastructures/crdt/GSetTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,14 @@ void testLookup() {
3232
void testCompare() {
3333
GSet<String> gSet1 = new GSet<>();
3434
GSet<String> gSet2 = new GSet<>();
35-
3635
gSet1.addElement("apple");
3736
gSet1.addElement("orange");
38-
3937
gSet2.addElement("orange");
40-
gSet2.addElement("banana");
41-
4238
assertFalse(gSet1.compare(gSet2));
43-
44-
GSet<String> gSet3 = new GSet<>();
45-
gSet3.addElement("apple");
46-
gSet3.addElement("orange");
47-
48-
assertTrue(gSet1.compare(gSet3));
39+
gSet2.addElement("apple");
40+
assertTrue(gSet1.compare(gSet2));
41+
gSet2.addElement("banana");
42+
assertTrue(gSet1.compare(gSet2));
4943
}
5044

5145
@Test

0 commit comments

Comments
 (0)