示例#1
0
def test_items():
    h = hashmap.HashMap()
    list = range(10)
    for i in list:
        h.add(i, i)

    for k, v in h.items():
        assert k == v and k == list[k]
示例#2
0
def test_keys():
    h = hashmap.HashMap()
    list = range(10)
    for i in list:
        h.add(i, None)

    for key in h.keys():
        assert key == list[key]
示例#3
0
def test_remove():
    h = hashmap.HashMap()
    h.add('john', 'Google')
    assert h.size() == 1

    assert h.remove('john') == 'Google'
    assert h.size() == 0
    h.get('john')
示例#4
0
def test_itervalues():
    h = hashmap.HashMap()
    list = range(10)
    for i in list:
        h.add(i, i)

    for value in h.itervalues():
        assert value == list[value]
示例#5
0
def test_get():
    h = hashmap.HashMap()

    h.add('john', 'Google')
    assert h.get('john') == 'Google'

    h.add('john', 'Facebook')
    assert h.get('john') == 'Facebook'
    assert not h.get('john') == 'Google'
示例#6
0
def test_add_with_resize():
    h = hashmap.HashMap(3)
    h.add('john', 'Google')
    h.add('jane', 'Amazon')
    h.add('victor', 12345)
    h.add('mark', 'Facebook')

    assert h.get('john') == 'Google'
    assert h.get('jane') == 'Amazon'
    assert h.get('mark') == 'Facebook'
    assert h.get('victor') == 12345
示例#7
0
def test_size():
    h = hashmap.HashMap()

    assert h.size() == 0
    h.add('john', 'Google')
    h.add('jane', 'Amazon')
    h.add('victor', 12345)
    h.add('mark', 'Facebook')
    h.add('bill', 'Microsoft')
    h.add('elon', ('tesla', 'spacex'))
    assert h.size() == 6

    assert h.remove('elon') == ('tesla', 'spacex')
    assert h.remove('victor') == 12345
    assert h.size() == 4
示例#8
0
def test_get_fail():
    h = hashmap.HashMap()
    h.get('john')
示例#9
0
def test_remove2():
    h = hashmap.HashMap(2)
    h.add('john', 'Google')

    h.remove('jim')
示例#10
0
def test_add():
    h = hashmap.HashMap()
    h.add('john', 'Google')
    assert h.get('john') == 'Google'
示例#11
0
def test_negative_capacity():
    h = hashmap.HashMap(-10)
    assert h.size() == 0

    h.add('john', 'Google')
    assert h.get('john') == 'Google'