本文整理汇总了Python中Vector.Vector.index方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.index方法的具体用法?Python Vector.index怎么用?Python Vector.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VectorTester
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import index [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.oneVec, Vector())
def testRemoveAtStart(self):
vec = Vector()
for i in range(1,BIG_VEC_SIZE):
vec.append(i)
self.bigVec.remove(0)
vec.remove(0)
self.assertEqual(vec, self.bigVec)
def testRemoveAtEnd(self):
vec = Vector()
for i in range(BIG_VEC_SIZE-1):
vec.append(i)
self.bigVec.remove(BIG_VEC_SIZE-1)
self.assertEqual(vec, self.bigVec)
def testManyRemoves(self):
vec = Vector()
for i in range(50, BIG_VEC_SIZE):
vec.append(i)
for i in range(50):
self.bigVec.remove(i)
self.assertEquals(vec, self.bigVec)
def testRemoveWithDuplicates(self):
vec = Vector()
vec.append("a")
vec.append("b")
vec.append("c")
self.duplicatesVec.remove("b")
self.assertEquals(vec, self.duplicatesVec)
#--------------------------------------------------------
#TESTING METHODS FOR INDEX
#--------------------------------------------------------
def testIndexEmpty(self):
self.assertRaises(ValueError, self.emptyVec.index, "a")
self.assertEqual(len(self.emptyVec), 0)
def testIndexNotIn(self):
self.assertRaises(ValueError, self.bigVec.index, "a")
self.assertEqual(len(self.emptyVec), 0)
def testIndexAtStart(self):
self.assertEqual(self.bigVec.index(0), 0)
def testIndexAtEnd(self):
self.assertEqual(self.bigVec.index(BIG_VEC_SIZE-1), BIG_VEC_SIZE -1)
def testIndexDuplicate(self):
#should return position of first match
self.assertEqual(self.duplicatesVec.index("b"), 1)
#--------------------------------------------------------
#TESTING METHODS FOR COUNT
#--------------------------------------------------------
#NOT YET IMPLEMENTED!
#--------------------------------------------------------
#TESTING METHODS FOR POP
#--------------------------------------------------------
def testPop(self):
testV = Vector()
for i in range(BIG_VEC_SIZE):
testV.append(i)
testV.pop(5)
self.bigVec.pop(5)
for i in range(10,20):
testV.pop(i)
self.bigVec.pop(i)
self.assertRaises(IndexError, testV.pop, -7)
self.assertRaises(IndexError, testV.pop, BIG_VEC_SIZE + 5)
self.assertEqual(testV, self.bigVec)
#--------------------------------------------------------
#TESTING METHODS FOR REVERSE
#--------------------------------------------------------
def testReverse(self):
testV = Vector()