當前位置: 首頁>>代碼示例>>Python>>正文


Python LinkedList.getByIndex方法代碼示例

本文整理匯總了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")
開發者ID:Highstaker,項目名稱:Python-LinkedList-studies,代碼行數:15,代碼來源:insert_test.py

示例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)
開發者ID:Highstaker,項目名稱:Python-LinkedList-studies,代碼行數:69,代碼來源:getByIndex_test.py

示例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)
開發者ID:Highstaker,項目名稱:Python-LinkedList-studies,代碼行數:64,代碼來源:getByIndex_test.py


注:本文中的LinkedList.LinkedList.getByIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。