Skip to content

Commit

Permalink
Merge pull request #6 from jimrthy/feature/collections
Browse files Browse the repository at this point in the history
Have ImmutableDict implement collections.Mapping
  • Loading branch information
zhemao committed Sep 29, 2015
2 parents 0d3ccbf + 313db6a commit 63c6abc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion funktown/dictionary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .lookuptree import LookupTree

class ImmutableDict(object):
import collections

class ImmutableDict(collections.Mapping):
'''An immutable dictionary class. Access, insertion, and removal
are guaranteed to have O(log(n)) performance. Constructor takes same
arguments as builtin dict'''
Expand Down
8 changes: 8 additions & 0 deletions unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from funktown.lookuptree import LookupTree
from funktown import ImmutableDict, ImmutableVector, ImmutableList

import collections

def treetest():
t1 = LookupTree({0:0, 32:32, 4:4})
assert t1.get(0) == 0
Expand Down Expand Up @@ -51,6 +53,11 @@ def dicttest():
assert ImmutableDict() == {}
assert ImmutableDict().get(1, 2) == 2

def dictismappingtest():
start = {'a': 1, 'b': 2, 'c': 3}
i_d = ImmutableDict(start)
assert isinstance(i_d, collections.Mapping)

def listtest():
l1 = ImmutableList([2, 3])
assert l1.conj(1) == [1, 2, 3]
Expand All @@ -77,6 +84,7 @@ def typetest():
treetest()
vectortest()
dicttest()
dictismappingtest()
listtest()
typetest()
print("All tests passed")

0 comments on commit 63c6abc

Please sign in to comment.