def test_nearest_neighbor(self): threshold = 1e-5 metric = "euclidean" x = np.array([[1, 1], [4, 4], [5, 4]]) pri = Privacy() nn_dist = pri.nearest_neighbors(arr1=x, metric=metric) assert abs(nn_dist[0] - pri.distance(x[0, :], x[1, :], metric)) < threshold
def test_distance_euclidean(self): pri = Privacy() metric = 'euclidean' a = np.array([[1, 1]]) b = np.array([[2, 1]]) d = pri.distance(arr1=a, arr2=b, metric=metric) assert d == 1
def test_distance_hamming(self): pri = Privacy() metric = 'hamming' a = np.array([[1, 1]]) b = np.array([[1, 1]]) d = pri.distance(arr1=a, arr2=b, metric=metric) assert d == 0