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
14 def test_single_item_trie():
15 t = SimpleTrie([('foob', 42)])
17 assert t.longest_prefix('afoobar') == (None, 0)
18 assert t.longest_prefix('afoobar', start=1) == (42, 5)
19 assert t.longest_prefix('foob') == (42, 4)
20 assert t.longest_prefix('123foofoo', 3) == (None, 3)
23 def test_complex_item_tree():
24 t = SimpleTrie([('a', 1),
32 assert t.longest_prefix('a') == (1, 1)
33 assert t.longest_prefix('au') == (1, 1)
34 assert t.longest_prefix('aut') == (1, 1)
35 assert t.longest_prefix('auto') == (3, 4)
36 assert t.longest_prefix('automat') == (5, 7)
37 assert t.longest_prefix('automatx') == (5, 7)
38 assert t.longest_prefix('butomat') == (4, 4)
39 assert t.longest_prefix('butomat', 1) == (None, 1)