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 Tests for centroid computation.
12 from nominatim_db.utils.centroid import PointsCentroid
17 with pytest.raises(ValueError, match='No points'):
21 @pytest.mark.parametrize("centroid", [(0,0), (-1, 3), [0.0000032, 88.4938]])
22 def test_one_point_centroid(centroid):
27 assert len(c.centroid()) == 2
28 assert c.centroid() == (pytest.approx(centroid[0]), pytest.approx(centroid[1]))
31 def test_multipoint_centroid():
35 assert c.centroid() == (pytest.approx(20.0), pytest.approx(-10.0))
37 assert c.centroid() == (pytest.approx(20.1), pytest.approx(-9.5))
39 assert c.centroid() == (pytest.approx(20.13333), pytest.approx(-9.333333))
42 def test_manypoint_centroid():
45 for _ in range(10000):
46 c += (4.564732, -0.000034)
48 assert c.centroid() == (pytest.approx(4.564732), pytest.approx(-0.000034))
51 @pytest.mark.parametrize("param", ["aa", None, 5, [1, 2, 3], (3, None), ("a", 3.9)])
52 def test_add_non_tuple(param):
55 with pytest.raises(ValueError, match='2-element tuples'):