Example #1
0
    def test_delete(self):
        table = ht.newMap(capacity=17, maptype='PROBING')

        ht.put(table, '1', 'title1', self.comparekeys)
        ht.put(table, '2', 'title2', self.comparekeys)
        ht.put(table, '3', 'title3', self.comparekeys)
        ht.put(table, '4', 'title4', self.comparekeys)
        ht.put(table, '5', 'title5', self.comparekeys)
        ht.put(table, '6', 'title6', self.comparekeys)
        self.assertEqual(ht.size(table), 6)

        self.printTable(table)
        entry = ht.remove(table, '3', self.comparekeys)
        self.assertEqual(ht.size(table), 5)
        entry = ht.get(table, '3', self.comparekeys)
        self.assertIsNone(entry)
        self.printTable(table)
Example #2
0
    def test_get(self):
        table = ht.newMap(capacity=17, maptype='PROBING')

        ht.put(table, '1', 'title1', self.comparekeys)
        ht.put(table, '2', 'title2', self.comparekeys)
        ht.put(table, '3', 'title3', self.comparekeys)
        ht.put(table, '4', 'title4', self.comparekeys)
        ht.put(table, '5', 'title5', self.comparekeys)
        ht.put(table, '6', 'title6', self.comparekeys)
        self.assertEqual(ht.size(table), 6)

        entry = ht.get(table, '5', self.comparekeys)
        print(entry)
Example #3
0
    def test_contains(self):
        table = ht.newMap(capacity=17, maptype='PROBING')

        ht.put(table, '1', 'title1', self.comparekeys)
        ht.put(table, '2', 'title2', self.comparekeys)
        ht.put(table, '3', 'title3', self.comparekeys)
        ht.put(table, '4', 'title4', self.comparekeys)
        ht.put(table, '5', 'title5', self.comparekeys)
        ht.put(table, '6', 'title6', self.comparekeys)

        self.assertTrue(ht.contains(table, '1', self.comparekeys))
        self.assertFalse(ht.contains(table, '15', self.comparekeys))
        self.assertTrue(ht.contains(table, '6', self.comparekeys))
        self.assertEqual(ht.size(table), 6)
    def test_put (self):
        """
        """
        table = ht.newMap (capacity= 7, maptype='CHAINING')

        ht.put (table, 'book1', 'title1', self.compareentryfunction)
        ht.put (table, 'book2', 'title2', self.compareentryfunction)
        ht.put (table, 'book3', 'title3', self.compareentryfunction)
        ht.put (table, 'book4', 'title4', self.compareentryfunction)
        ht.put (table, 'book5', 'title5', self.compareentryfunction)
        ht.put (table, 'book6', 'title6', self.compareentryfunction)
        ht.put (table, 'book2', 'new-title 2', self.compareentryfunction)
        self.printTable (table)
        self.assertEqual (ht.size(table), 6)
Example #5
0
    def test_get(self):
        """
        """
        table = ht.newMap(capacity=7,
                          maptype='CHAINING',
                          comparefunction=self.comparefunction)

        ht.put(table, 'book1', 'title1')
        ht.put(table, 'book2', 'title2')
        ht.put(table, 'book3', 'title3')
        ht.put(table, 'book4', 'title4')
        ht.put(table, 'book5', 'title5')
        ht.put(table, 'book6', 'title6')

        book = ht.get(table, 'book2')
        print(book)
        self.assertEqual(ht.size(table), 6)
Example #6
0
def size(map):
    """
    Retornar el nĂºmero de entradas en la tabla de hash.
    """
    return ht.size(map)