00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import sys
00019 sys.path.insert(1,"../")
00020
00021 import unittest
00022 import OpenRTM_aist
00023
00024 import CORBA_SeqUtil
00025
00026 class FunctorAdd:
00027 def __init__(self, lists):
00028 self._list = lists
00029
00030 def __call__(self, obj):
00031 self._list.append(obj)
00032
00033 class Property:
00034 def __init__(self,id_):
00035 self.id =id_
00036
00037 class FunctorFind:
00038 def __init__(self, id):
00039 self._id = id
00040
00041 def __call__(self, prof):
00042 return self._id == prof.id
00043
00044
00045
00046 class TestCORBA_SeqUtil(unittest.TestCase):
00047 def setUp(self):
00048 pass
00049
00050 def tearDown(self):
00051 OpenRTM_aist.Manager.instance().shutdownManager()
00052 return
00053
00054 def test_for_each(self):
00055 list_ = [0,1,2]
00056 func_ = FunctorAdd(list_)
00057 add_ = [3,4,5,6,7]
00058 CORBA_SeqUtil.for_each(add_,func_)
00059 self.assertEqual(list_, [0,1,2,3,4,5,6,7])
00060
00061
00062 def test_find(self):
00063 prof = [Property(100),Property(200),Property(300)]
00064 index = CORBA_SeqUtil.find(prof,FunctorFind(300))
00065 self.assertEqual(index, 2)
00066
00067 index = CORBA_SeqUtil.find(prof,FunctorFind(3000))
00068 self.assertEqual(index, -1)
00069
00070
00071 def test_push_back(self):
00072 list_ = [0,1,2,3]
00073 CORBA_SeqUtil.push_back(list_,100)
00074 self.assertEqual(list_, [0,1,2,3,100])
00075
00076
00077 def test_push_back_list(self):
00078 list1 = [0,1,2]
00079 list2 = [3,4,5,6,7]
00080 CORBA_SeqUtil.push_back_list(list1,list2)
00081 self.assertEqual(list1, [0,1,2,3,4,5,6,7])
00082
00083
00084 def test_insert(self):
00085 list_ = [0,1,2]
00086 CORBA_SeqUtil.insert(list_, "INS", 1)
00087 self.assertEqual(list_, [0,"INS",1,2])
00088
00089 CORBA_SeqUtil.insert(list_, 10, 100)
00090 self.assertEqual(list_, [0,"INS",1,2,10])
00091
00092
00093 def test_front(self):
00094 list_ = [3,4,5,6]
00095 self.assertEqual(CORBA_SeqUtil.front(list_),3)
00096
00097
00098 def test_back(self):
00099 list_ = [3,4,5,6]
00100 self.assertEqual(CORBA_SeqUtil.back(list_),6)
00101
00102
00103 def test_erase(self):
00104 list_ = [9,8,7,6]
00105 CORBA_SeqUtil.erase(list_, 10)
00106 self.assertEqual(list_, [9,8,7,6])
00107
00108 CORBA_SeqUtil.erase(list_, 1)
00109 self.assertEqual(list_, [9,7,6])
00110
00111
00112 def test_erase_if(self):
00113 prof = [Property(100),Property(200),Property(300)]
00114 CORBA_SeqUtil.erase_if(prof,FunctorFind(999))
00115 self.assertEqual(len(prof), 3)
00116
00117 CORBA_SeqUtil.erase_if(prof,FunctorFind(200))
00118 self.assertEqual(len(prof), 2)
00119
00120
00121 def test_clear(self):
00122 list_ = [0,1,2,3,4,5]
00123 CORBA_SeqUtil.clear(list_)
00124 self.assertEqual(list_,[])
00125
00126
00127 def test_refToVstring(self):
00128 pass
00129
00130
00131
00132 if __name__ == '__main__':
00133 unittest.main()