1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
# Copyright 2019-2020 by Christopher C. Little.
# This file is part of Abydos.
#
# Abydos is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Abydos is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Abydos. If not, see <http://www.gnu.org/licenses/>.
"""abydos.tests.distance.test_distance_ncd_lzss.
This module contains unit tests for abydos.distance.NCDlzss
"""
import unittest
from abydos.distance import NCDlzss
class NCDlzssTestCases(unittest.TestCase):
"""Test NCDlzss functions.
abydos.distance.NCDlzss
"""
cmp = NCDlzss()
def test_ncd_lzss_dist(self):
"""Test abydos.distance.NCDlzss.dist."""
try:
import lzss # noqa: F401
except ImportError: # pragma: no cover
return
# Base cases
self.assertEqual(self.cmp.dist('', ''), 0.0)
self.assertEqual(self.cmp.dist('a', ''), 1.0)
self.assertEqual(self.cmp.dist('', 'a'), 1.0)
self.assertEqual(self.cmp.dist('abc', ''), 1.0)
self.assertEqual(self.cmp.dist('', 'abc'), 1.0)
self.assertEqual(self.cmp.dist('abc', 'abc'), 0.0)
self.assertEqual(self.cmp.dist('abcd', 'efgh'), 0.8)
self.assertAlmostEqual(self.cmp.dist('Nigel', 'Niall'), 1)
self.assertAlmostEqual(self.cmp.dist('Niall', 'Nigel'), 1)
self.assertAlmostEqual(self.cmp.dist('Colin', 'Coiln'), 1)
self.assertAlmostEqual(self.cmp.dist('Coiln', 'Colin'), 1)
self.assertAlmostEqual(self.cmp.dist('ATCAACGAGT', 'AACGATTAG'), 0.5)
def test_ncd_lzss_sim(self):
"""Test abydos.distance.NCDlzss.sim."""
try:
import lzss # noqa: F401
except ImportError: # pragma: no cover
return
# Base cases
self.assertEqual(self.cmp.sim('', ''), 1.0)
self.assertEqual(self.cmp.sim('a', ''), 0.0)
self.assertEqual(self.cmp.sim('', 'a'), 0.0)
self.assertEqual(self.cmp.sim('abc', ''), 0.0)
self.assertEqual(self.cmp.sim('', 'abc'), 0.0)
self.assertEqual(self.cmp.sim('abc', 'abc'), 1.0)
self.assertEqual(self.cmp.sim('abcd', 'efgh'), 0.19999999999999996)
self.assertAlmostEqual(self.cmp.sim('Nigel', 'Niall'), 0)
self.assertAlmostEqual(self.cmp.sim('Niall', 'Nigel'), 0)
self.assertAlmostEqual(self.cmp.sim('Colin', 'Coiln'), 0)
self.assertAlmostEqual(self.cmp.sim('Coiln', 'Colin'), 0)
self.assertAlmostEqual(self.cmp.sim('ATCAACGAGT', 'AACGATTAG'), 0.5)
if __name__ == '__main__':
unittest.main()
|