Ejemplo n.º 1
0
def test_key_index():
    d = OrderedDict([('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')])

    assert d.key_index('a') == 0
    assert d.key_index('c') == 1
    assert d.key_index('e') == 2
    assert d.key_index('g') == 3
Ejemplo n.º 2
0
def test_key_index():
    d = OrderedDict([('a', 'b'),
               ('c', 'd'),
               ('e', 'f'),
               ('g', 'h')])

    assert d.key_index('a') == 0
    assert d.key_index('c') == 1
    assert d.key_index('e') == 2
    assert d.key_index('g') == 3
Ejemplo n.º 3
0
class TestOrderedDict(unittest.TestCase):
    def setUp(self):
        self._test_keys = ['a', 'b', 'c']
        self._test_vals = [-2, 0, 1]
        self.d = OrderedDict(zip(self._test_keys, self._test_vals))

    def test_order(self):
        self.assertEquals(self.d.keys(), [key for key in self._test_keys])

    def test_index(self):
        self.assertEquals(self.d.key_index('c'), 2)

    def test_reorder(self):
        new_order = ['c', 'a', 'b']
        self.d.reorder_keys(new_order)
        self.assertEquals(self.d.keys(), new_order)