def test_hashtable_get_set(): hashtable = ht.hashtable() dictionary = dict() for value in xrange(100): keys = get_keys() for key in keys: hashtable[key] = value dictionary[key] = value assert len(hashtable) == len(dictionary) for key in dictionary: assert hashtable[key] == dictionary[key]
def test_hashtable_delete(): hashtable = ht.hashtable() dictionary = dict() for value in xrange(100): keys = get_keys() for key in keys: hashtable[key] = value dictionary[key] = value for _ in range(10): key = random.choice(dictionary.keys()) del hashtable[key] del dictionary[key] assert len(hashtable) == len(dictionary) for key in dictionary: assert hashtable[key] == dictionary[key]
def test_hashtable_less_than_linear_time_complexity(): test_cases = dict() Ns = [n for n in xrange(100, 5000, 100)] for n in Ns: hashtable = ht.hashtable() for value in xrange(n): for key in get_keys(): hashtable[key] = value test_cases[n] = hashtable execution_times = [] for n in Ns: time1 = time.clock() for key in test_cases[n]: _ = test_cases[n][key] average_time = (time.clock() - time1) / n execution_times.append(average_time) correlation = numpy.corrcoef(Ns, execution_times)[0, 1] assert correlation < 0.5