diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-01-07 15:42:16 -0800 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-01-07 15:42:16 -0800 |
| commit | 6d6bc9efc17c0fd4f28f935280db6d8dee100d4f (patch) | |
| tree | d1be037346e6e2c4844e83f5435771eaf2670208 /tests/basics | |
| parent | dfc0bac086a0277cc1c3d6a72ee906214bbbf9ac (diff) | |
| parent | baa665406fef58cfb0be0df8d2798ed0961506da (diff) | |
Merge pull request #108 from chipaca/dict_feats
Dictionary features that don't involve views or classmethods. First part of issue #99.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/tests/dict_clear.py | 6 | ||||
| -rw-r--r-- | tests/basics/tests/dict_copy.py | 5 | ||||
| -rw-r--r-- | tests/basics/tests/dict_get.py | 3 | ||||
| -rw-r--r-- | tests/basics/tests/dict_iterator.py | 3 | ||||
| -rw-r--r-- | tests/basics/tests/dict_pop.py | 12 | ||||
| -rw-r--r-- | tests/basics/tests/dict_popitem.py | 11 | ||||
| -rw-r--r-- | tests/basics/tests/dict_setdefault.py | 13 | ||||
| -rw-r--r-- | tests/basics/tests/dict_update.py | 10 |
8 files changed, 63 insertions, 0 deletions
diff --git a/tests/basics/tests/dict_clear.py b/tests/basics/tests/dict_clear.py new file mode 100644 index 000000000..6be2778be --- /dev/null +++ b/tests/basics/tests/dict_clear.py @@ -0,0 +1,6 @@ +d = {1: 2, 3: 4} +print(d) +d.clear() +print(d) +d[2] = 42 +print(d) diff --git a/tests/basics/tests/dict_copy.py b/tests/basics/tests/dict_copy.py new file mode 100644 index 000000000..c3eb7ffc1 --- /dev/null +++ b/tests/basics/tests/dict_copy.py @@ -0,0 +1,5 @@ +a = {i: 2*i for i in range(1000)} +b = a.copy() +for i in range(1000): + print(i, b[i]) +print(len(b)) diff --git a/tests/basics/tests/dict_get.py b/tests/basics/tests/dict_get.py new file mode 100644 index 000000000..fb43a45ea --- /dev/null +++ b/tests/basics/tests/dict_get.py @@ -0,0 +1,3 @@ +for d in {}, {42:2}: + print(d.get(42)) + print(d.get(42,2)) diff --git a/tests/basics/tests/dict_iterator.py b/tests/basics/tests/dict_iterator.py new file mode 100644 index 000000000..f190e32ff --- /dev/null +++ b/tests/basics/tests/dict_iterator.py @@ -0,0 +1,3 @@ +d = {1: 2, 3: 4} +for i in d: + print(i, d[i]) diff --git a/tests/basics/tests/dict_pop.py b/tests/basics/tests/dict_pop.py new file mode 100644 index 000000000..602560ce9 --- /dev/null +++ b/tests/basics/tests/dict_pop.py @@ -0,0 +1,12 @@ +d = {1: 2, 3: 4} +print(d.pop(3), d) +print(d) +print(d.pop(1, 42), d) +print(d.pop(1, 42), d) +print(d.pop(1, None), d) +try: + print(d.pop(1), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not rise KeyError!") diff --git a/tests/basics/tests/dict_popitem.py b/tests/basics/tests/dict_popitem.py new file mode 100644 index 000000000..184735cde --- /dev/null +++ b/tests/basics/tests/dict_popitem.py @@ -0,0 +1,11 @@ +d={1:2,3:4} +print(d.popitem()) +print(d) +print(d.popitem()) +print(d) +try: + print(d.popitem(), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not raise KeyError") diff --git a/tests/basics/tests/dict_setdefault.py b/tests/basics/tests/dict_setdefault.py new file mode 100644 index 000000000..57d0ba451 --- /dev/null +++ b/tests/basics/tests/dict_setdefault.py @@ -0,0 +1,13 @@ +d = {} +print(d.setdefault(1)) +print(d.setdefault(1)) +print(d.setdefault(5, 42)) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) +d.pop(5) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) + + diff --git a/tests/basics/tests/dict_update.py b/tests/basics/tests/dict_update.py new file mode 100644 index 000000000..e7ae0bd96 --- /dev/null +++ b/tests/basics/tests/dict_update.py @@ -0,0 +1,10 @@ +d = {1:2, 3:4} +print(d) +d.update(["ab"]) +print(d[1]) +print(d[3]) +print(d["a"]) +print(len(d)) +d.update([(1,4)]) +print(d[1]) +print(len(d)) |
