Exemple #1
0
    def test_BSTCeiling(self):
        """
        """
        tree = bst.newMap('BST')
        self.assertTrue(bst.isEmpty(tree))
        bst.put(tree, '50', 'Title 50', self.comparekeys)
        bst.put(tree, '70', 'Title 70', self.comparekeys)
        bst.put(tree, '30', 'Title 30', self.comparekeys)
        bst.put(tree, '80', 'Title 80', self.comparekeys)
        bst.put(tree, '60', 'Title 60', self.comparekeys)
        bst.put(tree, '40', 'Title 40', self.comparekeys)
        bst.put(tree, '20', 'Title 20', self.comparekeys)
        bst.put(tree, '10', 'Title 10', self.comparekeys)
        bst.put(tree, '25', 'Title 6', self.comparekeys)
        bst.put(tree, '6', 'Title 3', self.comparekeys)
        bst.put(tree, '12', 'Title 12', self.comparekeys)
        bst.put(tree, '7', 'Title 7', self.comparekeys)
        bst.put(tree, '28', 'Title 28', self.comparekeys)

        node = bst.ceiling(tree, '29', self.comparekeys)
        self.assertEqual(node['key'], '30')

        node = bst.ceiling(tree, '28', self.comparekeys)
        self.assertEqual(node['key'], '28')

        node = bst.ceiling(tree, '30', self.comparekeys)
        self.assertEqual(node['key'], '30')

        node = bst.ceiling(tree, '72', self.comparekeys)
        self.assertEqual(node['key'], '80')
Exemple #2
0
 def test_DisorderedBST(self):
     """
     """
     tree = bst.newMap('BST')
     self.assertTrue(bst.isEmpty(tree))
     bst.put(tree, '50', 'Title 50', self.comparekeys)
     bst.put(tree, '70', 'Title 70', self.comparekeys)
     bst.put(tree, '30', 'Title 30', self.comparekeys)
     bst.put(tree, '80', 'Title 80', self.comparekeys)
     bst.put(tree, '60', 'Title 60', self.comparekeys)
     bst.put(tree, '40', 'Title 40', self.comparekeys)
     bst.put(tree, '20', 'Title 20', self.comparekeys)
     bst.put(tree, '10', 'Title 10', self.comparekeys)
     bst.put(tree, '25', 'Title 6', self.comparekeys)
     bst.put(tree, '6', 'Title 3', self.comparekeys)
     bst.put(tree, '12', 'Title 12', self.comparekeys)
     bst.put(tree, '7', 'Title 7', self.comparekeys)
     bst.put(tree, '28', 'Title 28', self.comparekeys)
     self.assertTrue(bst.contains(tree, '6', self.comparekeys))
     self.assertFalse(bst.contains(tree, '16', self.comparekeys))
     self.assertEqual(bst.min(tree)['key'], '6')
     self.assertEqual(bst.max(tree)['key'], '80')
     bst.deleteMin(tree)
     self.assertEqual(bst.min(tree)['key'], '7')
     bst.deleteMin(tree)
     self.assertEqual(bst.min(tree)['key'], '10')
     bst.deleteMax(tree)
     self.assertEqual(bst.max(tree)['key'], '70')
     bst.deleteMax(tree)
     self.assertEqual(bst.max(tree)['key'], '60')
Exemple #3
0
    def test_BSTRemove(self):
        """
        """
        tree = bst.newMap('BST')
        self.assertTrue(bst.isEmpty(tree))
        bst.put(tree, '50', 'Title 50', self.comparekeys)
        bst.put(tree, '70', 'Title 70', self.comparekeys)
        bst.put(tree, '30', 'Title 30', self.comparekeys)
        bst.put(tree, '80', 'Title 80', self.comparekeys)
        bst.put(tree, '60', 'Title 60', self.comparekeys)
        bst.put(tree, '40', 'Title 40', self.comparekeys)
        bst.put(tree, '20', 'Title 20', self.comparekeys)
        bst.put(tree, '10', 'Title 10', self.comparekeys)
        bst.put(tree, '25', 'Title 6', self.comparekeys)
        bst.put(tree, '6', 'Title 3', self.comparekeys)
        bst.put(tree, '12', 'Title 12', self.comparekeys)
        bst.put(tree, '7', 'Title 7', self.comparekeys)
        bst.put(tree, '28', 'Title 28', self.comparekeys)

        bst.remove(tree, '20', self.comparekeys)
        self.assertIsNone(bst.get(tree, '20', self.comparekeys))
