Exemplo n.º 1
0
def test_dictionary():
    notifications = []

    def listener(longest_key):
        notifications.append(longest_key)

    d = StenoDictionary()
    assert d.longest_key == 0
    assert len(d) == 0
    assert not d

    d.add_longest_key_listener(listener)
    d[('S', )] = 'a'
    assert d.longest_key == 1
    assert ('S', ) in d
    assert notifications == [1]
    assert len(d) == 1
    assert d
    d[('S', 'S', 'S', 'S')] = 'b'
    assert d.longest_key == 4
    assert notifications == [1, 4]
    assert len(d) == 2
    d[('S', 'S')] = 'c'
    assert d.longest_key == 4
    assert d[('S', 'S')] == 'c'
    assert notifications == [1, 4]
    assert len(d) == 3
    del d[('S', 'S', 'S', 'S')]
    assert d.longest_key == 2
    assert notifications == [1, 4, 2]
    assert len(d) == 2
    del d[('S', )]
    assert d.longest_key == 2
    assert ('S', ) not in d
    assert notifications == [1, 4, 2]
    assert len(d) == 1
    assert d.reverse_lookup('c') == [('S', 'S')]
    assert d.casereverse_lookup('c') == ['c']
    d.clear()
    assert d.longest_key == 0
    assert notifications == [1, 4, 2, 0]
    assert len(d) == 0
    assert not d
    assert d.reverse_lookup('c') == []
    assert d.casereverse_lookup('c') == []

    d.remove_longest_key_listener(listener)
    d[('S', 'S')] = 'c'
    assert d.longest_key == 2
    assert notifications == [1, 4, 2, 0]
    def test_dictionary(self):
        notifications = []

        def listener(longest_key):
            notifications.append(longest_key)

        d = StenoDictionary()
        self.assertEqual(d.longest_key, 0)

        d.add_longest_key_listener(listener)
        d[('S', )] = 'a'
        self.assertEqual(d.longest_key, 1)
        self.assertEqual(notifications, [1])
        d[('S', 'S', 'S', 'S')] = 'b'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(notifications, [1, 4])
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(d[('S', 'S')], 'c')
        self.assertEqual(notifications, [1, 4])
        del d[('S', 'S', 'S', 'S')]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        del d[('S', )]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        self.assertEqual(d.reverse_lookup('c'), [('S', 'S')])
        self.assertEqual(d.casereverse_lookup('c'), ['c'])
        d.clear()
        self.assertEqual(d.longest_key, 0)
        self.assertEqual(notifications, [1, 4, 2, 0])
        self.assertEqual(d.reverse_lookup('c'), [])
        self.assertEqual(d.casereverse_lookup('c'), [])

        d.remove_longest_key_listener(listener)
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2, 0])
Exemplo n.º 3
0
def test_dictionary():
    notifications = []

    def listener(longest_key):
        notifications.append(longest_key)

    d = StenoDictionary()
    assert d.longest_key == 0

    d.add_longest_key_listener(listener)
    d[('S', )] = 'a'
    assert d.longest_key == 1
    assert notifications == [1]
    d[('S', 'S', 'S', 'S')] = 'b'
    assert d.longest_key == 4
    assert notifications == [1, 4]
    d[('S', 'S')] = 'c'
    assert d.longest_key == 4
    assert d[('S', 'S')] == 'c'
    assert notifications == [1, 4]
    del d[('S', 'S', 'S', 'S')]
    assert d.longest_key == 2
    assert notifications == [1, 4, 2]
    del d[('S', )]
    assert d.longest_key == 2
    assert notifications == [1, 4, 2]
    assert d.reverse_lookup('c') == {('S', 'S')}
    assert d.casereverse_lookup('c') == {'c'}
    d.clear()
    assert d.longest_key == 0
    assert notifications == [1, 4, 2, 0]
    assert d.reverse_lookup('c') == set()
    assert d.casereverse_lookup('c') == set()

    d.remove_longest_key_listener(listener)
    d[('S', 'S')] = 'c'
    assert d.longest_key == 2
    assert notifications == [1, 4, 2, 0]
Exemplo n.º 4
0
    def test_dictionary(self):
        notifications = []
        def listener(longest_key):
            notifications.append(longest_key)

        d = StenoDictionary()
        self.assertEqual(d.longest_key, 0)

        d.add_longest_key_listener(listener)
        d[('S',)] = 'a'
        self.assertEqual(d.longest_key, 1)
        self.assertEqual(notifications, [1])
        d[('S', 'S', 'S', 'S')] = 'b'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(notifications, [1, 4])
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(d[('S', 'S')], 'c')
        self.assertEqual(notifications, [1, 4])
        del d[('S', 'S', 'S', 'S')]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        del d[('S',)]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        self.assertEqual(d.reverse_lookup('c'), [('S', 'S')])
        self.assertEqual(d.casereverse_lookup('c'), ['c'])
        d.clear()
        self.assertEqual(d.longest_key, 0)
        self.assertEqual(notifications, [1, 4, 2, 0])
        self.assertEqual(d.reverse_lookup('c'), [])
        self.assertEqual(d.casereverse_lookup('c'), [])

        d.remove_longest_key_listener(listener)
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2, 0])
Exemplo n.º 5
0
def test_dictionary():
    notifications = []
    def listener(longest_key):
        notifications.append(longest_key)

    d = StenoDictionary()
    assert d.longest_key == 0

    d.add_longest_key_listener(listener)
    d[('S',)] = 'a'
    assert d.longest_key == 1
    assert notifications == [1]
    d[('S', 'S', 'S', 'S')] = 'b'
    assert d.longest_key == 4
    assert notifications == [1, 4]
    d[('S', 'S')] = 'c'
    assert d.longest_key == 4
    assert d[('S', 'S')] == 'c'
    assert notifications == [1, 4]
    del d[('S', 'S', 'S', 'S')]
    assert d.longest_key == 2
    assert notifications == [1, 4, 2]
    del d[('S',)]
    assert d.longest_key == 2
    assert notifications == [1, 4, 2]
    assert d.reverse_lookup('c') == [('S', 'S')]
    assert d.casereverse_lookup('c') == ['c']
    d.clear()
    assert d.longest_key == 0
    assert notifications == [1, 4, 2, 0]
    assert d.reverse_lookup('c') == []
    assert d.casereverse_lookup('c') == []

    d.remove_longest_key_listener(listener)
    d[('S', 'S')] = 'c'
    assert d.longest_key == 2
    assert notifications == [1, 4, 2, 0]