import unittest
import pylev


class ClassicLevenshteinTestCase(unittest.TestCase):
    def test_classic(self):
        self.assertEqual(pylev.classic_levenshtein('kitten', 'sitting'), 3)

    def test_same(self):
        self.assertEqual(pylev.classic_levenshtein('kitten', 'kitten'), 0)

    def test_empty(self):
        self.assertEqual(pylev.classic_levenshtein('', ''), 0)

    def test_long(self):
        self.assertEqual(pylev.classic_levenshtein('confide', 'deceit'), 6)

    def test_painful(self):
        # This is pretty slow but should work.
        self.assertEqual(pylev.classic_levenshtein('CUNsperrICY', 'conspiracy'), 8)


class LevenshteinTestCase(unittest.TestCase):
    def test_classic(self):
        self.assertEqual(pylev.levenshtein('kitten', 'sitting'), 3)

    def test_same(self):
        self.assertEqual(pylev.levenshtein('kitten', 'kitten'), 0)

    def test_empty(self):
        self.assertEqual(pylev.levenshtein('', ''), 0)

    def test_long(self):
        self.assertEqual(pylev.levenshtein('confide', 'deceit'), 6)

    def test_painful(self):
        # This is much faster than the above.
        self.assertEqual(pylev.levenshtein('CUNsperrICY', 'conspiracy'), 8)

import itertools
import unittest
import pylev

test_data = [
    ('classic', "kitten", "sitting", 3),
    ('same', "kitten", "kitten", 0),
    ('empty', "", "", 0),
    ('a', "meilenstein", "levenshtein", 4),
    ('b', "levenshtein", "frankenstein", 6),
    ('c', "confide", "deceit", 6),
    ('d', "CUNsperrICY", "conspiracy", 8),
]

test_functions = [
    # pylev.classic_levenshtein,   # disabled because it is so slow
    pylev.recursive_levenshtein,
    pylev.wf_levenshtein,
    pylev.wfi_levenshtein
]

class Tests(unittest.TestCase):

    pass


def mk_test_fn(fn, a, b, expected):
    return lambda self: self.assertEqual(fn(a, b), expected)


for lev_fn, data in itertools.product(test_functions, test_data):
    name, a, b, expected = data
    test_fn = mk_test_fn(lev_fn, a, b, expected)
    setattr(Tests, "test_%s_%s" % (name, lev_fn.__name__), test_fn)

make generated test suite