1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for simplified trie structure.
11 from nominatim_db.tokenizer.token_analysis.simple_trie import SimpleTrie
13 def test_single_item_trie():
14 t = SimpleTrie([('foob', 42)])
16 assert t.longest_prefix('afoobar') == (None, 0)
17 assert t.longest_prefix('afoobar', start=1) == (42, 5)
18 assert t.longest_prefix('foob') == (42, 4)
19 assert t.longest_prefix('123foofoo', 3) == (None, 3)
21 def test_complex_item_tree():
22 t = SimpleTrie([('a', 1),
30 assert t.longest_prefix('a') == (1, 1)
31 assert t.longest_prefix('au') == (1, 1)
32 assert t.longest_prefix('aut') == (1, 1)
33 assert t.longest_prefix('auto') == (3, 4)
34 assert t.longest_prefix('automat') == (5, 7)
35 assert t.longest_prefix('automatx') == (5, 7)
36 assert t.longest_prefix('butomat') == (4, 4)
37 assert t.longest_prefix('butomat', 1) == (None, 1)