Skip to content

Commit 53ce0fb

Browse files
authored
Merge pull request #49 from UBC-MDS/16-additional_tests
16 additional tests
2 parents 61fc353 + f8fe2e7 commit 53ce0fb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pydistrrr/get_all_distances.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_all_distances(point, data, metric = "euclidean"):
2929
Returns
3030
-------
3131
list
32-
numeric vector of length n containing distances for each row of data
32+
numeric list of length n containing distances for each row of data
3333
3434
Example
3535
-------
@@ -47,6 +47,11 @@ def get_all_distances(point, data, metric = "euclidean"):
4747
if not isinstance(point, list):
4848
raise Exception("the point argument should be type list")
4949

50+
# raise error if point isn't all numeric
51+
for obs in point:
52+
if not isinstance(obs, int) and not isinstance(obs, float):
53+
raise Exception("point argument should be a list containing only type float or int")
54+
5055
# number of observations in data frame
5156
n = data.shape[0]
5257
k = data.shape[1]

pydistrrr/test/test_get_all_distances.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ def test_point_correct_length():
9292

9393
def test_metric_input():
9494
"""
95-
dist should be a string and one of 'cosine', 'euclidean' or 'manhattan'
95+
metric should be a string and one of 'cosine', 'euclidean' or 'manhattan'
9696
"""
9797
try:
9898
get_all_distances(ref_vec,df, metric = "cityblock")
9999
except:
100100
assert True
101+
102+
def test_point_types():
103+
"""
104+
Test for error if input 'point' contains items other than numerics
105+
"""
106+
try:
107+
get_all_distances(["a","b","c"],df)
108+
except:
109+
assert True

0 commit comments

Comments
 (0)