Пример #1
0
void test_deleteElementAt_end(){
	LinkedList list = createList();
	int num = 10,num1 = 9,num2 = 8,num3 = 7;
	add_to_list(&list,&num);
	add_to_list(&list,&num1);
	add_to_list(&list,&num2);
	add_to_list(&list,&num3);
	assert(7==*(int *)list.tail->value);
	int result = *(int *)deleteElementAt(&list,3);
	assert(7==result);
	assert(8==*(int *)list.tail->value);
}
Пример #2
0
void test_deleteElementAt_deletes_the_element_at_the_given_index_and_returns_the_address_of_the_value_in_the_deleted_element () {
	LinkedList list = createList();
	int array[] = {1,2,3,4,5,6};

	for (int i = 0; i < 6; ++i){
		addToList(&list, &array[i]);
	}

	void *value = deleteElementAt(&list, 3);

	assert(*(int *)value == 4);
}
Пример #3
0
void test_deleteElementAt() {
    LinkedList list = createList();
    int element = 12,element1 = 13,element2 = 14,element3 = 15;
    add_to_list(&list,&element);
    add_to_list(&list,&element1);
    add_to_list(&list,&element2);
    add_to_list(&list,&element3);
    assert(4 == list.length);
    int deletedValue = *((int *)deleteElementAt(&list,2));
    assert(14 == deletedValue);
    assert(3 == list.length);
}
Пример #4
0
void test_deleteElementAt_beg(){
	LinkedList list = createList();
	int num = 10,num1 = 9,num2 = 8,num3 = 7;
	add_to_list(&list,&num);
	add_to_list(&list,&num1);
	add_to_list(&list,&num2);
	add_to_list(&list,&num3);
	assert(10==*(int *)list.head->value);
	int result = *(int *)deleteElementAt(&list,0);
	assert(10==result);
	assert(9==*(int *)list.head->value);
}
Пример #5
0
void test_deleteElementAt_if_listLength_one(){
	LinkedList list = createList();
	int number = 12;
	add_to_list(&list, &number);

	assert(list.length == 1);

	void *delete_element = deleteElementAt(&list, 0);
	assert(_TYPEINT_(delete_element) == 12);

	void *ele = getElementAt(list,0);
	assert(list.length == 0);
};
Пример #6
0
void test_deleteElementAt_deletes_the_last_element_and_rewrites_tail_if_last_element_is_choosen_to_delete () {
	LinkedList list = createList();
	int array[] = {1,2,3,4,5,6};

	for (int i = 0; i < 6; ++i){
		addToList(&list, &array[i]);
	}

	void *value = deleteElementAt(&list, 5);

	assert(*(int *)value == 6);

	assert(*(int *)(list.tail->value) == 5);
}
Пример #7
0
void test_deleteElementAt_for_lastElement(){
	LinkedList list = createList();
	int number = 12, number2 = 33, number3 = 23;
	add_to_list(&list, &number);
	add_to_list(&list, &number2);
	add_to_list(&list, &number3);

	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPEINT_(delete_element) == 23);

	void *ele = getElementAt(list,1);
	assert(_TYPEINT_(ele) == 33);
	assert(list.length == 2);
};
Пример #8
0
void test_deleteElementAt_deletes_the_first_element_and_rewrites_head_if_first_element_is_choosen_to_delete () {
	LinkedList list = createList();
	int array[] = {1,2,3,4,5,6};

	for (int i = 0; i < 6; ++i){
		addToList(&list, &array[i]);
	}

	void *value = deleteElementAt(&list, 0);

	assert(*(int *)value == 1);

	assert(*(int *)(list.head->value) == 2);
}
Пример #9
0
void test_deleteElementAt_forChar_if_listLength_one(){
	LinkedList list = createList();
	char value = 'p';
	add_to_list(&list, &value);

	assert(list.length == 1);

	void *delete_element = deleteElementAt(&list, 0);
	assert(_TYPECHAR_(delete_element) == 'p');

	void *ele = getElementAt(list,0);
	assert(list.length == 0);
	assert(ele == NULL);
};
Пример #10
0
void test_deleteElementAt_forChar(){
	LinkedList list = createList();
	char char1 = 'p',char2 = 'q', char3 = 'r', char4 = 's';

	add_to_list(&list, &char1);
	add_to_list(&list, &char2);
	add_to_list(&list, &char3);
	add_to_list(&list, &char4);

	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPECHAR_(delete_element) == 'r');

	void *ele = getElementAt(list,2);
	assert(_TYPECHAR_(ele) == 's');
}
Пример #11
0
void test_deleteElementAt(){
	LinkedList list = createList();
	int number = 12, number2 = 33, number3 = 23, number4 = 44, number5 = 23;
	add_to_list(&list, &number);
	add_to_list(&list, &number2);
	add_to_list(&list, &number3);
	add_to_list(&list, &number4);
	add_to_list(&list, &number5);

	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPEINT_(delete_element) == 23);

	void *ele = getElementAt(list,2);
	assert(_TYPEINT_(ele) == 44);
}
Пример #12
0
void test_deleteElementAt_forFloat_if_listLength_one(){
	LinkedList list = createList();
	float number = 23.43;
	add_to_list(&list, &number);

	assert(list.length == 1);

	float deleted_ele = 23.43;
	void *delete_element = deleteElementAt(&list, 0);
	assert(_TYPEFLOAT_(delete_element) == deleted_ele);

	void *ele = getElementAt(list,0);
	assert(list.length == 0);
	assert(ele == NULL);
};
Пример #13
0
void test_deleteElementAt__forChar_for_lastElement(){
	LinkedList list = createList();
	char char1 = 'p',char2 = 'q', char3 = 'r';

	add_to_list(&list, &char1);
	add_to_list(&list, &char2);
	add_to_list(&list, &char3);

	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPECHAR_(delete_element) == 'r');

	void *ele = getElementAt(list,1);
	assert(_TYPECHAR_(ele) == 'q');
	assert(list.length == 2);
};
Пример #14
0
void test_deleteElementAt(){
  LinkedList list = createList();
  void *item = (int *)malloc(sizeof(int));
  *(int *)item = 10;
  int length = add_to_list(&list, item);
  void *item1 = (int *)malloc(sizeof(int));
  *(int *)item1 = 11;
  length = add_to_list(&list, item1);
  void *item2 = (int *)malloc(sizeof(int));
  *(int *)item2 = 12;
  length = add_to_list(&list, item2);
  void *item3 = (char *)malloc(sizeof(char));
  *(char *)item3 = 'P';
  length = add_to_list(&list, item3);
  
  int index = 0; 
  int * deleted_item = deleteElementAt(&list,index);

  assert(*(int *)deleted_item == 10);
  printf("Item has been deleted and returned\n");
  
  int item_to_find = 10;
  assert(indexOf(list, item) == -1); 
  printf("deleted item can not be found\n");
  
  index = 2; 
  char * deleted_item_1 = deleteElementAt(&list,index);

  assert(*(char *)deleted_item_1 == 'P');
  assert(list.length == 2);
  printf("Last item has been deleted and returned\n");
  
  assert(indexOf(list, &item3) == -1); 
  printf("deleted item can not be found\n");

}
Пример #15
0
void test_deleteElementAt(){
	LinkedList list = createList();
	int num = 10,num1 = 9,num2 = 8,num3 = 7;
	add_to_list(&list,&num);
	add_to_list(&list,&num1);
	add_to_list(&list,&num2);
	add_to_list(&list,&num3);
	int * result1 = getElementAt(list,1);
	assert(9==*result1);
	int result = *(int *)deleteElementAt(&list,1);
	assert(9==result);
	int * result2 = getElementAt(list,1);
	assert(8==*result2);
	int * result6 = getElementAt(list,1);
	assert(8==*result6);
}
Пример #16
0
void test_deleteElementAt__forFloat_for_lastElement(){
	LinkedList list = createList();
	float float_point = 44.5, float_point2 = 32.145, float_point3 = 23.0987;

	add_to_list(&list, &float_point);
	add_to_list(&list, &float_point2);
	add_to_list(&list, &float_point3);

	float deleted_ele = 23.0987;
	float f_index_ele = 32.145;
	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPEFLOAT_(delete_element) == deleted_ele);

	void *ele = getElementAt(list,1);
	assert(_TYPEFLOAT_(ele) == f_index_ele);
	assert(list.length == 2);
};
Пример #17
0
void test_deleteElementAt_forFloat(){
	LinkedList list = createList();
	float float_point = 44.5, float_point2 = 32.145, float_point3 = 23.0987,float_point4 = 3421.24;

	add_to_list(&list, &float_point);
	add_to_list(&list, &float_point2);
	add_to_list(&list, &float_point3);
	add_to_list(&list, &float_point4);

	float deleted_ele = 23.0987;
	void *delete_element = deleteElementAt(&list, 2);
	assert(_TYPEFLOAT_(delete_element) == deleted_ele);

	float s_index_ele = 3421.24;
	void *ele = getElementAt(list,2);
	assert(_TYPEFLOAT_(ele) == s_index_ele);
}
Пример #18
0
void test_for_deleteElement_it_delete_the_LAST_element_of_int_type_from_list(){
  Linked_list list=createList();
  int _1st =22,_2nd=23,_3rd=24;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);

  
  assert(list.length==3);
  assert(TYPEINT(list.head->value)==_1st);
  assert(TYPEINT(list.tail->value)==_3rd);


  deleteElementAt(&list,list.length-1);
   
  assert(TYPEINT(list.head->value)==_1st);
  assert(TYPEINT(list.tail->value)==_2nd);
  assert(list.length==2);

}
Пример #19
0
void test_for_deleteElement_it_delete_the_LAST_element_of_CHAR_type_from_list(){
  Linked_list list=createList();
  char _1st ='A',_2nd='a',_3rd='b';
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);

  
  assert(list.length==3);
  assert(TYPECHAR(list.head->value)==_1st);
  assert(TYPECHAR(list.tail->value)==_3rd);


  deleteElementAt(&list,list.length-1);
   
  assert(TYPECHAR(list.head->value)==_1st);
  assert(TYPECHAR(list.tail->value)==_2nd);
  assert(list.length==2);


}
Пример #20
0
void test_for_deleteElement_it_delete_the_first_element_of_float_type_from_list(){
  Linked_list list=createList();
  float _1st =22.5,_2nd=23.0,_3rd=24.50;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);

  
  assert(list.length==3);
  assert(TYPEFLOAT(list.head->value)==22.5);
  assert(TYPEFLOAT(list.tail->value)==24.50);


  deleteElementAt(&list,0);
   
  assert(TYPEFLOAT(list.head->value)==23.0);
  assert(TYPEFLOAT(list.tail->value)==24.50);
  assert(list.length==2);


}
Пример #21
0
void test_for_deleteElement_it_delete_the_LAST_element_of_DOUBLE_type_from_list(){
  Linked_list list=createList();
  double _1st =229876897678976578976786.5908765789657896578;
  double _2nd=2300000000.00000099999999999999;
  double _3rd=_1st+24.50;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);

  
  assert(list.length==3);
  assert(TYPEDOUBLE(list.head->value)==_1st);
  assert(TYPEDOUBLE(list.tail->value)==_3rd);


  deleteElementAt(&list,list.length-1);
   
  assert(TYPEDOUBLE(list.head->value)==_1st);
  assert(TYPEDOUBLE(list.tail->value)==_2nd);
  assert(list.length==2);

}
Пример #22
0
void test_for_deleteElement_it_delete_the_ANY_element_of_DOUBLE_type_from_list(){
  Linked_list list=createList();
  double _1st =9.9;
  double _2nd=23;
  double _3rd=4.50;
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);

  
  assert(list.length==3);
  assert(TYPEDOUBLE(list.head->value)==_1st);
  assert(TYPEDOUBLE(list.tail->value)==_3rd);


  deleteElementAt(&list,2);
   
  assert(TYPEDOUBLE(list.head->value)==_1st);
  assert(TYPEDOUBLE(list.tail->value)==_2nd);
  assert(list.length==2);

}
Пример #23
0
void test_deleteElementAt_deleting_from_middle(){
  LinkedList list = createList();
  void *item = (int *)malloc(sizeof(int));
  *(int *)item = 10;
  int length = add_to_list(&list, item);
  void *item1 = (int *)malloc(sizeof(int));
  *(int *)item1 = 11;
  length = add_to_list(&list, item1);
  void *item2 = (int *)malloc(sizeof(int));
  *(int *)item2 = 12;
  length = add_to_list(&list, item2);
  void *item3 = (char *)malloc(sizeof(char));
  *(char *)item3 = 'P';
  length = add_to_list(&list, item3);
  
  int index = 2;
  int * deleted_item = deleteElementAt(&list,index);
  assert(*(int *)deleted_item == 12);
  assert(list.length == 3);
  printf("Item has been deleted from the middle and returned\n");

  assert(indexOf(list, item2) == -1); 
  printf("deleted item can not be found\n");
}