コード例 #1
0
    def test_sorted_iterable(self):

        sorted_data = ['bar', 'foo', 'foobar']
        d = simtrie.Set(sorted_data, sorted=True)

        assert 'bar' in d
        assert 'foo' in d
コード例 #2
0
    def test_unicode_sorting(self):
        key1 = '\uff72\uff9c\uff90\uff7b\uff9e\uff9c'
        key2 = '\U00010345\U0001033f\U00010337\U00010330\U0001033d'

        # This apparently depends on Python version:
        # assert key1 < key2
        assert key1.encode('utf8') < key2.encode('utf8')

        # Constructor should sort data according to utf8 values,
        # not according to unicode sorting rules. It will raise an exception
        # if data is sorted according to unicode rules.
        simtrie.Set([key1, key2], sorted=True)
コード例 #3
0
 def test_contains_with_null_bytes(self):
     d = simtrie.Set(['foo'])
     assert b'foo' in d
     assert b'foo\x00bar' not in d
コード例 #4
0
 def test_build_errors(self):
     with pytest.raises(ValueError):
         data = [b'foo\x00bar', b'bar']
         simtrie.Set(data)
コード例 #5
0
 def test_no_segfaults_after_wrong_stream(self):
     d = simtrie.Set()
     assert 'random-key' not in d
コード例 #6
0
    def test_no_segfaults_on_invalid_file(self):
        d = simtrie.Set()

        with pytest.raises(IOError) as e:
            d.frombytes(b"foo")
コード例 #7
0
def _dam_lev(a, b, metric=None):
    s = simtrie.Set([a])
    for k, cost in s.similar(b, MAX_COST, metric=metric, allow_transpose=True):
        assert k == a
        return cost
コード例 #8
0
def _lev(a, b, metric):
    s = simtrie.Set([a])
    for k, cost in s.similar(b, MAX_COST, metric):
        assert k == a
        return cost
コード例 #9
0
 def get_cost(a, b):
     s = simtrie.Set([a])
     for k, cost in s.similar(b, 10):
         assert k == a
         return cost
コード例 #10
0
 def test_no_segfaults_on_empty_dawg(self):
     d = simtrie.Set([])
     assert list(d.keys()) == []
コード例 #11
0
 def empty_dawg(self):
     return simtrie.Set()
コード例 #12
0
 def dawg(self):
     return simtrie.Set(self.keys)