Beispiel #1
0
 def test_string_key(self):
     dl = diclist()
     dl.add('a', 1)
     dl.add('b', 2)
     dl.add('c', 3)
     self.assertEqual([1,2,3], [value for value in dl] ) 
     self.assertEqual(dl['c'], 3)
Beispiel #2
0
 def test_string_key(self):
     dl = diclist()
     dl.add('a', 1)
     dl.add('b', 2)
     dl.add('c', 3)
     self.assertEqual([1, 2, 3], [value for value in dl])
     self.assertEqual(dl['c'], 3)
Beispiel #3
0
 def test_iter(self):
     dl = diclist()
     dl.add('a', 1)
     dl.add('b', 2)
     dl.add('c', 3)
     dl.values()
     keyval = []
     for key, value in dl.iteritems():
         keyval.append((key, value))
     self.assertListEqual(keyval, [('a', 1), ('b', 2), ('c', 3)])
     self.assertListEqual(dl.keys(), ['a', 'b', 'c'])
     self.assertListEqual(dl.values(), [1, 2, 3])
Beispiel #4
0
 def test_iter(self):
     dl = diclist()
     dl.add('a', 1)
     dl.add('b', 2)
     dl.add('c', 3)
     dl.values()
     keyval = []
     for key, value in dl.iteritems():
         keyval.append((key, value))
     self.assertListEqual(keyval,
                          [('a', 1), ('b', 2), ('c', 3)])
     self.assertListEqual(dl.keys(), ['a', 'b', 'c'])
     self.assertListEqual(dl.values(), [1, 2, 3])
Beispiel #5
0
 def test_float_key(self):
     dl = diclist()
     dl.add(1., 'a')
     dl.add(2., 'b')
     self.assertRaises(IndexError, dl.__getitem__, 2)
     self.assertEqual(dl[2.], 'b')
Beispiel #6
0
 def test_bad_int_key(self):
     dl = diclist()
     self.assertRaises(ValueError, dl.add, 1, 'a')
     self.assertRaises(ValueError, dl.add, 1L, 'a')
Beispiel #7
0
 def test_float_key(self):
     dl = diclist()
     dl.add(1., 'a')
     dl.add(2., 'b')
     self.assertRaises(IndexError, dl.__getitem__, 2)
     self.assertEqual(dl[2.], 'b')
Beispiel #8
0
 def test_bad_int_key(self):
     dl = diclist()
     self.assertRaises(ValueError, dl.add, 1, 'a')
     self.assertRaises(ValueError, dl.add, 1, 'a')
Beispiel #9
0
 def test_add_brackets(self):
     dl = diclist()
     dl['a'] = 1
     self.assertEqual(dl['a'], 1)
     self.assertEqual(dl[0], 1)
Beispiel #10
0
 def test_add_brackets(self):
     dl = diclist()
     dl['a'] = 1
     self.assertEqual(dl['a'], 1)
     self.assertEqual(dl[0], 1)