def test_nested_dictionaries(self): dict1 = { 0: { 1: False } } dict2 = { 0: { 1: True } } actual = dicttools.union(dict1, dict2) expected = { 0: { 1: True} } self.assertEquals(actual, expected, msg="%s != %s" % (expected, actual))
def test_basic_dictionaries(self): dict1 = { 0: 0, 1: 0 } dict2 = { 1: 1, 2: 2 } actual = dicttools.union(dict1, dict2) expected = { 0: 0, 1: 1, 2: 2 } self.assertEquals(actual, expected, msg="%s != %s" % (expected, actual))
def test_union_performance(self): total = 20000 items1 = [ (x, float(x)) for x in range(0, total) ] items2 = [ (x, float(x)) for x in range(0, total) ] dict1 = dict(items1) dict2 = dict(items1) start = time.time() dicttools.union(dict1, dict2) dictionary_elapsed = time.time() - start start = time.time() set(itertools.chain(items1, items2)) list_elapsed = time.time() - start print('\n dict union is %2.2fx slower than list union' % \ (dictionary_elapsed/list_elapsed))