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 centroid computation.
 
  12 from nominatim_db.utils.centroid import PointsCentroid
 
  18     with pytest.raises(ValueError, match='No points'):
 
  22 @pytest.mark.parametrize("centroid", [(0, 0), (-1, 3), [0.0000032, 88.4938]])
 
  23 def test_one_point_centroid(centroid):
 
  28     assert len(c.centroid()) == 2
 
  29     assert c.centroid() == (pytest.approx(centroid[0]), pytest.approx(centroid[1]))
 
  32 def test_multipoint_centroid():
 
  36     assert c.centroid() == (pytest.approx(20.0), pytest.approx(-10.0))
 
  38     assert c.centroid() == (pytest.approx(20.1), pytest.approx(-9.5))
 
  40     assert c.centroid() == (pytest.approx(20.13333), pytest.approx(-9.333333))
 
  43 def test_manypoint_centroid():
 
  46     for _ in range(10000):
 
  47         c += (4.564732, -0.000034)
 
  49     assert c.centroid() == (pytest.approx(4.564732), pytest.approx(-0.000034))
 
  52 @pytest.mark.parametrize("param", ["aa", None, 5, [1, 2, 3], (3, None), ("a", 3.9)])
 
  53 def test_add_non_tuple(param):
 
  56     with pytest.raises(ValueError, match='2-element tuples'):