Skip to content

Commit dfbca02

Browse files
committed
Improved test method naming
1 parent 317bf09 commit dfbca02

File tree

12 files changed

+96
-108
lines changed

12 files changed

+96
-108
lines changed

tests/test_bench_cover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def run(X, r, dist, vp, **kwargs):
4141

4242
class TestVpSettings(unittest.TestCase):
4343

44-
def testCoverRandom(self):
44+
def test_cover_random(self):
4545
for r in [1.0, 10.0, 100.0]:
4646
for n in [100, 1000, 10000]:
4747
print(f'============= n: {n}, r: {r} =============')
@@ -57,7 +57,7 @@ def testCoverRandom(self):
5757
run(X, r, dist, SkBallTree, leaf_radius=r)
5858
print('')
5959

60-
def testCoverDigits(self):
60+
def test_cover_digits(self):
6161
X, _ = load_digits(return_X_y=True)
6262
#X = PCA(n_components=3).fit_transform(X)
6363
for r in [1.0, 10.0, 100.0]:

tests/test_core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def dataset(dim=10, num=1000):
1818

1919
class TestMapper(unittest.TestCase):
2020

21-
def testTrivial(self):
21+
def test_trivial(self):
2222
data = dataset()
2323
mp = MapperAlgorithm(TrivialCover(), TrivialClustering())
2424
g = mp.fit_transform(data, data)
@@ -29,7 +29,7 @@ def testTrivial(self):
2929
ccs2 = mapper_connected_components(data, data, TrivialCover(), TrivialClustering())
3030
self.assertEqual(len(data), len(ccs2))
3131

32-
def testBallSmallRadius(self):
32+
def test_ball_small_radius(self):
3333
data = np.array([[float(i)] for i in range(1000)])
3434
cover = BallCover(0.5, metric=dist)
3535
clustering = TrivialClustering()
@@ -43,7 +43,7 @@ def testBallSmallRadius(self):
4343
ccs2 = mapper_connected_components(data, data, cover, clustering)
4444
self.assertEqual(len(data), len(ccs2))
4545

46-
def testBallSmallRadiusList(self):
46+
def test_ball_small_radius_list(self):
4747
data = [np.array([float(i)]) for i in range(1000)]
4848
cover = BallCover(0.5, metric=dist)
4949
clustering = DBSCAN(eps=1.0, min_samples=1)
@@ -59,7 +59,7 @@ def testBallSmallRadiusList(self):
5959
ccs2 = mapper_connected_components(data, data, cover, clustering)
6060
self.assertEqual(len(data), len(ccs2))
6161

62-
def testBallLargeRadius(self):
62+
def test_ball_large_radius(self):
6363
data = np.array([[float(i)] for i in range(1000)])
6464
cover = BallCover(1000.0, metric=dist)
6565
clustering = TrivialClustering()
@@ -75,7 +75,7 @@ def testBallLargeRadius(self):
7575
ccs2 = mapper_connected_components(data, data, cover, clustering)
7676
self.assertEqual(len(data), len(ccs2))
7777

78-
def testTwoDisconnectedClusters(self):
78+
def test_two_disconnected_clusters(self):
7979
data = [np.array([float(i), 0.0]) for i in range(100)]
8080
data.extend([np.array([float(i), 500.0]) for i in range(100)])
8181
data = np.array(data)
@@ -93,7 +93,7 @@ def testTwoDisconnectedClusters(self):
9393
ccs2 = mapper_connected_components(data, data, cover, clustering)
9494
self.assertEqual(len(data), len(ccs2))
9595

96-
def testTwoConnectedClusters(self):
96+
def test_two_connected_clusters(self):
9797
data = [
9898
np.array([0.0, 1.0]), np.array([1.0, 0.0]),
9999
np.array([0.0, 0.0]), np.array([1.0, 1.0])]
@@ -111,7 +111,7 @@ def testTwoConnectedClusters(self):
111111
ccs2 = mapper_connected_components(data, data, cover, clustering)
112112
self.assertEqual(len(data), len(ccs2))
113113

114-
def testCCS(self):
114+
def test_connected_components(self):
115115
data = [0, 1, 2, 3]
116116

117117
class MockCover:
@@ -131,7 +131,7 @@ def apply(self, X):
131131
self.assertEqual(cc0, ccs[2])
132132
self.assertEqual(cc0, ccs[3])
133133

134-
def testLabels(self):
134+
def test_labels(self):
135135
data = [0, 1, 2, 3]
136136

