def simpler_dict_collision_test(): d = {n:n for n in range(10000)} i_d = ImmutableDict(d) failures = [] result_keys = i_d.keys() for n in range(10000): if n not in result_keys: failures.append(n) if failures: print "Lost %d keys: %s" % (len(failures), failures) assert False, str(failures)
def simpler_dict_collision_test(): d = {n: n for n in range(10000)} i_d = ImmutableDict(d) failures = [] result_keys = i_d.keys() for n in range(10000): if n not in result_keys: failures.append(n) if failures: print "Lost %d keys: %s" % (len(failures), failures) assert False, str(failures)
def dict_collision_test(): l = [str(uuid.uuid4()) for _ in range(10000)] d = {l[n]: n for n in range(10000)} i_d = ImmutableDict(d) assert len(i_d.keys()) == len(d.keys()) failures = [] for k in l: if str(k) not in i_d: failures.append({k: d[k]}) if failures: msg = 'UUID entries lost:' for uid in failures: msg += '{}\n'.format(uid) msg += '\n(There are {} of them)'.format(len(failures)) assert False, msg
def dicttest(): d1 = ImmutableDict(hello="world") d2 = d1.assoc("goodbye", "moon") d3 = d2.remove("hello") assert d1["hello"] == "world" assert d2["goodbye"] == "moon" assert d1.get("goodbye") is None assert d3.get("hello") is None assert d2 == {"hello":"world", "goodbye":"moon"} d4 = d2.update(ImmutableDict({"a":"b", "c":"d"})) assert len(d4) == 4 assert d4['a'] == 'b' assert d4['c'] == 'd' d5 = d1.update(hola="mundo") assert d5['hola'] == 'mundo' assert 'hola' in d5 assert ImmutableDict() == {}
def typetest(): l = ImmutableList() v = ImmutableVector() d = ImmutableDict() assert l is not None assert v != 3 assert d != 'a' assert l == v assert d != v assert d != l
def __init__(self, *args, **kwargs): if not kwargs: if len(args) == 1: ImmutableDict.__init__(self, args[0]) else: ImmutableDict.__init__(self) else: ImmutableDict.__init__(self, kwargs)
def brutal_creation_test(): """ Note that this is incredibly slow and painful. You probably won't want to run it often """ errors = [] for i in range(10000): print '@', d = {n: n for n in range(i)} i_d = ImmutableDict(d) for j in range(i): if j not in i_d: msg = '@ length {}, index {} got lost' errors.append(msg.format(i, j)) if not i % 80: print '!' assert not errors, str(errors)
def dicttest(): d1 = ImmutableDict(hello="world") d2 = d1.assoc("goodbye", "moon") d3 = d2.remove("hello") assert d1["hello"] == "world" assert d2["goodbye"] == "moon" assert d1.get("goodbye") is None assert d3.get("hello") is None assert d2 == {"hello": "world", "goodbye": "moon"} d4 = d2.update(ImmutableDict({"a": "b", "c": "d"})) assert len(d4) == 4 assert d4['a'] == 'b' assert d4['c'] == 'd' d5 = d1.update(hola="mundo") assert d5['hola'] == 'mundo' assert 'hola' in d5 assert ImmutableDict() == {} assert ImmutableDict().get(1, 2) == 2
def dict_int_test(): d = {n:n for n in range(16)} d1 = ImmutableDict(d) assert (len(d1.keys()) == 16)
def __eq__(self, other): return ImmutableDict.__eq__(self, other)
def dict_int_test(): d = {n: n for n in range(16)} d1 = ImmutableDict(d) assert (len(d1.keys()) == 16)
def dict_creation_test(): d1 = {"a": 1, "b": 2, "c": 3, 4: 'd'} initial_length = len(d1) i_d = ImmutableDict(d1, d=4) assert len(d1) == initial_length assert len(i_d) == initial_length + 1
def dictismappingtest(): start = {'a': 1, 'b': 2, 'c': 3} i_d = ImmutableDict(start) assert isinstance(i_d, collections.Mapping)