source: utilitiespy/test/tools/dictkeystest.py@ 1259

Last change on this file since 1259 was 1259, checked in by wouter, 2 days ago

added issuperset to Keys

File size: 1.2 KB
Line 
1from unittest.case import TestCase
2from tudelft.utilities.tools.dictkeys import Keys
3from collections.abc import Set
4
5
6class dictKeysTest(TestCase):
7 def testSimple(self):
8 d={'a':1,'b':2}
9 keys=Keys(d)
10 self.assertTrue(isinstance(keys,Set))
11 self.assertEquals(2, len(keys))
12 self.assertTrue('a' in keys)
13 self.assertFalse('d' in keys)
14 #self.assertFalse(d in keys)
15
16 self.assertEquals(None, keys.pop('d'))
17 self.assertEquals(1, keys.pop('a'))
18 self.assertEquals(1, len(d))
19
20
21 def testFrozen(self):
22 d={'a':1,'b':2}
23 keys=Keys(d)
24 print(frozenset(keys))
25 self.assertEqual(2, len(frozenset(keys)))
26
27 def test_difference_update(self):
28 d={'a':1,'b':2,'c':3}
29 keys=Keys(d)
30 keys.difference_update(set(['a','b']))
31 self.assertEquals(set(['c']), keys)
32
33 def test_issuperset(self):
34 self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({1:'x'})))
35 self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({0:'w',1:'x'})))
36 self.assertFalse(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({2:'x',3:'y'})))
37 self.assertTrue(Keys({0:'a',1:'b',2:'c'}).issuperset(Keys({})))
Note: See TracBrowser for help on using the repository browser.