137137
class MockCover:

tests/test_cover.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,35 @@
1010
)
1111

1212

13-
def dist(x, y):
14-
return np.linalg.norm(x - y)
15-
16-
1713
def dataset(dim=1, num=10000):
1814
return [np.random.rand(dim) for _ in range(num)]
1915

2016

2117
class TestCover(unittest.TestCase):
2218

23-
def testTrivialCover(self):
19+
def test_trivial_cover(self):
2420
data = dataset()
2521
cover = TrivialCover()
2622
charts = list(cover.apply(data))
2723
self.assertEqual(1, len(charts))
2824

29-
def testBallCoverSimple(self):
25+
def test_ball_cover_simple(self):
3026
data = [
3127
np.array([0.0, 1.0]), np.array([1.0, 0.0]),
3228
np.array([0.0, 0.0]), np.array([1.0, 1.0])]
33-
cover = BallCover(radius=1.1, metric=dist)
29+
cover = BallCover(radius=1.1, metric='euclidean')
3430
charts = list(cover.apply(data))
3531
self.assertEqual(2, len(charts))
3632

37-
def testKNNCoverSimple(self):
33+
def test_knn_cover_simple(self):
3834
data = [
3935
np.array([0.0, 1.0]), np.array([1.1, 0.0]),
4036
np.array([0.0, 0.0]), np.array([1.1, 1.0])]
41-
cover = KNNCover(neighbors=2, metric=dist)
37+
cover = KNNCover(neighbors=2, metric='euclidean')
4238
charts = list(cover.apply(data))
4339
self.assertEqual(2, len(charts))
4440

45-
def testCubicalCoverSimple(self):
41+
def test_cubical_cover_simple(self):
4642
data = [
4743
np.array([0.0, 1.0]), np.array([1.1, 0.0]),
4844
np.array([0.0, 0.0]), np.array([1.1, 1.0])]

tests/test_heap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ def maxheap(data):
1313

1414
class TestMaxHeap(unittest.TestCase):
1515

16-
def testEmpty(self):
16+
def test_empty(self):
1717
m = MaxHeap()
1818
self.assertEqual(0, len(m))
1919

20-
def testMax(self):
20+
def test_max(self):
2121
data = list(range(10))
2222
random.shuffle(data)
2323
m = maxheap(data)
2424
self.assertEqual((9, 9), m.top())
2525
self.assertEqual(10, len(m))
2626

27-
def testMaxRandom(self):
27+
def test_max_random(self):
2828
data = random.sample(list(range(1000)), 100)
2929
m = maxheap(data)
3030
self.assertEqual(100, len(m))

tests/test_knn.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33

44
from tdamapper.proximity import KNNProximity
5+
from tdamapper.utils.metrics import euclidean
56
from tdamapper.utils.vptree_flat import VPTree
67

78

@@ -92,34 +93,33 @@
9293
x = np.array([ 99.73199663, 100.8024564 ])
9394

9495

95-
def euclidean(x, y):
96-
return np.linalg.norm(x - y)
97-
98-
9996
class TestKNN(unittest.TestCase):
10097

101-
def testKNNSearch(self):
102-
knn_prox = KNNProximity(neighbors=5, metric=euclidean)
98+
def test_knn_search(self):
99+
knn_prox = KNNProximity(neighbors=5, metric='euclidean')
103100
knn_prox.fit(X)
104101
neigh_ids = knn_prox.search(x)
105-
dists = [euclidean(x, X[j]) for j in neigh_ids]
106-
x_dist = euclidean(x, X[5])
102+
d = euclidean()
103+
dists = [d(x, X[j]) for j in neigh_ids]
104+
x_dist = d(x, X[5])
107105
self.assertTrue(x_dist in dists)
108106

109-
def testVPTree(self):
110-
vptree = VPTree(X[:80], metric=euclidean, leaf_capacity=5)
107+
def test_vptree(self):
108+
vptree = VPTree(X[:80], metric='euclidean', leaf_capacity=5)
111109
neigh = vptree.knn_search(x, 5)
112-
dists = [euclidean(x, y) for y in neigh]
113-
x_dist = euclidean(x, X[5])
110+
d = euclidean()
111+
dists = [d(x, y) for y in neigh]
112+
x_dist = d(x, X[5])
114113
self.check_vptree(vptree)
115114
self.assertTrue(x_dist in dists)
116115

