コード例 #1
0
void test_of_reverse_for_CHAR_TYPE(){
  Linked_list list=createList();
  char _0th='Y',_1st='S',_2nd='e',_3rd='e',_4th='t',_5th='a',_6th=' ',_7th='R',_8th='a',_9th='m';
    
  add_to_list(&list,&_0th);
  add_to_list(&list,&_1st);
  add_to_list(&list,&_2nd);
  add_to_list(&list,&_3rd);
  add_to_list(&list,&_4th);
  add_to_list(&list,&_5th);
  add_to_list(&list,&_6th);
  add_to_list(&list,&_7th);
  add_to_list(&list,&_8th);
  add_to_list(&list,&_9th);

  Linked_list reversed_list = reverse(list);
  Element *e0=getElementAt(reversed_list,0);
  Element *e8=getElementAt(reversed_list,8);
  Element *e3=getElementAt(reversed_list,3);
  Element *e2=getElementAt(reversed_list,2);
  Element *e9=getElementAt(reversed_list,9);

  assert(TYPECHAR(e0->value)=='m');
  assert(TYPECHAR(e8->value)=='S');
  assert(TYPECHAR(e3->value)==' ');
  assert(TYPECHAR(e2->value)=='R');
  assert(TYPECHAR(e9->value)=='Y');
}
コード例 #2
0
ファイル: linkedListTest.c プロジェクト: PrasunPK/C
void test_map(){
  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 = 13;
  length = add_to_list(&list, item3);

  int hint = 2;
  
  LinkedList mapped_list = map(list, add, &hint);
  assert(mapped_list.length == 4);
  printf("All items are inserted\n");
  
  assert(*(int *)mapped_list.first->value == 12);
  assert(*(int *)mapped_list.last->value == 15);
  int element = *(int *)getElementAt(mapped_list, 1);
  int element1 = *(int *)getElementAt(mapped_list, 2);

  assert(element == 13);
  assert(element1 == 14);

  printf("All items are mapped\n");
}
コード例 #3
0
ファイル: linkedListTest.c プロジェクト: PrasunPK/C
void test_reverse(){
  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 = 13;
  length = add_to_list(&list, item3);
   
  LinkedList reversed_list = reverse(list);
  
  assert(reversed_list.length == 4);
  assert(*(int *)(reversed_list.first->value) == 13);
  assert(*(int *)(reversed_list.last->value) == 10);
  int element = *(int *)getElementAt(reversed_list, 1);
  int element1 = *(int *)getElementAt(reversed_list, 2);

  assert(element == 12);
  assert(element1 == 11);
  
  printf("Given linked list has been reversed\n");
}
コード例 #4
0
ファイル: linkedListTest.c プロジェクト: PrasunPK/C
void test_filter(){
  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 = 13;
  length = add_to_list(&list, item3);
  
  LinkedList filtered_list = filter(list, isEven, NULL);
  
  assert(filtered_list.length == 2);
  printf("List has been filtered and has two items in it\n");
  
  int element = *(int *)getElementAt(filtered_list, 0);
  int element1 = *(int *)getElementAt(filtered_list, 1);

  assert(element == 10);
  assert(element1 == 12);
  printf("Two items are there in the filtered list\n");
}
コード例 #5
0
ファイル: linkedListTest.c プロジェクト: PrasunPK/C
void test_getElementAt(){
  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 element = *(int *)getElementAt(list, 1);
  int element1 = *(int *)getElementAt(list, 2);
  char element2 = *(char *)getElementAt(list, 3);
  
  assert(element == 11);
  assert(element1 == 12);
  assert(element2 == 'P');
  printf("Element has been found at second position\n");
}
コード例 #6
0
void test_get_element_at_int() {
  LinkedList list = createList();
  int val1 = 2, val2 = 3, val3 = 4;
  add_to_list(&list, &val1);
  add_to_list(&list, &val2);
  add_to_list(&list, &val3);
  assert(4 == *(int *)getElementAt(list, 2));
  assert(2 == *(int *)getElementAt(list, 0));
  assert(NULL == (int *)getElementAt(list, 3));
  assert(NULL == (int *)getElementAt(list, -1));
};
コード例 #7
0
void test_get_element_at_float() {
  LinkedList list = createList();
  float val1 = 2.23, val2 = 3.11, val3 = 4.02;
  add_to_list(&list, &val1);
  add_to_list(&list, &val2);
  add_to_list(&list, &val3);
  assert(val3 == *(float *)getElementAt(list, 2));
  assert(val1 == *(float *)getElementAt(list, 0));
  assert(NULL == (float *)getElementAt(list, 3));
  assert(NULL == (float *)getElementAt(list, -1));
};
コード例 #8
0
void test_get_element_at_double() {
  LinkedList list = createList();
  double val1 = 2.23, val2 = 3.11, val3 = 4.02;
  add_to_list(&list, &val1);
  add_to_list(&list, &val2);
  add_to_list(&list, &val3);
  assert(4.02 == *(double *)getElementAt(list, 2));
  assert(2.23 == *(double *)getElementAt(list, 0));
  assert(NULL == (double *)getElementAt(list, 3));
  assert(NULL == (double *)getElementAt(list, -1));
};
コード例 #9
0
void test_get_element_at_char() {
  LinkedList list = createList();
  char val1 = 'S', val2 = 'A', val3 = 'Q';
  add_to_list(&list, &val1);
  add_to_list(&list, &val2);
  add_to_list(&list, &val3);
  assert('Q' == *(char *)getElementAt(list, 2));
  assert('S' == *(char *)getElementAt(list, 0));
  assert(NULL == (char *)getElementAt(list, 3));
  assert(NULL == (char *)getElementAt(list, -1));
};
コード例 #10
0
void test_get_element_at_string() {
  LinkedList list = createList();
  char val1[] = "The", val2[] = "World", val3[] = "Beautiful";
  add_to_list(&list, &val1);
  add_to_list(&list, &val2);
  add_to_list(&list, &val3);
  assert(val3 == (char *)getElementAt(list, 2));
  assert(val1 == (char *)getElementAt(list, 0));
  assert(NULL == (char *)getElementAt(list, 3));
  assert(NULL == (char *)getElementAt(list, -1));
};
コード例 #11
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
void test_getElementAt(){
	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 * result = getElementAt(list,1);
	assert(9==*result);
	int * result1 = getElementAt(list,3);
	assert(7==*result1);
}
コード例 #12
0
void test_for_get_element_at_given_index() {
    LinkedList list = createList();
    int num[10] = {32,43,223,54,76,7,45,3,4,23};
    for (int i = 0; i < 10; ++i) {
        add_to_list(&list,&num[i]);
    };
    void *ele1 = getElementAt(list,4);
    void *ele2 = getElementAt(list,6);
    void *ele3 = getElementAt(list,11);
    assert(*(int *)ele1==76);
    assert(*(int *)ele2==45);
    assert(ele3==NULL);
}
コード例 #13
0
void test_map_increment() {
  LinkedList list = createList();
  int arr[7] = {2, 3, 4, 6, 1, 12, 45};
  for (size_t i = 0; i < 7; i++) {
    add_to_list(&list, &arr[i]);
  }
  LinkedList output = map(list, &increment_by_1, NULL);
  int *index1 = getElementAt(output, 1);
  int *index2 = getElementAt(output, 2);
  assert(*(int *)output.head->value == 3);
  assert(*index1 == 4);
  assert(*index2 == 5);
  assert(*(int *)output.tail->value == 46);
};
コード例 #14
0
void test_filter_isEven() {
  LinkedList list = createList();
  int arr[7] = {2, 3, 4, 6, 1, 12, 45};
  for (size_t i = 0; i < 7; i++) {
    add_to_list(&list, &arr[i]);
  }
  LinkedList output = filter(list, &isEven, NULL);
  int *index1 = getElementAt(output, 1);
  int *index2 = getElementAt(output, 2);
  assert(*(int *)output.head->value == 2);
  assert(*index1 == 4);
  assert(*index2 == 6);
  assert(*(int *)output.tail->value == 12);
};
コード例 #15
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
void test_getElementAt_for_string(){
	LinkedList list = createList();
	char letter[] = "anjaly";
	char letter1[] = "babitha";
	char letter2[] = "chithra";
	char letter3[] = "diya";
	add_to_list(&list,letter);
	add_to_list(&list,letter1);
	add_to_list(&list,letter2);
	add_to_list(&list,letter3);
	assert(strcmp((char *)getElementAt(list,1),letter1)==0);
	assert(strcmp((char *)getElementAt(list,0),letter)==0);
	assert(strcmp((char *)getElementAt(list,2),letter2)==0);
	assert(strcmp((char *)getElementAt(list,3),letter3)==0);
}
コード例 #16
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
void test_getElementAt_for_char(){
	LinkedList list = createList();
	char letter[] = "a";
	char letter1[] = "b";
	char letter2[] = "c";
	char letter3[] = "d";
	add_to_list(&list,letter);
	add_to_list(&list,letter1);
	add_to_list(&list,letter2);
	add_to_list(&list,letter3);
	assert(strcmp((char *)getElementAt(list,1),letter1)==0);
	assert(strcmp((char *)getElementAt(list,0),letter)==0);
	assert(strcmp((char *)getElementAt(list,2),letter2)==0);
	assert(strcmp((char *)getElementAt(list,3),letter3)==0);
}
コード例 #17
0
void test_filter_is_divisible() {
  int hint = 3;
  LinkedList list = createList();
  int arr[7] = {2, 3, 4, 6, 1, 12, 45};
  for (size_t i = 0; i < 7; i++) {
    add_to_list(&list, &arr[i]);
  }
  LinkedList output = filter(list, &isDivisible, &hint);
  int *index1 = getElementAt(output, 1);
  int *index2 = getElementAt(output, 2);
  assert(*(int *)output.head->value == 3);
  assert(*index1 == 6);
  assert(*index2 == 12);
  assert(*(int *)output.tail->value == 45);
};
コード例 #18
0
void test_reverse() {
  LinkedList list = createList();
  int arr[7] = {2, 3, 4, 6, 1, 12, 45};
  for (size_t i = 0; i < 7; i++) {
    add_to_list(&list, &arr[i]);
  }
  LinkedList res = reverse(list);
  int *index1 = getElementAt(res, 1);
  int *index2 = getElementAt(res, 2);
  int *index5 = getElementAt(res, 5);
  assert(*(int *)res.head->value == 45);
  assert(*index1 == 12);
  assert(*index2 == 1);
  assert(*index5 == 3);
  assert(*(int *)res.tail->value == 2);
};
コード例 #19
0
ファイル: SymbolInvoc.c プロジェクト: a-krebs/YACC
/* ea is an array of nodes now */
ProxySymbol *isValidPreDefFuncInvocation(Symbol *s, struct ElementArray *ea)
{
	Symbol *param = NULL;
	Symbol * type;
	int i = 0;
	int nArgs = 0;

	nArgs = ea->nElements;

	// check argument count
	if (nArgs != 1) {
		errMsg = customErrorString("Function %s expected "
		    "1 argument but %d given.", s->name, nArgs);
		recordError(errMsg, yylineno, colno, SEMANTIC);
		return 0;
	}
	
	param = ((struct treeNode *)getElementAt(ea, i))->symbol;
	type = getTypeSym(param);
	
	if (isArgTypeValidInPreDefFunc(s, param)) {
		return getPreDefFuncReturnType(s, type);
			
	} else {
		errMsg = customErrorString("Function %s cannot be "
		    "called with argument of type %s.", s->name,
		    typeToString(getType(type)));
		recordError(errMsg, yylineno, colno, SEMANTIC);
		return 0;
	}
}
コード例 #20
0
ファイル: SymbolInvoc.c プロジェクト: a-krebs/YACC
int
isValidIOProcInvocation(Symbol *s, struct ElementArray *ea)
{
	Symbol *param = NULL;
	type_t type;
	int i, nArgs, valid = 1;

	nArgs = ea->nElements;

	// TODO use is isElementArraySimple() to do type checking?
	for (i = 0; i < nArgs; i++) {
		param = ((struct treeNode *)getElementAt(ea, i))->symbol;
		type = getType(param);
		
		if (!isArgTypeValidInIOFunc(s, param)) {
			errMsg = customErrorString("Invalid argument "
			    "of type %s passed to procedure %s.",
			    typeToString(type), s->name);
			recordError(errMsg, yylineno, colno, SEMANTIC);
			valid = 0;
		}
	}
	if (!valid) return 0;
	return 1;
}
コード例 #21
0
bool GuiFilesystemList::mouseMove(int mx, int my)
{
	GuiElement *element = getElementAt((int)(mx-x), (int)(my-y));
	if (element != NULL && element != background) {
        // Call mouseExit, if we're leaving
        if (element != highlightedElement && highlightedElement != NULL) {
            highlightedElement->mouseIn = false;
            if (highlightedElement->onMouseExit != NULL) {
                highlightedElement->onMouseExit();
            }
        }

        // We're now in a new element
        highlightedElement = element;

        // Call mouseEnter, if we haven't yet.
        if (!element->mouseIn) {
            element->mouseIn = true;
            if (element->onMouseEnter != NULL) {
                element->onMouseEnter();
            }
        }
	}
	return true;
}
コード例 #22
0
ファイル: linkedListTest.c プロジェクト: piolAtif/learning_c
void test_getElementAt(){
	LinkedList list = createList();
	int number = 44, number2 = 33, number3 = 23;	
	add_to_list(&list, &number);
	add_to_list(&list, &number2);
	add_to_list(&list, &number3);

	void *ele = getElementAt(list, 2);
	assert(_TYPEINT_(ele) == 23);

	void *ele2 = getElementAt(list,1);
	assert(_TYPEINT_(ele2) == 33);

	void *ele3 = getElementAt(list,0);
	assert(_TYPEINT_(ele3) == 44);
};
コード例 #23
0
void 
BoundrySegmentsVector::deleteAllConnections()
{
   for(uint32 i = 0; i < getSize(); i++ ) {
      static_cast<BoundrySegment*>(getElementAt(i))->deleteAllConnections();
   }
}
コード例 #24
0
void test_reverse_double() {
  LinkedList list = createList();
  double arr[7] = {2.21, 3.212, 4.87, 6.34, 1.435, 12.43, 45.22};
  for (size_t i = 0; i < 7; i++) {
    add_to_list(&list, &arr[i]);
  }
  LinkedList res = reverse(list);
  double *index1 = getElementAt(res, 1);
  double *index2 = getElementAt(res, 2);
  double *index5 = getElementAt(res, 5);
  assert(*(double *)res.head->value == 45.22);
  assert(*index1 == 12.43);
  assert(*index2 == 1.435);
  assert(*index5 == 3.212);
  assert(*(double *)res.tail->value == 2.21);
};
コード例 #25
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
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);
}
コード例 #26
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
void test_getElementAt_for_float(){
	LinkedList list = createList();
	float a = 15.7,b=20.0;
	add_to_list(&list,&a);
	add_to_list(&list,&b);
	assert(*(float *)getElementAt(list,1)==b);
}
コード例 #27
0
ファイル: linkedlistTest.c プロジェクト: vkdive/linked-list
void test_for_filter_in_linked_list(){
	LinkedList list = create();
	int x = 1;
	int y = 2;
	int z = 3;

	add(&list, &x);
	add(&list, &y);
	add(&list, &z);

	int hint = 2;
	LinkedList newlist = filter(list, &isEven ,&hint);

	assert(getElementAt(newlist, 0) == &y);
	assert(getElementAt(newlist, 1) == NULL);
}
コード例 #28
0
ファイル: CCenarioList.cpp プロジェクト: phabh/warbugs
void CCenarioList::update()
{
	for(int i = 0; i < size(); i=i+1)
	{
		getElementAt(i)->update();
	}
}
コード例 #29
0
 virtual void updateModelInRow(int row)
 {
     gcn::DropDown *choicebox = static_cast<gcn::DropDown *>(
                                getElementAt(row, RELATION_CHOICE_COLUMN));
     player_relations.setRelation(getPlayerAt(row),
                                static_cast<PlayerRelation::Relation>(
                                choicebox->getSelected()));
 }
コード例 #30
0
ファイル: linkedListTest.c プロジェクト: anjalyj/linked_list
void test_getElementAt_for_empty_string(){
	LinkedList list = createList();
	char letter[] = "a";
	char letter1[] = "";
	add_to_list(&list,letter);
	add_to_list(&list,letter1);
	assert(strcmp((char *)getElementAt(list,1),letter1)==0);
}