Skip to content
Snippets Groups Projects
Commit bb4cb11e authored by Enric Tejedor Saavedra's avatar Enric Tejedor Saavedra
Browse files

[Exp PyROOT] Test __getitem__ pythonisation of TVectorT

parent 0778c11a
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,7 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_tarray_len tarray_len.py) ...@@ -48,6 +48,7 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_tarray_len tarray_len.py)
# TVectorT pythonisations # TVectorT pythonisations
ROOT_ADD_PYUNITTEST(pyroot_pyz_tvectort_len tvectort_len.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_tvectort_len tvectort_len.py)
ROOT_ADD_PYUNITTEST(pyroot_pyz_tvectort_getitem tvectort_getitem.py)
# TString pythonisations # TString pythonisations
ROOT_ADD_PYUNITTEST(pyroot_pyz_tstring_len tstring_len.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_tstring_len tstring_len.py)
......
import unittest
import ROOT
class TVectorTGetItem(unittest.TestCase):
"""
Test for the pythonization that allows to: (i) get an item of a
TVectorT with boundary check for the index and (ii) iterate over
a TVectorT.
"""
num_elems = 3
# Tests
def test_boundary_check(self):
v = ROOT.TVectorT[float](self.num_elems)
# In range
self.assertEqual(v[0], v[0])
# Out of range
with self.assertRaises(IndexError):
v[-1]
# Out of range
with self.assertRaises(IndexError):
v[self.num_elems]
def test_iterable(self):
v = ROOT.TVectorT[float](self.num_elems)
val = 1
for i in range(self.num_elems):
v[i] = val
self.assertEquals(list(v), [ val for _ in range(self.num_elems) ])
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment