File indexing completed on 2024-11-25 02:29:50
0001 import unittest
0002
0003 from .diclist import diclist
0004
0005 class DiclistTestCase(unittest.TestCase):
0006
0007 def test_string_key(self):
0008 dl = diclist()
0009 dl.add('a', 1)
0010 dl.add('b', 2)
0011 dl.add('c', 3)
0012 self.assertEqual([1,2,3], [value for value in dl] )
0013 self.assertEqual(dl['c'], 3)
0014
0015 def test_bad_int_key(self):
0016 dl = diclist()
0017 self.assertRaises(ValueError, dl.add, 1, 'a')
0018 self.assertRaises(ValueError, dl.add, 1, 'a')
0019
0020 def test_float_key(self):
0021 dl = diclist()
0022 dl.add(1., 'a')
0023 dl.add(2., 'b')
0024 self.assertRaises(IndexError, dl.__getitem__, 2)
0025 self.assertEqual(dl[2.], 'b')
0026
0027
0028 if __name__ == '__main__':
0029 unittest.main()