コード例 #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'