diff options
Diffstat (limited to 'tests')
-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 0000000000..6be2778bea --- /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 0000000000..c3eb7ffc18 --- /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 0000000000..fb43a45eab --- /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 0000000000..f190e32ffd --- /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 0000000000..602560ce9d --- /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 0000000000..184735cde6 --- /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 0000000000..57d0ba4518 --- /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 0000000000..e7ae0bd965 --- /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)) |