test_CORBA_SeqUtil.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 #
5 # \file CORBA_SeqUtil.py
6 # \brief test for CORBA sequence utility template functions
7 # \date $Date: 2007/09/03$
8 # \author Shinji Kurihara
9 #
10 # Copyright (C) 2006
11 # Task-intelligence Research Group,
12 # Intelligent Systems Research Institute,
13 # National Institute of
14 # Advanced Industrial Science and Technology (AIST), Japan
15 # All rights reserved.
16 #
17 
18 import sys
19 sys.path.insert(1,"../")
20 
21 import unittest
22 import OpenRTM_aist
23 
24 import CORBA_SeqUtil
25 
26 class FunctorAdd:
27  def __init__(self, lists):
28  self._list = lists
29 
30  def __call__(self, obj):
31  self._list.append(obj)
32 
33 class Property:
34  def __init__(self,id_):
35  self.id =id_
36 
38  def __init__(self, id):
39  self._id = id
40 
41  def __call__(self, prof):
42  return self._id == prof.id
43 
44 
45 
46 class TestCORBA_SeqUtil(unittest.TestCase):
47  def setUp(self):
48  pass
49 
50  def tearDown(self):
51  OpenRTM_aist.Manager.instance().shutdownManager()
52  return
53 
54  def test_for_each(self):
55  list_ = [0,1,2]
56  func_ = FunctorAdd(list_)
57  add_ = [3,4,5,6,7]
58  CORBA_SeqUtil.for_each(add_,func_)
59  self.assertEqual(list_, [0,1,2,3,4,5,6,7])
60 
61 
62  def test_find(self):
63  prof = [Property(100),Property(200),Property(300)]
64  index = CORBA_SeqUtil.find(prof,FunctorFind(300))
65  self.assertEqual(index, 2)
66 
67  index = CORBA_SeqUtil.find(prof,FunctorFind(3000))
68  self.assertEqual(index, -1)
69 
70 
71  def test_push_back(self):
72  list_ = [0,1,2,3]
73  CORBA_SeqUtil.push_back(list_,100)
74  self.assertEqual(list_, [0,1,2,3,100])
75 
76 
78  list1 = [0,1,2]
79  list2 = [3,4,5,6,7]
80  CORBA_SeqUtil.push_back_list(list1,list2)
81  self.assertEqual(list1, [0,1,2,3,4,5,6,7])
82 
83 
84  def test_insert(self):
85  list_ = [0,1,2]
86  CORBA_SeqUtil.insert(list_, "INS", 1)
87  self.assertEqual(list_, [0,"INS",1,2])
88 
89  CORBA_SeqUtil.insert(list_, 10, 100)
90  self.assertEqual(list_, [0,"INS",1,2,10])
91 
92 
93  def test_front(self):
94  list_ = [3,4,5,6]
95  self.assertEqual(CORBA_SeqUtil.front(list_),3)
96 
97 
98  def test_back(self):
99  list_ = [3,4,5,6]
100  self.assertEqual(CORBA_SeqUtil.back(list_),6)
101 
102 
103  def test_erase(self):
104  list_ = [9,8,7,6]
105  CORBA_SeqUtil.erase(list_, 10)
106  self.assertEqual(list_, [9,8,7,6])
107 
108  CORBA_SeqUtil.erase(list_, 1)
109  self.assertEqual(list_, [9,7,6])
110 
111 
112  def test_erase_if(self):
113  prof = [Property(100),Property(200),Property(300)]
114  CORBA_SeqUtil.erase_if(prof,FunctorFind(999))
115  self.assertEqual(len(prof), 3)
116 
117  CORBA_SeqUtil.erase_if(prof,FunctorFind(200))
118  self.assertEqual(len(prof), 2)
119 
120 
121  def test_clear(self):
122  list_ = [0,1,2,3,4,5]
123  CORBA_SeqUtil.clear(list_)
124  self.assertEqual(list_,[])
125 
126 
127  def test_refToVstring(self):
128  pass
129 
130 
131 ############### test #################
132 if __name__ == '__main__':
133  unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34