[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/develop] Add unittests for bridgedb.util.levenshteinDistance().



commit 387115d8aa4be39da059deb793916defad6f1d0a
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Mon Jul 7 12:16:15 2014 +0000

    Add unittests for bridgedb.util.levenshteinDistance().
---
 lib/bridgedb/test/test_util.py |   42 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/lib/bridgedb/test/test_util.py b/lib/bridgedb/test/test_util.py
index a18e1c6..065c401 100644
--- a/lib/bridgedb/test/test_util.py
+++ b/lib/bridgedb/test/test_util.py
@@ -17,6 +17,7 @@ from __future__ import unicode_literals
 
 import os
 
+from twisted.mail.smtp import Address
 from twisted.trial import unittest
 
 from bridgedb import util
@@ -58,3 +59,44 @@ class MiscLoggingUtilTests(unittest.TestCase):
         from bridgedb.persistent import Conf
         util.configureLogging(Conf())
         util.logging.info("BridgeDB's email address: bridges@xxxxxxxxxxxxxx")
+
+
+class LevenshteinDistanceTests(unittest.TestCase):
+    """Unittests for `bridgedb.util.levenshteinDistance."""
+
+    def test_levenshteinDistance_blank_blank(self):
+        """The Levenshtein Distance between '' and '' should be 0."""
+        distance = util.levenshteinDistance('', '')
+        self.assertEqual(distance, 0)
+
+    def test_levenshteinDistance_cat_cat(self):
+        """The Levenshtein Distance between 'cat' and 'cat' should be 0."""
+        distance = util.levenshteinDistance('cat', 'cat')
+        self.assertEqual(distance, 0)
+
+    def test_levenshteinDistance_bat_cat(self):
+        """The Levenshtein Distance between 'bat' and 'cat' should be 1."""
+        distance = util.levenshteinDistance('bat', 'cat')
+        self.assertEqual(distance, 1)
+
+    def test_levenshteinDistance_bar_cat(self):
+        """The Levenshtein Distance between 'bar' and 'cat' should be 2."""
+        distance = util.levenshteinDistance('bar', 'cat')
+        self.assertEqual(distance, 2)
+
+    def test_levenshteinDistance_bridgedb_doge(self):
+        """The Levenshtein Distance between 'bridgedb' and 'doge' should be 6."""
+        distance = util.levenshteinDistance('bridgedb', 'doge')
+        self.assertEqual(distance, 6)
+
+    def test_levenshteinDistance_feidanchaoren0043_feidanchaoren0011(self):
+        """The Levenshtein Distance between the usernames in
+        'feidanchaoren0043@xxxxxxxxx' and 'feidanchaoren0011@xxxxxxxxx' should
+        be less than an EMAIL_FUZZY_MATCH parameter.
+        """
+        email1 = Address('feidanchaoren0043@xxxxxxxxx')
+        email2 = Address('feidanchaoren0011@xxxxxxxxx')
+        # Fuzzy match if the Levenshtein Distance is less than or equal to:
+        fuzzyMatch = 4
+        distance = util.levenshteinDistance(email1.local, email2.local)
+        self.assertLessEqual(distance, fuzzyMatch)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits