コード例 #1
0
class TestSortedDictIterMethods(unittest.TestCase):
    def setUp(self):
        self.sd = SortedDict([
            ('elma', 1),
            ('armut', 2),
            ('kel', 3),
            ('mahmut', 4)
        ])

    def test_items(self):
        l = [('armut', 2), ('elma', 1), ('kel', 3), ('mahmut', 4)]
        self.assertEqual(list(self.sd.items()), l)

    def test_keys(self):
        l = ['armut', 'elma', 'kel', 'mahmut']
        self.assertEqual(list(self.sd.keys()), l)

    def test_values(self):
        l = [2, 1, 3, 4]
        self.assertEqual(list(self.sd.values()), l)

    def test_iter(self):
        l = []
        for k in self.sd:
            l.append(k)
        self.assertEqual(l, ['armut', 'elma', 'kel', 'mahmut'])
コード例 #2
0
 def setUp(self):
     self.sd = SortedDict([
         ('elma', 1),
         ('armut', 2),
         ('kel', 3),
         ('mahmut', 4)
     ])