Esempio n. 1
0
    def test_is_not_equal_both_non_empty_but_same_length(self):
        other = BinarySearchTree()
        other.add('zaraza', 'something')
        another = BinarySearchTree()
        another.add('zaraz', 'something else')
        self.assertEqual(len(other), len(another))

        self.assertNotEqual(other, another)
Esempio n. 2
0
    def test_is_equal_both_non_empty(self):
        other = BinarySearchTree()
        another = BinarySearchTree()
        for k, v in dict(testdata).iteritems():
            other.add(k, v)
            another.add(k, v)

        self.assertEqual(other, another)
Esempio n. 3
0
class BaseTestCase(TestCase):

    bst_class = BinarySearchTree

    def setUp(self):
        super(BaseTestCase, self).setUp()
        self.instance = BinarySearchTree()

    def add_from_sequence(self, sequence=None):
        if sequence is None:
            sequence = testdata
        for i, d in sequence:
            self.instance.add(i, d)

    def remove_from_position(self, position):
        self.add_from_sequence()
        assert len(self.instance) == len(testdata)

        i = testdata[position][0]
        self.instance.remove(i)

        self.assertEqual(len(self.instance), len(testdata) - 1)
        # and all the other stuff is reachable
        for k, v in dict(testdata).iteritems():
            if k != i:
                self.assertEqual(self.instance.search(k), v)
            else:
                self.assertIsNone(self.instance.search(i))
Esempio n. 4
0
    def test_is_not_equal_from_empty(self):
        other = BinarySearchTree()
        other.add('zaraza', 'something')
        another = BinarySearchTree()

        self.assertNotEqual(another, other)
Esempio n. 5
0
 def test_is_equal_both_empty(self):
     other = BinarySearchTree()
     another = BinarySearchTree()
     self.assertEqual(other, another)
Esempio n. 6
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     self.instance = BinarySearchTree()