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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
# 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_gilbert_wells.
This module contains unit tests for abydos.distance.GilbertWells
"""
import unittest
from abydos.distance import GilbertWells
class GilbertWellsTestCases(unittest.TestCase):
"""Test GilbertWells functions.
abydos.distance.GilbertWells
"""
cmp = GilbertWells()
cmp_no_d = GilbertWells(alphabet=0)
def test_gilbert_wells_sim(self):
"""Test abydos.distance.GilbertWells.sim."""
# 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.assertAlmostEqual(self.cmp.sim('abcd', 'efgh'), 0.028716013247135602)
self.assertAlmostEqual(self.cmp.sim('Nigel', 'Niall'), 0.3776594411)
self.assertAlmostEqual(self.cmp.sim('Niall', 'Nigel'), 0.3776594411)
self.assertAlmostEqual(self.cmp.sim('Colin', 'Coiln'), 0.3776594411)
self.assertAlmostEqual(self.cmp.sim('Coiln', 'Colin'), 0.3776594411)
self.assertAlmostEqual(
self.cmp.sim('ATCAACGAGT', 'AACGATTAG'), 0.4950086952
)
# Tests with alphabet=0 (no d factor)
self.assertEqual(self.cmp_no_d.sim('', ''), 1.0)
self.assertEqual(self.cmp_no_d.sim('a', ''), 0.0)
self.assertEqual(self.cmp_no_d.sim('', 'a'), 0.0)
self.assertEqual(self.cmp_no_d.sim('abc', ''), 0.0)
self.assertEqual(self.cmp_no_d.sim('', 'abc'), 0.0)
self.assertEqual(self.cmp_no_d.sim('abc', 'abc'), 1.0)
self.assertAlmostEqual(
self.cmp_no_d.sim('abcd', 'efgh'), 0.13486136169765683
)
self.assertAlmostEqual(
self.cmp_no_d.sim('Nigel', 'Niall'), 0.0255856715
)
self.assertAlmostEqual(
self.cmp_no_d.sim('Niall', 'Nigel'), 0.0255856715
)
self.assertAlmostEqual(
self.cmp_no_d.sim('Colin', 'Coiln'), 0.0255856715
)
self.assertAlmostEqual(
self.cmp_no_d.sim('Coiln', 'Colin'), 0.0255856715
)
self.assertAlmostEqual(
self.cmp_no_d.sim('ATCAACGAGT', 'AACGATTAG'), 0.0153237873
)
def test_gilbert_wells_dist(self):
"""Test abydos.distance.GilbertWells.dist."""
# 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.assertAlmostEqual(self.cmp.dist('abcd', 'efgh'), 0.9712839867528644)
self.assertAlmostEqual(self.cmp.dist('Nigel', 'Niall'), 0.6223405589)
self.assertAlmostEqual(self.cmp.dist('Niall', 'Nigel'), 0.6223405589)
self.assertAlmostEqual(self.cmp.dist('Colin', 'Coiln'), 0.6223405589)
self.assertAlmostEqual(self.cmp.dist('Coiln', 'Colin'), 0.6223405589)
self.assertAlmostEqual(
self.cmp.dist('ATCAACGAGT', 'AACGATTAG'), 0.5049913048
)
# Tests with alphabet=0 (no d factor)
self.assertEqual(self.cmp_no_d.dist('', ''), 0.0)
self.assertEqual(self.cmp_no_d.dist('a', ''), 1.0)
self.assertEqual(self.cmp_no_d.dist('', 'a'), 1.0)
self.assertEqual(self.cmp_no_d.dist('abc', ''), 1.0)
self.assertEqual(self.cmp_no_d.dist('', 'abc'), 1.0)
self.assertEqual(self.cmp_no_d.dist('abc', 'abc'), 0.0)
self.assertAlmostEqual(
self.cmp_no_d.dist('abcd', 'efgh'), 0.8651386383023432
)
self.assertAlmostEqual(
self.cmp_no_d.dist('Nigel', 'Niall'), 0.9744143285
)
self.assertAlmostEqual(
self.cmp_no_d.dist('Niall', 'Nigel'), 0.9744143285
)
self.assertAlmostEqual(
self.cmp_no_d.dist('Colin', 'Coiln'), 0.9744143285
)
self.assertAlmostEqual(
self.cmp_no_d.dist('Coiln', 'Colin'), 0.9744143285
)
self.assertAlmostEqual(
self.cmp_no_d.dist('ATCAACGAGT', 'AACGATTAG'), 0.9846762127
)
def test_gilbert_wells_sim_score(self):
"""Test abydos.distance.GilbertWells.sim_score."""
# Base cases
self.assertAlmostEqual(self.cmp.sim_score('', ''), 76.91383873217538)
self.assertAlmostEqual(self.cmp.sim_score('a', ''), 40.179592442305186)
self.assertAlmostEqual(self.cmp.sim_score('', 'a'), 40.179592442305186)
self.assertAlmostEqual(self.cmp.sim_score('abc', ''), 39.4890060826051)
self.assertAlmostEqual(self.cmp.sim_score('', 'abc'), 39.4890060826051)
self.assertAlmostEqual(self.cmp.sim_score('abc', 'abc'), 49.00800898579118)
self.assertAlmostEqual(
self.cmp.sim_score('abcd', 'efgh'), 1.6845961909440712
)
self.assertAlmostEqual(
self.cmp.sim_score('Nigel', 'Niall'), 25.6938443303
)
self.assertAlmostEqual(
self.cmp.sim_score('Niall', 'Nigel'), 25.6938443303
)
self.assertAlmostEqual(
self.cmp.sim_score('Colin', 'Coiln'), 25.6938443303
)
self.assertAlmostEqual(
self.cmp.sim_score('Coiln', 'Colin'), 25.6938443303
)
self.assertAlmostEqual(
self.cmp.sim_score('ATCAACGAGT', 'AACGATTAG'), 55.2085412384
)
# Tests with alphabet=0 (no d factor)
self.assertAlmostEqual(self.cmp_no_d.sim_score('', ''), -36.04365338911715)
self.assertAlmostEqual(self.cmp_no_d.sim_score('a', ''), 70.9425768923849)
self.assertAlmostEqual(self.cmp_no_d.sim_score('', 'a'), 70.9425768923849)
self.assertAlmostEqual(self.cmp_no_d.sim_score('abc', ''), 71.63572407294485)
self.assertAlmostEqual(self.cmp_no_d.sim_score('', 'abc'), 71.63572407294485)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('abc', 'abc'), 71.63572407294485
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('abcd', 'efgh'), 9.690984737859244
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('Nigel', 'Niall'), 1.8432222004
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('Niall', 'Nigel'), 1.8432222004
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('Colin', 'Coiln'), 1.8432222004
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('Coiln', 'Colin'), 1.8432222004
)
self.assertAlmostEqual(
self.cmp_no_d.sim_score('ATCAACGAGT', 'AACGATTAG'), 1.1132321566
)
if __name__ == '__main__':
unittest.main()
|