Example #1
0
    def test_length(self):
        '''
        case12:测试length函数

        1、当链表为空时,调用length函数,返回链表长度为0        
        2、原链表存在4个元素[1,2,'a','b'],调用length函数,返回链表长度为4    
        '''
        '''step 1'''
        temp_list = Llist()
        value = temp_list.length()
        self.assertEqual(value, 0, "value_info " + str(value))
        '''step 2'''
        temp_list.append(1)
        temp_list.append(2)
        temp_list.append('a')
        temp_list.append('b')
        value = temp_list.length()
        self.assertEqual(value, 4, "value_info " + str(value))
Example #2
0
    def test_index_pop(self):
        '''
        case14:测试index_pop函数

        1、当链表为空时,删除空链表中元素,抛出指定异常   
        2、当链表为[0,1,2,3,4,5,6]时,删除index=-1或7的元素,抛出指定异常   
        3、当链表为[0,1,2,3,4,5,6]时,删除index=5和index=1的元素,元素删除正确,删除后链表长度为5
        4、当链表为[0,2,3,4,6]时,删除index=0,元素删除正确
        5、当链表为[2,3,4,6]时,删除index=3,元素删除正确,删除后链表长度为3
        '''
        '''step 1'''
        temp_list = Llist()
        with self.assertRaisesRegexp(LinkedListOperateError, 'list is empty'):
            temp_list.index_pop(0)
        '''step 2'''
        for i in xrange(7):
            temp_list.append(i)
        with self.assertRaisesRegexp(LinkedListOperateError,
                                     'index is out of range'):
            temp_list.index_pop(-1)
        with self.assertRaisesRegexp(LinkedListOperateError,
                                     'index is out of range'):
            temp_list.index_pop(7)
        '''step 3'''
        value = temp_list.index_pop(5)
        self.assertEqual(value, 5, "value_info " + str(value))

        value = temp_list.index_pop(1)
        self.assertEqual(value, 1, "value_info " + str(value))

        value = temp_list.length()
        self.assertEqual(value, 5, "value_info " + str(value))
        '''step 4'''
        value = temp_list.index_pop(0)
        self.assertEqual(value, 0, "value_info " + str(value))
        '''step 5'''
        value = temp_list.index_pop(3)
        self.assertEqual(value, 6, "value_info " + str(value))

        value = temp_list.length()
        self.assertEqual(value, 3, "value_info " + str(value))