def test_intersect(self): s1 = EquivSet() s2 = EquivSet() r = s1.intersect(s2) self.assertTrue(r.is_empty()) s1.insert_equiv('a', 'b') r = s1.intersect(s2) self.assertTrue(r.is_empty()) s2.insert_equiv('b', 'c') r = s1.intersect(s2) self.assertTrue(r.is_empty()) s2.insert_equiv('d', 'a') r = s1.intersect(s2) self.assertTrue(r.is_empty()) s1.insert_equiv('a', 'e') s2.insert_equiv('c', 'd') r = s1.intersect(s2) self.assertTrue(r.is_equiv('a', 'b')) self.assertFalse(r.is_equiv('a', 'e')) self.assertFalse(r.is_equiv('c', 'd'))
def test_insert_equiv(self): s1 = EquivSet() s1.insert_equiv('a', 'b') self.assertTrue(s1.is_equiv('a', 'b')) self.assertTrue(s1.is_equiv('b', 'a')) s1.insert_equiv('c', 'd') self.assertTrue(s1.is_equiv('c', 'd')) self.assertFalse(s1.is_equiv('c', 'a')) s1.insert_equiv('a', 'c') self.assertTrue(s1.is_equiv('a', 'b', 'c', 'd')) self.assertFalse(s1.is_equiv('a', 'e'))