class TestSimilar(TestCase): # pylint: disable=R0904 """Integration tests for similarity functions.""" items = [Number(42), Number(42.001), Number(43)] def test_find_similar(self): """Verify similar items can be found.""" base = Number(42) gen = tools.find_similar(base, self.items) self.assertListEqual([Number(42), Number(42.001)], list(gen)) def test_find_similar_none(self): """Verify an empty generator when no items can be found.""" base = Number(41) gen = tools.find_similar(base, self.items) self.assertListEqual([], list(gen)) def test_match_similar(self): """Verify an similar item can be matched.""" base = Number(42) item = tools.match_similar(base, self.items) self.assertEqual(Number(42), item) def test_match_similar_none(self): """Verify None is return when no similar item.""" base = Number(41) item = tools.match_similar(base, self.items) self.assertEqual(None, item)
class TestDuplicates(TestCase): # pylint: disable=R0904 """Integration tests for duplicate functions.""" items = [Number(42), Number(42.001), Number(43)] def test_duplicates(self): """Verify duplicate items can be found.""" base = Number(42) gen = tools.duplicates(base, self.items) self.assertListEqual([Number(42.001)], list(gen))
class TestSort(TestCase): # pylint: disable=R0904 """Integration tests for sort functions.""" items = [Number(42), Number(42.001), Number(43)] def test_sort(self): """Verify items can be sorted.""" base = Number(42.001) items = tools.sort(base, self.items) self.assertListEqual([Number(42.001), Number(42), Number(43)], items)
def test_duplicates(self): """Verify duplicate items can be found.""" base = Number(42) gen = tools.duplicates(base, self.items) self.assertListEqual([Number(42.001)], list(gen))
def test_match_similar_none(self): """Verify None is return when no similar item.""" base = Number(41) item = tools.match_similar(base, self.items) self.assertEqual(None, item)
def test_match_similar(self): """Verify an similar item can be matched.""" base = Number(42) item = tools.match_similar(base, self.items) self.assertEqual(Number(42), item)
def test_find_similar_none(self): """Verify an empty generator when no items can be found.""" base = Number(41) gen = tools.find_similar(base, self.items) self.assertListEqual([], list(gen))
def test_find_similar(self): """Verify similar items can be found.""" base = Number(42) gen = tools.find_similar(base, self.items) self.assertListEqual([Number(42), Number(42.001)], list(gen))
def test_different(self): """Verify two different numbers can be compared.""" a = Number(1) b = Number(42) self.assertComparison(a, b, False, False, 0.02)
def test_find_equal(self): """Verify equal items can be found.""" base = Number(42) gen = tools.find_equal(base, self.items) self.assertListEqual([Number(42)], list(gen))
def test_threshold(self): """Verify the Number threshold is correct.""" self.assertTrue(Number(100) % Number(99.9)) self.assertFalse(Number(100) % Number(99.8))
def test_bool(self): """verify a Number can be converted to a boolean.""" self.assertTrue(Number(42)) self.assertFalse(Number(0))
def test_str(self): """Verify a Number can be converted to a string.""" self.assertEqual("42.0", str(Number(42.0)))
def test_both_zero(self): """Verify two zero can be compared.""" a = Number(0) b = Number(0) self.assertComparison(a, b, True, True, 1.00)
def test_one_zero(self): """Verify zero can be compared with another number.""" a = Number(0) b = Number(42) self.assertComparison(a, b, False, False, 0.00)
def test_sort(self): """Verify items can be sorted.""" base = Number(42.001) items = tools.sort(base, self.items) self.assertListEqual([Number(42.001), Number(42), Number(43)], items)
def test_identical(self): """Verify two identical numbers can be compared.""" a = Number(42) b = Number(42) self.assertComparison(a, b, True, True, 1.00)