def __init__(self, name):
     self.name = name
     self.customers = hashtable.Hashtable()
     self.classicals = binarysearchtree.BinarySearchTree()
     self.rocks = binarysearchtree.BinarySearchTree()
     self.metals = binarysearchtree.BinarySearchTree()
     self.fact = factory.Factory()
def main():

    studentname = hashtable.Hashtable(300000)

    InsertName(studentname)
    Traverse(studentname)
    deleteNames(studentname)
    retrievename(studentname)
Exemplo n.º 3
0
def test_insert_then_find(l):
    h = hashtable.Hashtable(ht_lib)
    d = dict()

    for kv in l:
        k, v = kv
        d[k] = v
        h[k] = v

    for k in d:
        assert d[k] == h[k]
Exemplo n.º 4
0
def test_init():
    '''test initialization of hashtable'''
    h = hashtable.Hashtable(one="one",
                            two="two",
                            three="three",
                            four="four",
                            five="five",
                            six="six",
                            seven="seven",
                            eight="eight",
                            nine="nine")
    assert len(h._buckets) == 32  # 32 - buckets have grown to accomodate items
Exemplo n.º 5
0
def test_find():
    '''test location of keys'''
    h = hashtable.Hashtable(one="one",
                            two="two",
                            three="three",
                            four="four",
                            five="five",
                            six="six",
                            seven="seven",
                            eight="eight",
                            nine="nine")
    assert h.get('four') == 'four'
def test_delete():
    ''' test deletion of keys'''
    minsize = 8
    # Remove a bunch of the keys
    h = hashtable.Hashtable(minsize,one="one", two="two", three="three", four="four", five="five", six="six", seven="seven", eight="eight", nine="nine")
    del h['one']
    del h['two']
    del h['three']
    del h['four']
    del h['five']
    del h['six']
    del h['seven']
    del h['eight']
    assert h.CHAIN_ELEMENTS == 1 
def test_insert_after_del():
    '''test insertion of keys after deletion'''
    minsize = 8
    # Remove some of the keys
    h = hashtable.Hashtable(minsize,one="one", two="two", three="three", four="four", five="five", six="six", seven="seven", eight="eight", nine="nine")
    del h['one']
    del h['two']
    del h['three']
    del h['four']
    del h['five']
    del h['six']
    del h['seven']
    del h['eight']
    h['ten'] = 10
    assert h.get('ten') == 10  
def test_resize():
    '''test resizing of hashtable once load factor is reached'''
    minsize = 3
    h = hashtable.Hashtable(minsize)
    h['one'] = "one"
    h['two'] = "two"
    h['three'] = "three"
    h['four'] = "four"
    h['five'] = "five"
    h['six'] = "six"
    h['seven'] = "seven"
    h['eight'] = "eight"
    h['nine'] = "nine"
    h['ten'] = 10
    #After resize, the number of (active) chains in the table should be 4 and total chain elements should be 10
    assert h.CHAIN_ELEMENTS == 10 and h.NUM_CHAINS == 4
Exemplo n.º 9
0
def test_delete():
    ''' test deletion of keys'''
    # Remove a bunch of the keys
    h = hashtable.Hashtable(one="one",
                            two="two",
                            three="three",
                            four="four",
                            five="five",
                            six="six",
                            seven="seven",
                            eight="eight",
                            nine="nine")
    del h['one']
    del h['two']
    del h['three']
    del h['four']
    del h['five']
    del h['six']
    del h['seven']
    del h['eight']

    assert len(
        h._buckets) == 8  # 8 - buckets has now shrunk due to utilization
Exemplo n.º 10
0
def test_insert_after_del():
    '''test insertion of keys after deletion'''
    # Remove a bunch of the keys
    h = hashtable.Hashtable(one="one",
                            two="two",
                            three="three",
                            four="four",
                            five="five",
                            six="six",
                            seven="seven",
                            eight="eight",
                            nine="nine")
    del h['one']
    del h['two']
    del h['three']
    del h['four']
    del h['five']
    del h['six']
    del h['seven']
    del h['eight']

    #print(len(h._buckets))  # 8 - buckets has now shrunk due to utilization
    h['ten'] = 10
    assert h.get('ten') == 10  # 10
def test_add_duplicate():
    '''test if the hashtable handles duplicates'''
    minsize = 8
    h  = hashtable.Hashtable(minsize,one="one", two="two", three="three", four="four", five="five", six="six", seven="seven", eight="eight", nine="nine")
    h["one"] = 17
    assert h.get("one") == 17
def test_init():
    '''test initialization of hashtable'''
    minsize = 8
    h = hashtable.Hashtable(minsize,one="one", two="two", three="three", four="four", five="five", six="six", seven="seven", eight="eight", nine="nine")
    assert len(h._buckets)  ==  8 and  h.CHAIN_ELEMENTS == 9