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

Last change on this file since 1278 was 1265, checked in by wouter, 2 months ago

#386 Added tests and lt and eq methods to Keys.

File size: 1.7 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({})))
38
39 def test_equals(self):
40 d1={'a':1,'b':2}
41 keys1=Keys(d1)
42 d2={'a':1,'b':2}
43 keys2=Keys(d2)
44 self.assertTrue(keys2<=keys1)
45 self.assertTrue(keys1<=keys2)
46 self.assertTrue(keys1==keys2)
47
48 d3={'a':1}
49 keys3=Keys(d3)
50 self.assertTrue(keys3<=keys1)
51 self.assertFalse(keys1<=keys3)
52 self.assertFalse(keys3==keys1)
53
54
55
Note: See TracBrowser for help on using the repository browser.