aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George2014-08-13 13:22:24 +0100
committerDamien George2014-08-13 13:22:24 +0100
commit9b7a8ee8f1032a1c9172afe0bd3ac5be7780e4a2 (patch)
tree79b3b74827761d1db8b2081a2e1e2be24322a527 /tests
parent9d02780eafd9546354fd3ac429b0211f52331650 (diff)
py: Fix mult by negative number of tuple, list, str, bytes.
Multiplication of a tuple, list, str or bytes now yields an empty sequence (instead of crashing). Addresses issue #799 Also added ability to mult bytes on LHS by integer.
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/bytes_mult.py12
-rw-r--r--tests/basics/list_mult.py10
-rw-r--r--tests/basics/string_mult.py12
-rw-r--r--tests/basics/tuple_mult.py10
4 files changed, 42 insertions, 2 deletions
diff --git a/tests/basics/bytes_mult.py b/tests/basics/bytes_mult.py
new file mode 100644
index 000000000..0effd938e
--- /dev/null
+++ b/tests/basics/bytes_mult.py
@@ -0,0 +1,12 @@
+# basic multiplication
+print(b'0' * 5)
+
+# check negative, 0, positive; lhs and rhs multiplication
+for i in (-4, -2, 0, 2, 4):
+ print(i * b'12')
+ print(b'12' * i)
+
+# check that we don't modify existing object
+a = b'123'
+c = a * 3
+print(a, c)
diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py
index ec65fbb3f..16948f74c 100644
--- a/tests/basics/list_mult.py
+++ b/tests/basics/list_mult.py
@@ -1,4 +1,12 @@
+# basic multiplication
print([0] * 5)
+
+# check negative, 0, positive; lhs and rhs multiplication
+for i in (-4, -2, 0, 2, 4):
+ print(i * [1, 2])
+ print([1, 2] * i)
+
+# check that we don't modify existing list
a = [1, 2, 3]
c = a * 3
-print(c)
+print(a, c)
diff --git a/tests/basics/string_mult.py b/tests/basics/string_mult.py
new file mode 100644
index 000000000..c0713c1d3
--- /dev/null
+++ b/tests/basics/string_mult.py
@@ -0,0 +1,12 @@
+# basic multiplication
+print('0' * 5)
+
+# check negative, 0, positive; lhs and rhs multiplication
+for i in (-4, -2, 0, 2, 4):
+ print(i * '12')
+ print('12' * i)
+
+# check that we don't modify existing object
+a = '123'
+c = a * 3
+print(a, c)
diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py
index f8350f2f2..0f52bce44 100644
--- a/tests/basics/tuple_mult.py
+++ b/tests/basics/tuple_mult.py
@@ -1,4 +1,12 @@
+# basic multiplication
print((0,) * 5)
+
+# check negative, 0, positive; lhs and rhs multiplication
+for i in (-4, -2, 0, 2, 4):
+ print(i * (1, 2))
+ print((1, 2) * i)
+
+# check that we don't modify existing tuple
a = (1, 2, 3)
c = a * 3
-print(c)
+print(a, c)