def test_haversine_decomposition(): # Distancia a-->c <= a-->b + b-->c (metric='haversine') p_a = [1, 1] p_b = [2, 2] p_c = [1, 2] dist_ab = distances.haversine(np.array(p_a), np.array([p_b]), 2) dist_ac = distances.haversine(np.array(p_a), np.array([p_c]), 2) dist_bc = distances.haversine(np.array(p_b), np.array([p_c]), 2) assert dist_ac <= dist_ab + dist_bc
def test_haversine_simetric(): # Distancia a-->b = b-->a (metric='haversine') dist1 = distances.haversine(c0=np.array([1, 1]), centres=np.array([[2, 2]]), dim=2) dist2 = distances.haversine(c0=np.array([2, 2]), centres=np.array([[1, 1]]), dim=2) np.testing.assert_almost_equal(dist1, dist2, decimal=10)
def test_haversine_not_nan(): # Distancias != NaN (metric='haversine') random = np.random.RandomState(42) data = random.uniform(-10, 10, size=(10, 2)) centre_0 = random.uniform(-10, 10, size=(2, )) dist = distances.haversine(centre_0, data, 2) assert not np.isnan(dist).any()
def test_haversine_gt0(): # Distancias >= 0 (metric='haversine') random = np.random.RandomState(42) data = random.uniform(-10, 10, size=(10, 2)) centre_0 = random.uniform(-10, 10, size=(2, )) dist = distances.haversine(centre_0, data, 2) assert (dist >= 0).all()