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