示例#1
0
 def test_remove(self):
     l = OrderedList()
     l.add('test')
     l.add(1)
     l.add('ABC')
     l.remove(1)
     self.assertEqual(l.toList(), ['ABC', 'test'])
示例#2
0
 def test_index(self):
     l = OrderedList()
     l.add('test')
     l.add(100)
     l.add('ABC')
     self.assertEqual(l.index(100), 1)
     self.assertEqual(l.index(2), -1)
示例#3
0
 def test_search(self):
     l = OrderedList()
     l.add('test')
     l.add(1)
     l.add('ABC')
     self.assertEqual(l.search('ABC'), True)
     self.assertEqual(l.search(2), False)
示例#4
0
 def test_pop(self):
     l = OrderedList()
     l.add('test')
     l.add(100)
     l.add('ABC')
     self.assertEqual(l.pop(-1), None)
     self.assertEqual(l.pop(5), None)
     self.assertEqual(l.pop(0), 'test')
示例#5
0
    def test_size(self):
        mylist = OrderedList()
        self.assertEquals(mylist.size(), 0)

        mylist.add(1)
        self.assertEquals(mylist.size(), 1)

        mylist.add(2)
        self.assertEquals(mylist.size(), 2)
示例#6
0
    def test_pop(self):
        mylist = OrderedList()
        mylist.add(1)
        mylist.add(2)
        mylist.add(3)

        self.assertEqual(mylist.pop(), 3)
        self.assertEqual(mylist.size(), 2)
示例#7
0
 def setUp(self):
     self.mylist = OrderedList()
     self.mylist.add(12)
     self.mylist.add(22)
     self.mylist.add(9)
     self.mylist.add(89)
     self.mylist.add(71)
     self.mylist.add(16)
示例#8
0
    def test_index(self):
        mylist = OrderedList()
        mylist.add(1)
        mylist.add(2)
        mylist.add(3)

        self.assertEqual(mylist.index(3), 3)
示例#9
0
    def test_search_item(self):
        mylist = OrderedList()
        mylist.add(1)
        mylist.add(2)
        mylist.add(3)

        self.assertEqual(mylist.search(3), True)
        self.assertEqual(mylist.search(4), False)
示例#10
0
    def test_add_items(self):
        mylist = OrderedList()
        mylist.add(3)
        mylist.add(2)
        mylist.add(1)

        self.assertEqual(mylist.head.getData(), 1)
        self.assertEqual(mylist.head.getNext().getData(), 2)
        self.assertEqual(mylist.head.getNext().getNext().getData(), 3)
示例#11
0
 def test_isEmpty(self):
     l = OrderedList()
     l.add('test')
     l.add(100)
     l.add('ABC')
     self.assertEqual(l.isEmpty(), False)
     l.remove('test')
     l.remove(100)
     l.remove('ABC')
     self.assertEqual(l.isEmpty(), True)
示例#12
0
 def test_length(self):
     l = OrderedList()
     l.add('test')
     l.add(100)
     l.add('ABC')
     self.assertEqual(l.length(), 3)
示例#13
0
 def test_add(self):
     l = OrderedList()
     l.add('test')
     l.add(1)
     l.add('ABC')
     self.assertEqual(l.toList(), ['ABC', 1, 'test'])
示例#14
0
class OrderedListTestCase(unittest.TestCase):
    def setUp(self):
        self.mylist = OrderedList()
        self.mylist.add(12)
        self.mylist.add(22)
        self.mylist.add(9)
        self.mylist.add(89)
        self.mylist.add(71)
        self.mylist.add(16)

    def test_length(self):
        self.assertEqual(self.mylist.length(), 6)

    def test_search(self):
        self.assertEqual(self.mylist.search(89), True)
        self.assertEqual(self.mylist.search(8), False)

    def test_remove(self):
        self.mylist.remove(12)
        self.mylist.remove(11)
        self.assertEqual(self.mylist.search(12), False)
        self.assertEqual(self.mylist.search(11), False)
        self.assertEqual(self.mylist.length(), 5)

    def test_toList(self):
        self.assertEqual(self.mylist.toList(), [9, 12, 16, 22, 71, 89])
示例#15
0
 def test_remove(self):
     mylist = OrderedList()
     mylist.add(1)
     mylist.remove(1)
     self.assertEqual(mylist.isEmpty(), True)
示例#16
0
 def test_isempty(self):
     mylist = OrderedList()
     self.assertEqual(mylist.isEmpty(), True)
     
     mylist.add(1)
     self.assertEqual(mylist.isEmpty(), False)