本文整理匯總了Python中LinkedList.LinkedList.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.isEmpty方法的具體用法?Python LinkedList.isEmpty怎麽用?Python LinkedList.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.isEmpty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import isEmpty [as 別名]
class Stack:
def __init__(self):
self.content = LinkedList()
def push(self, x):
self.content.insert(0, x)
def pop(self):
return self.content.delete(0)
def top(self):
return self.content[0]
def isEmpty(self):
return self.content.isEmpty()
示例2: comment
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import isEmpty [as 別名]
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name +"\n remove() debe lanzar una excepcion de tipo IndexError cuando la lista esta vacia")
grade(0)
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)
# Check empty list - isEmpty
try:
l = LinkedList()
test_name = 'LinkedList vacia: isEmpty()'
if l.isEmpty():
comment("OK -> " + test_name)
grade(points['ll_vacia_isempty'])
else:
comment("FAIL -> " + test_name +"\n isEmpty() debe ser True cuando la lista esta vacia")
grade(0)
except:
e = sys.exc_info()[1]
comment("FAIL -> " + test_name + "\n" + str(e))
grade(0)
# Check empty list - str
示例3: test_isEmpty
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import isEmpty [as 別名]
def test_isEmpty(self):
myLinkedList = LinkedList()
self.assertTrue(myLinkedList.isEmpty())
示例4: TestLinkedList
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import isEmpty [as 別名]
class TestLinkedList(unittest.TestCase):
def setUp(self):
self.linkedList = LinkedList()
def test_0(self):
print("{} Can create linked list object".format(inspect.stack()[0][3]))
self.assertTrue(type(self.linkedList) is LinkedList)
def test_1(self):
print("{} Newly created linked list, value and next should be null".format(inspect.stack()[0][3]))
last = self.linkedList.getNext()
self.assertEqual(last.value, None)
self.assertEqual(last.next, None)
def test_2(self):
print("{} Newly created list, should be empty".format(inspect.stack()[0][3]))
self.assertTrue(self.linkedList.isEmpty())
def test_3(self):
print("{} After one added, list size should be one".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.assertEqual(self.linkedList.getSize(), 1)
def test_4(self):
print("{} After two added, list size should be two".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.assertEqual(self.linkedList.getSize(), 2)
def test_5(self):
print("{} After one added, first index search should return value".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.assertEqual(self.linkedList.searchValueAt(0),1)
def test_6(self):
print("{} After one added, second index search should return null".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.assertEqual(self.linkedList.searchValueAt(1),None)
def test_7(self):
print("{} When two values are added, second index search should return second value".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.assertEqual(self.linkedList.searchValueAt(1),2)
def test_8(self):
print("{} When two values are added, first index search should return first value".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.assertEqual(self.linkedList.searchValueAt(0),1)
def test_9(self):
print("{} Remove first node on empty list, should return null".format(inspect.stack()[0][3]))
self.assertEqual(self.linkedList.removeAtInd(0), None)
def test_10(self):
print("{} After one added then remove first node, list should be empty".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.removeAtInd(0)
self.assertTrue(self.linkedList.isEmpty())
def test_11(self):
print("{} After one added then remove first node, then add another value, first index should have second value".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.removeAtInd(0)
self.linkedList.add(2)
self.assertEqual(self.linkedList.searchValueAt(0),2)
def test_12(self):
print("{} After two values added then second value removed, length of list should be one".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.linkedList.removeAtInd(1)
self.assertEqual(self.linkedList.getSize(),1)
def test_13(self):
print("{} After two values added then value at third index removed, length of list should be two".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.linkedList.removeAtInd(2)
self.assertEqual(self.linkedList.getSize(),2)
def test_14(self):
print("{} After two values added then second value removed, first index should be first value and value of second index should be null".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.linkedList.removeAtInd(1)
self.assertEqual(self.linkedList.searchValueAt(1),None)
self.assertEqual(self.linkedList.searchValueAt(1),None)
def test_15(self):
print("{} After two added then remove first node, length should be one".format(inspect.stack()[0][3]))
self.linkedList.add(1)
self.linkedList.add(2)
self.linkedList.removeAtInd(0)
self.assertEqual(self.linkedList.getSize(),1)
def test_16(self):
print("{} After two values added then remove first, value at first index should be second value pushed".format(inspect.stack()[0][3]))
self.linkedList.add(1)
#.........這裏部分代碼省略.........