本文整理匯總了Python中LinkedList.LinkedList.getByIndex方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.getByIndex方法的具體用法?Python LinkedList.getByIndex怎麽用?Python LinkedList.getByIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.getByIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_insert
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import getByIndex [as 別名]
def test_insert(self):
ll = LinkedList()
ll.append("cero")
ll.append("uno")
ll.append("dos")
ll.append("tres")
ll.append("cuatro")
self.assertEqual(ll.getByIndex(0),"cero")
self.assertEqual(ll.getByIndex(1),"uno")
self.assertEqual(ll.getByIndex(2),"dos")
self.assertEqual(ll.getByIndex(3),"tres")
self.assertEqual(ll.getByIndex(4),"cuatro")
示例2: test_GetByIndex_BorderOOPList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import getByIndex [as 別名]
def test_GetByIndex_BorderOOPList(self):
# `border` is the default policy, so I specify nothing
ll = LinkedList()
self.assertEqual(ll.getLength(), 0)
self.assertRaises(IndexError, ll.getByIndex(0))
self.assertRaises(IndexError, ll.getByIndex(1))
self.assertRaises(IndexError, ll.getByIndex(-1))
ll.insert(data="tres", index=-1)
self.assertEqual(ll.getByIndex(0), "tres")
self.assertEqual(ll.getByIndex(1), "tres")
self.assertEqual(ll.getByIndex(-1), "tres")
self.assertEqual(ll.getLength(), 1)
ll.insert(data="uno")
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(1), "tres")
self.assertEqual(ll.getByIndex(-1), "uno")
self.assertEqual(ll.getByIndex(-2), "uno")
self.assertEqual(ll.getByIndex(2), "tres")
self.assertEqual(ll.getByIndex(3), "tres")
self.assertEqual(ll.getByIndex(4), "tres")
self.assertEqual(ll.getLength(), 2)
ll.insert(data="dos", index=1)
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(2), "tres")
self.assertEqual(ll.getByIndex(1), "dos")
self.assertEqual(ll.getByIndex(-1), "uno")
self.assertEqual(ll.getByIndex(-2), "uno")
self.assertEqual(ll.getByIndex(-3), "uno")
self.assertEqual(ll.getByIndex(-4), "uno")
self.assertEqual(ll.getByIndex(3), "tres")
self.assertEqual(ll.getByIndex(4), "tres")
self.assertEqual(ll.getByIndex(5), "tres")
self.assertEqual(ll.getLength(), 3)
ll.insert(data="cuatro", index=5)
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(2), "tres")
self.assertEqual(ll.getByIndex(1), "dos")
self.assertEqual(ll.getByIndex(3), "cuatro")
self.assertEqual(ll.getByIndex(4), "cuatro")
self.assertEqual(ll.getByIndex(5), "cuatro")
self.assertEqual(ll.getByIndex(6), "cuatro")
self.assertEqual(ll.getByIndex(7), "cuatro")
self.assertEqual(ll.getByIndex(-1), "uno")
self.assertEqual(ll.getByIndex(-2), "uno")
self.assertEqual(ll.getByIndex(-3), "uno")
self.assertEqual(ll.getByIndex(-4), "uno")
self.assertEqual(ll.getByIndex(-5), "uno")
self.assertEqual(ll.getLength(), 4)
ll.insert(data="cero", index=0)
self.assertEqual(ll.getByIndex(1), "uno")
self.assertEqual(ll.getByIndex(3), "tres")
self.assertEqual(ll.getByIndex(2), "dos")
self.assertEqual(ll.getByIndex(4), "cuatro")
self.assertEqual(ll.getByIndex(0), "cero")
self.assertEqual(ll.getByIndex(-1), "cero")
self.assertEqual(ll.getByIndex(-2), "cero")
self.assertEqual(ll.getByIndex(-3), "cero")
self.assertEqual(ll.getByIndex(-4), "cero")
self.assertEqual(ll.getByIndex(-5), "cero")
self.assertEqual(ll.getLength(), 5)
示例3: test_GetByIndex_RoundOOPList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import getByIndex [as 別名]
def test_GetByIndex_RoundOOPList(self):
ll = LinkedList(oor_policy="round")
self.assertEqual(ll.getLength(), 0)
self.assertRaises(IndexError, ll.getByIndex(0))
self.assertRaises(IndexError, ll.getByIndex(1))
self.assertRaises(IndexError, ll.getByIndex(-1))
ll.insert("tres")
self.assertEqual(ll.getByIndex(0), "tres")
self.assertEqual(ll.getByIndex(1), "tres")
self.assertEqual(ll.getByIndex(-1), "tres")
self.assertEqual(ll.getLength(), 1)
ll.insert(data="uno")
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(1), "tres")
self.assertEqual(ll.getByIndex(-1), "tres")
self.assertEqual(ll.getByIndex(-2), "uno")
self.assertEqual(ll.getByIndex(2), "uno")
self.assertEqual(ll.getByIndex(3), "tres")
self.assertEqual(ll.getByIndex(4), "uno")
self.assertEqual(ll.getLength(), 2)
ll.insert(data="dos", index=1)
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(2), "tres")
self.assertEqual(ll.getByIndex(1), "dos")
self.assertEqual(ll.getByIndex(-1), "tres")
self.assertEqual(ll.getByIndex(-2), "dos")
self.assertEqual(ll.getByIndex(-3), "uno")
self.assertEqual(ll.getByIndex(-4), "tres")
self.assertEqual(ll.getByIndex(3), "uno")
self.assertEqual(ll.getByIndex(4), "dos")
self.assertEqual(ll.getByIndex(5), "tres")
self.assertEqual(ll.getByIndex(6), "uno")
self.assertEqual(ll.getLength(), 3)
ll.insert(data="cuatro", index=3)
self.assertEqual(ll.getByIndex(0), "uno")
self.assertEqual(ll.getByIndex(2), "tres")
self.assertEqual(ll.getByIndex(1), "dos")
self.assertEqual(ll.getByIndex(3), "cuatro")
self.assertEqual(ll.getByIndex(4), "uno")
self.assertEqual(ll.getByIndex(5), "dos")
self.assertEqual(ll.getByIndex(6), "tres")
self.assertEqual(ll.getByIndex(7), "cuatro")
self.assertEqual(ll.getByIndex(-1), "cuatro")
self.assertEqual(ll.getByIndex(-2), "tres")
self.assertEqual(ll.getByIndex(-3), "dos")
self.assertEqual(ll.getByIndex(-4), "uno")
self.assertEqual(ll.getByIndex(-5), "cuatro")
self.assertEqual(ll.getLength(), 4)
ll.insert(data="cero", index=0)
self.assertEqual(ll.getByIndex(1), "uno")
self.assertEqual(ll.getByIndex(3), "tres")
self.assertEqual(ll.getByIndex(2), "dos")
self.assertEqual(ll.getByIndex(4), "cuatro")
self.assertEqual(ll.getByIndex(0), "cero")
self.assertEqual(ll.getLength(), 5)