Exemple #4
0
    def test_BSTRank(self):
        """
        """
        print('Test rank')
        tree = bst.newMap('BST')
        self.assertTrue(bst.isEmpty(tree))
        bst.put(tree, '50', 'Title 50', self.comparekeys)
        bst.put(tree, '70', 'Title 70', self.comparekeys)
        bst.put(tree, '30', 'Title 30', self.comparekeys)
        bst.put(tree, '80', 'Title 80', self.comparekeys)
        bst.put(tree, '60', 'Title 60', self.comparekeys)
        bst.put(tree, '40', 'Title 40', self.comparekeys)
        bst.put(tree, '20', 'Title 20', self.comparekeys)
        bst.put(tree, '10', 'Title 10', self.comparekeys)
        bst.put(tree, '25', 'Title 25', self.comparekeys)
        bst.put(tree, '6', 'Title 6', self.comparekeys)
        bst.put(tree, '12', 'Title 12', self.comparekeys)
        bst.put(tree, '7', 'Title 7', self.comparekeys)
        bst.put(tree, '28', 'Title 28', self.comparekeys)

        rank = bst.rank(tree, '30', self.comparekeys)
        print("rank 30: ", rank)
Exemple #5
0
    def test_BSTValueSet(self):
        """
        """
        print('Test value')
        tree = bst.newMap('BST')
        self.assertTrue(bst.isEmpty(tree))
        bst.put(tree, '50', 'Title 50', self.comparekeys)
        bst.put(tree, '70', 'Title 70', self.comparekeys)
        bst.put(tree, '30', 'Title 30', self.comparekeys)
        bst.put(tree, '80', 'Title 80', self.comparekeys)
        bst.put(tree, '60', 'Title 60', self.comparekeys)
        bst.put(tree, '40', 'Title 40', self.comparekeys)
        bst.put(tree, '20', 'Title 20', self.comparekeys)
        bst.put(tree, '10', 'Title 10', self.comparekeys)
        bst.put(tree, '25', 'Title 25', self.comparekeys)
        bst.put(tree, '6', 'Title 6', self.comparekeys)
        bst.put(tree, '12', 'Title 12', self.comparekeys)
        bst.put(tree, '7', 'Title 7', self.comparekeys)
        bst.put(tree, '28', 'Title 28', self.comparekeys)

        lt = bst.valueSet(tree)

        print(lt)
Exemple #6
0
    def test_BSTSelect(self):
        """
        """
        print('Test select')
        tree = bst.newMap('BST')
        self.assertTrue(bst.isEmpty(tree))
        bst.put(tree, '50', 'Title 50', self.comparekeys)
        bst.put(tree, '70', 'Title 70', self.comparekeys)
        bst.put(tree, '30', 'Title 30', self.comparekeys)
        bst.put(tree, '80', 'Title 80', self.comparekeys)
        bst.put(tree, '60', 'Title 60', self.comparekeys)
        bst.put(tree, '40', 'Title 40', self.comparekeys)
        bst.put(tree, '20', 'Title 20', self.comparekeys)
        bst.put(tree, '10', 'Title 10', self.comparekeys)
        bst.put(tree, '25', 'Title 25', self.comparekeys)
        bst.put(tree, '6', 'Title 6', self.comparekeys)
        bst.put(tree, '12', 'Title 12', self.comparekeys)
        bst.put(tree, '7', 'Title 7', self.comparekeys)
        bst.put(tree, '28', 'Title 28', self.comparekeys)

        node = bst.select(tree, 1)
        #assert ??
        print("select 1:", node['key'])