コード例 #1
0
def test():
    comparable = TreeMap()
    with pytest.raises(TypeError):
        comparable.put(None, 'anything')
    comparable.put('test', 'anything')
    with pytest.raises(TypeError):
        comparable.put(None, 'anything')

    def case_insensitive_order(a, b):
        x, y = a.lower(), b.lower()
        if x < y:
            return -1
        elif x > y:
            return 1
        else:
            return 0

    comparator = TreeMap(case_insensitive_order)
    with pytest.raises(Exception):
        comparator.put(None, 'anything')
    comparator.put('test', 'anything')
    with pytest.raises(Exception):
        comparator.put(None, 'anything')
    comparator.clear()
    with pytest.raises(Exception):
        comparator.put(object(), 'anything')
コード例 #2
0
ファイル: test_moat.py プロジェクト: scp114514810/pytreemap
    def test_main(self):
        m = TreeMap()
        self.test_navigable_map_removers(m)
        self.test_navigable_map(m)
        self.test_navigable_map(m.head_map(6, False))
        self.test_navigable_map(m.head_map(5, True))
        self.test_navigable_map(m.tail_map(0, False))
        self.test_navigable_map(m.tail_map(1, True))
        self.test_navigable_map(m.sub_map(1, 6, True, False))
        self.test_navigable_map(m.sub_map(0, 5, False, True))

        self.check_functional_invariants(m)

        m.clear()

        assert m.put(3333, 77777) is None
        assert m.put(9134, 74982) is None
        assert m.get(9134) == 74982
        assert m.put(9134, 1382) == 74982
        assert m.get(9134) == 1382
        assert m.size() == 2
        self.check_functional_invariants(m)