def test_bst_get_next_inorder_nr(self): rlist = generate_random_list(999, 1, 9999) bst = get_bst_from_list(rlist) rlist.sort() for i in xrange(0, len(rlist) - 1): succ = bst.bst_get_next_inorder_nr(rlist[i]) self.assertEqual(rlist[i + 1], succ)
def test_min_heap_min_2(self): test_data = generate_random_list(18, 1, 999) mh = binary_min_heap(test_data) test_data.sort() self.assertEqual(test_data[0], mh.min_heap_get_min()) ret = mh.min_heap_sort() self.assertEqual(test_data, ret)
def test_bst_get_next_preorder_nr_3(self): rlist = generate_random_list(999, 1, 9999) bst = get_bst_from_list(rlist) r_pre = bst.bst_preorder_list_r() for i in xrange(len(r_pre) - 1): succ = bst.bst_get_next_preorder_nr(r_pre[i]) self.assertEqual(r_pre[i + 1], succ.data) succ = bst.bst_get_next_preorder_nr(r_pre[-1]) self.assertEqual(succ, None)
def test_rbt_insert_nr(self): lst = generate_random_list(99, 1, 999) bst = get_bst_from_list(lst) rbt = get_rbt_from_list(lst) self.assertEqual(bst.bst_get_size_r(), rbt.bst_get_size_r()) self.assertEqual(bst.bst_get_size_nr(), rbt.bst_get_size_nr()) self.assertEqual(bst.bst_inorder_list_r(), rbt.bst_inorder_list_r()) self.assertEqual(bst.bst_inorder_list_nr(), rbt.bst_inorder_list_nr()) print(rbt.bst_inorder_list_nr())
def test_stk_reverse(self): lst = generate_random_list(9, 1, 99) stk = stack() for x in xrange(0, len(lst)): stk.stk_push(lst[x]) ret = [] while not stk.stk_isempty(): ret.append(stk.stk_pop()) lst.reverse() self.assertEqual(lst, ret)
def test_que_list(self): lst = generate_random_list(9, 1, 99) que = queue() for x in xrange(0, len(lst)): que.que_enque(lst[x]) ret = [] self.assertEqual(lst[0], que.que_front()) self.assertEqual(lst[-1], que.que_rear()) while not que.que_isempty(): ret.append(que.que_deque()) self.assertEqual(ret, lst)
def test_min_heap_min(self): test_data = generate_random_list(9, 1, 49) mh = binary_min_heap(test_data) test_data.sort() self.assertEqual(test_data[0], mh.min_heap_get_min())
def test_max_heap_max(self): test_data = generate_random_list(9, 1, 49) mh = binary_max_heap(test_data) test_data.sort(reverse=True) self.assertEqual(test_data[0], mh.max_heap_get_max())
def test_bst_count(self): ret = generate_random_list(39, 19, 1000) bst = get_bst_from_list(ret) count = bst.bst_get_size_r() self.assertEqual(len(ret), count)