Skip to content

Commit fe6a7aa

Browse files
committed
[test] stl vector __iadd__ with array.array
1 parent 3340cea commit fe6a7aa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

bindings/pyroot/pythonizations/test/stl_vector.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,32 @@ def test_stl_vector_boolean(self):
4545
self.assertFalse(vector.empty())
4646
self.assertTrue(bool(vector))
4747

48+
def test_stl_vector_iadd(self):
49+
import random
50+
import array
51+
"""
52+
Test that the __iadd__ pythonization of std::vector works as expected.
53+
This call dispatches to std::insert
54+
https://github.com/root-project/root/issues/
55+
"""
56+
def assertVec(vec, arr):
57+
for x, y in zip(vec, arr):
58+
self.assertEqual(x, y)
59+
60+
entry_type = ['unsigned short', 'short', 'int', 'unsigned int', 'long', 'unsigned long', 'float', 'double']
61+
array_type = ['H', 'h', 'i', 'I', 'l', 'L', 'f', 'd']
62+
63+
typemap = zip(entry_type, array_type)
64+
n = 5
65+
for dtype in typemap:
66+
vector = ROOT.std.vector[dtype[0]]()
67+
self.assertTrue(vector.empty())
68+
li = [random.randint(1, 100) for _ in range(n)]
69+
arr = array.array(dtype[1], li)
70+
vec += arr
71+
self.assertFalse(vector.empty())
72+
assertVec(vec, arr)
73+
4874
def test_tree_with_containers(self):
4975
"""
5076
Test that the boolean conversion of a std::vector works as expected inside a TTree.

0 commit comments

Comments
 (0)