fog/test/clustering/sorted_neighborhood_test.py

39 lines
1009 B
Python
Raw Normal View History

2018-07-06 16:05:19 +00:00
# =============================================================================
# Fog Sorted Neighborhood Unit Tests
# =============================================================================
import csv
from test.clustering.utils import Clusters
from Levenshtein import distance as levenshtein
2018-07-31 14:07:54 +00:00
from fog.clustering import sorted_neighborhood, adaptive_sorted_neighborhood
2018-07-06 16:05:19 +00:00
DATA = [
2018-07-31 14:08:47 +00:00
'Belgian',
2018-07-06 16:05:19 +00:00
'Abelard',
'Atrium',
'Atrides',
2018-07-31 14:08:47 +00:00
'Abelar',
2018-07-06 16:05:19 +00:00
'Belgia',
'Telgia'
]
CLUSTERS = Clusters([
('Abelard', 'Abelar'),
('Belgian', 'Belgia')
])
class TestSortedNeighborhood(object):
def test_basics(self):
# Sorting alphabetically
2018-07-06 16:07:01 +00:00
clusters = Clusters(sorted_neighborhood(DATA, distance=levenshtein, radius=1, window=2))
2018-07-06 16:05:19 +00:00
assert clusters == CLUSTERS
2018-07-31 14:07:54 +00:00
def test_adaptive(self):
# Sorting alphabetically
clusters = Clusters(adaptive_sorted_neighborhood(DATA, distance=levenshtein, radius=1, window=2))
assert clusters == CLUSTERS