from unittest.case import TestCase from tudelft.utilities.tools.dictkeys import Keys from collections.abc import Set class dictKeysTest(TestCase): def testSimple(self): d={'a':1,'b':2} keys=Keys(d) self.assertTrue(isinstance(keys,Set)) self.assertEquals(2, len(keys)) self.assertTrue('a' in keys) self.assertFalse('d' in keys) #self.assertFalse(d in keys) self.assertEquals(None, keys.pop('d')) self.assertEquals(1, keys.pop('a')) self.assertEquals(1, len(d)) def testFrozen(self): d={'a':1,'b':2} keys=Keys(d) print(frozenset(keys)) self.assertEqual(2, len(frozenset(keys))) def test_difference_update(self): d={'a':1,'b':2,'c':3} keys=Keys(d) keys.difference_update(set(['a','b'])) self.assertEquals(set(['c']), keys) def test_issuperset(self): self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({1:'x'}))) self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({0:'w',1:'x'}))) self.assertFalse(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({2:'x',3:'y'}))) self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({}))) def test_equals(self): d1={'a':1,'b':2} keys1=Keys(d1) d2={'a':1,'b':2} keys2=Keys(d2) self.assertTrue(keys2<=keys1) self.assertTrue(keys1<=keys2) self.assertTrue(keys1==keys2) d3={'a':1} keys3=Keys(d3) self.assertTrue(keys3<=keys1) self.assertFalse(keys1<=keys3) self.assertFalse(keys3==keys1)