Example #1
0
    def test_keys_withNoneTypeArgument_shouldRaiseValueError(self):
        bst = AVLTree()

        with self.assertRaises(ValueError):
            bst.keys(None, 1)
        with self.assertRaises(ValueError):
            bst.keys(1, None)
Example #2
0
    def test_keys_withCompareFunctionAndNotEmptyBST_shouldReturnListOfKeysInGivenRangeIncludingGivenArguments(
            self):
        bst = AVLTree(self.cmp)
        for i in range(20):
            bst.put([0, i], i)

        for i in range(20):
            for j in range(i, 20):
                if i == j:
                    expected = [[0, i]]
                else:
                    expected = [[0, e] for e in range(i, j + 1)]
                self.assertEqual(expected, bst.keys([0, i], [0, j]))
Example #3
0
    def test_keys_withNotEmptyBSTAndArgumentsNotInBST_shouldReturnListOfKeysInGivenRangeExcludingGivenArguments(
            self):
        bst = AVLTree()
        for i in range(0, 20, 2):
            bst.put(i, i)

        for i in range(-1, 20, 2):
            for j in range(i, 20, 2):
                if i == j:
                    expected = []
                else:
                    expected = [e for e in range(i + 1, j + 1, 2)]
                self.assertEqual(expected, bst.keys(i, j))