117-
def testVPTreeSimple(self):
116+
def test_vptree_simple(self):
118117
XX = np.array([np.array([x, x/2]) for x in range(30)])
119-
vptree = VPTree(XX, metric=euclidean, leaf_capacity=5, leaf_radius=0.0)
118+
vptree = VPTree(XX, metric='euclidean', leaf_capacity=5, leaf_radius=0.0)
120119
xx = np.array([3, 3/2])
121120
neigh = vptree.knn_search(xx, 2)
122-
dists = [euclidean(xx, y) for y in neigh]
121+
d = euclidean()
122+
dists = [d(xx, y) for y in neigh]
123123
self.check_vptree(vptree)
124124
self.assertTrue(0.0 in dists)
125125

@@ -138,7 +138,7 @@ def check_sub(start, end):
138138
_, y = data[i]
139139
self.assertTrue(dist(v_point, y) >= v_radius)
140140
def check_rec(start, end):
141-
v_radius, v_point = data[start]
141+
v_radius, _ = data[start]
142142
if (end - start > leaf_capacity) and (v_radius > leaf_radius):
143143
check_sub(start, end)
144144
mid = (start + end) // 2

tests/test_plot.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@
88
from tdamapper.plot import MapperLayoutInteractive, MapperLayoutStatic
99

1010

11-
def dist(x, y):
12-
return np.linalg.norm(x - y)
13-
14-
1511
class TestMapperPlot(unittest.TestCase):
1612

17-
def testTwoConnectedClusters(self):
13+
def test_two_connected_clusters(self):
1814
data = [
1915
np.array([0.0, 1.0]), np.array([1.0, 0.0]),
2016
np.array([0.0, 0.0]), np.array([1.0, 1.0])]
21-
mp = MapperAlgorithm(cover=BallCover(1.1, metric=dist),
17+
mp = MapperAlgorithm(cover=BallCover(1.1, metric='euclidean'),
2218
clustering=TrivialClustering())
2319
g = mp.fit_transform(data, data)
2420
mp_plot1 = MapperLayoutInteractive(g, dim=2,

tests/test_proximity.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010
)
1111

1212

13-
def dist(x, y):
14-
return np.linalg.norm(x - y)
15-
16-
1713
def dataset(dim=1, num=10000):
1814
return [np.random.rand(dim) for _ in range(num)]
1915

2016

2117
class TestProximity(unittest.TestCase):
2218

23-
def testBallProximity(self):
19+
def test_ball_proximity(self):
2420
data = list(range(100))
2521
prox = BallProximity(radius=10, metric=lambda x,y: abs(x - y))
2622
prox.fit(data)
@@ -29,7 +25,7 @@ def testBallProximity(self):
2925
expected = [y for y in data if abs(x - y) <= 10]
3026
self.assertEqual(len(expected), len(result))
3127

32-
def testKNNProximity(self):
28+
def test_knn_proximity(self):
3329
data = list(range(100))
3430
prox = KNNProximity(neighbors=11, metric=lambda x,y: abs(x - y))
3531
prox.fit(data)
@@ -38,7 +34,7 @@ def testKNNProximity(self):
3834
expected = [x + i for i in range(-5, 6)]
3935
self.assertEqual(set(expected), set(result))
4036

41-
def testCubicalProximity(self):
37+
def test_cubical_proximity(self):
4238
m, M = 0, 99
4339
n = 10
4440
p = 0.1

tests/test_readme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
class TestReadme(unittest.TestCase):
55

6-
def testRun(self):
6+
def test_run(self):
77
import tests.example

tests/test_sklearn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ def get_clustering(self):
9797

9898
class TestSklearn(unittest.TestCase):
9999

100-
def testClustering(self):
100+
def test_clustering(self):
101101
check_estimator(TrivialClusteringEstimator())
102102

103-
def testBall(self):
103+
def test_ball(self):
104104
check_estimator(MapperClusteringEstimator(cover='ball'))
105105

106-
def testKNN(self):
106+
def test_knn(self):
107107
check_estimator(MapperClusteringEstimator(cover='knn'))
108108

109-
def testCubical(self):
109+
def test_cubical(self):
110110
check_estimator(MapperClusteringEstimator())
111111

112-
def testPermissive(self):
112+
def test_permissive(self):
113113
check_estimator(PermissiveKMeans())

tests/test_unionfind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class TestUnionFind(unittest.TestCase):
77

8-
def testList(self):
8+
def test_list(self):
99
data = [1, 2, 3, 4]
1010
uf = UnionFind(data)
1111
for i in data:

0 commit comments

Comments
 (0)