1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Test data types for search queries.
12 import nominatim_api.search.query as nq
14 def test_token_range_equal():
15 assert nq.TokenRange(2, 3) == nq.TokenRange(2, 3)
16 assert not (nq.TokenRange(2, 3) != nq.TokenRange(2, 3))
19 @pytest.mark.parametrize('lop,rop', [((1, 2), (3, 4)),
21 ((10, 12), (11, 12))])
22 def test_token_range_unequal(lop, rop):
23 assert not (nq.TokenRange(*lop) == nq.TokenRange(*rop))
24 assert nq.TokenRange(*lop) != nq.TokenRange(*rop)
27 def test_token_range_lt():
28 assert nq.TokenRange(1, 3) < nq.TokenRange(10, 12)
29 assert nq.TokenRange(5, 6) < nq.TokenRange(7, 8)
30 assert nq.TokenRange(1, 4) < nq.TokenRange(4, 5)
31 assert not(nq.TokenRange(5, 6) < nq.TokenRange(5, 6))
32 assert not(nq.TokenRange(10, 11) < nq.TokenRange(4, 5))
35 def test_token_rankge_gt():
36 assert nq.TokenRange(3, 4) > nq.TokenRange(1, 2)
37 assert nq.TokenRange(100, 200) > nq.TokenRange(10, 11)
38 assert nq.TokenRange(10, 11) > nq.TokenRange(4, 10)
39 assert not(nq.TokenRange(5, 6) > nq.TokenRange(5, 6))
40 assert not(nq.TokenRange(1, 2) > nq.TokenRange(3, 4))
41 assert not(nq.TokenRange(4, 10) > nq.TokenRange(3, 5))
44 def test_token_range_unimplemented_ops():
45 with pytest.raises(TypeError):
46 nq.TokenRange(1, 3) <= nq.TokenRange(10, 12)
47 with pytest.raises(TypeError):
48 nq.TokenRange(1, 3) >= nq.TokenRange(10, 12)