Beispiel #1
0
def test_map():
    map = TreeMap()
    for each in range(TEST_SIZE):
        map.put(KEYS[each], VALUES[each])
    keys = map.key_set().to_list()
    keys.sort()
    for each in range(TEST_SIZE):
        assert keys[each] == KEYS[each]
    values = map.values().to_list()
    values.sort()
    for each in range(TEST_SIZE):
        assert values[each] == VALUES[each]
    entries = map.entry_set().to_list()
    entries.sort(key=lambda e: e.get_key())
    for each in range(TEST_SIZE):
        assert (entries[each].get_key() == KEYS[each]
                and entries[each].get_value() == VALUES[each])
Beispiel #2
0
def test():
    m1 = TreeMap(none_at_end)
    assert m1.put('a', 'a') is None
    assert m1.put('b', 'b') is None
    assert m1.put('c', 'c') is None
    assert m1.put(None, 'd') is None

    m2 = TreeMap(none_at_end)
    m2.put_all(m1)

    assert m1.last_key() is None
    assert m1.get(m1.last_key()) == 'd'
    assert m1.remove(m1.last_key()) == 'd'
    assert m1.last_key() == 'c'

    assert m2.entry_set().to_string() == '[a=a, b=b, c=c, None=d]'

    m3 = m2.tail_map('b')

    assert m3.last_key() is None
    assert m3.get(m3.last_key()) == 'd'
    assert m3.remove(m3.last_key()) == 'd'
    assert m3.last_key() == 'c'
Beispiel #3
0
#!/usr/bin/env python
import pytest
from pytreemap import TreeMap

__author__ = 'Haoran Peng'
__email__ = '*****@*****.**'
__license__ = 'GPL-2.0'

m = TreeMap()
for i in range(18):
    m.put(i, i)


@pytest.mark.parametrize('c', [m.values(), m.key_set(), m.entry_set()])
def test(c):
    it = iter(c)
    with pytest.raises(StopIteration):
        while True:
            next(it)