本文整理汇总了Python中Vector.Vector.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.insert方法的具体用法?Python Vector.insert怎么用?Python Vector.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInsertMiddle
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import insert [as 别名]
def testInsertMiddle(self):
vec1 = Vector()
vec1.append("a")
vec1.append("b")
vec1.append("c")
vec2 = Vector()
vec2.append("a")
vec2.append("c")
vec2.insert(1,"b")
self.assertEqual(vec1, vec2)
示例2: VectorTester
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import insert [as 别名]
#.........这里部分代码省略.........
vec.extend(self.bigVec)
self.assertEqual(self.bigVec, vec)
def testExtendEmptyByEmpty(self):
vec = Vector()
vec.extend(Vector())
self.assertEqual(vec, Vector())
def testExtendBySelf(self):
self.assertRaises(NotImplementedError,self.bigVec.extend, self.bigVec )
self.assertEqual(self.bigVec, self.cleanBigVec)
def testExtendGood(self):
vec = Vector()
for i in range(BIG_VEC_SIZE):
vec.append(i)
vec.append(10)
self.bigVec.extend(self.oneVec)
self.assertEqual(self.bigVec, vec)
def testExtendByNonVector(self):
vec1 = Vector()
vec2 = Vector()
vec1.extend(["a", "b"])
vec2.append("a")
vec2.append("b")
self.assertEqual(vec1, vec2)
#--------------------------------------------------------
#TESTING METHODS FOR INSERT
#--------------------------------------------------------
def testInsertIndexTooSmall(self):
self.assertRaises(IndexError, self.bigVec.insert,
-BIG_VEC_SIZE - 1, "a")
self.assertEqual(self.bigVec, self.cleanBigVec)
def testInsertIndexTooBig(self):
self.assertRaises(IndexError, self.bigVec.insert,
BIG_VEC_SIZE + 1, "a")
self.assertEqual(self.bigVec, self.cleanBigVec)
def testInsertAtStart(self):
self.bigVec.insert(0, "a")
vec = Vector()
vec.append("a")
for i in range(BIG_VEC_SIZE):
vec.append(i)
self.assertEqual(self.bigVec, vec)
def testInsertAtStartNegative(self):
self.bigVec.insert(-BIG_VEC_SIZE, "a")
vec = Vector()
vec.append("a")
for i in range(BIG_VEC_SIZE):
vec.append(i)
self.assertEqual(self.bigVec, vec)
def testInsertAtEnd(self):
self.bigVec.insert(BIG_VEC_SIZE, "a")
vec = Vector()
for i in range(BIG_VEC_SIZE):
vec.append(i)
vec.append("a")
self.assertEqual(self.bigVec, vec)