예제 #1
0
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)
예제 #2
0
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))
예제 #3
0
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)
예제 #4
0
 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))
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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))
예제 #8
0
 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))
예제 #9
0
 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)
예제 #10
0
 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))
예제 #11
0
 def test_threshold(self):
     """Verify the Number threshold is correct."""
     self.assertTrue(Number(100) % Number(99.9))
     self.assertFalse(Number(100) % Number(99.8))
예제 #12
0
 def test_bool(self):
     """verify a Number can be converted to a boolean."""
     self.assertTrue(Number(42))
     self.assertFalse(Number(0))
예제 #13
0
 def test_str(self):
     """Verify a Number can be converted to a string."""
     self.assertEqual("42.0", str(Number(42.0)))
예제 #14
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)
예제 #15
0
 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)
예제 #16
0
 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)
예제 #17
0
 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)