コード例 #1
0
ファイル: main.c プロジェクト: nchen24/LinkedListExample
void testInsertAtN(){
    Node *list = makeRandListOfSizeN(100);
    int vals[] = {16,   1024,   99, -10,    -54098};
    int poss[] = {0,    40,     22, 99,     32};

    // Test insertion into null list
    Node *test = NULL;
    test = insertAtN(test, vals[0], poss[0]);
    assert(test->val == vals[0]);

    // Insert at various places
    for(int i = 0 ; i < (int)getArrLen(vals) ; i++){
        list = insertAtN(list, vals[i], poss[i]);
    }

    // Ensure length is correct
    assert(getNumElements(list) == 100 + (int)getArrLen(vals));

    // Insert random value at end
    int newRandVal = arc4random();
    list = insertAtN(list, newRandVal, getNumElements(list));

    DArray arr = arrayify(list);
    // Ensure that value (plus a couple other inserted ones) are correct
    assert(arr.contents[arr.size-1] == newRandVal);
    assert(arr.contents[poss[0]] == vals[0]);
    assert(arr.contents[poss[2]] == vals[2]);

    free(arr.contents);
    delList(list);
    delList(test);
    printf(">> Test insert at n completed! <<\n");
}
コード例 #2
0
ファイル: main.c プロジェクト: nchen24/LinkedListExample
void testAddToTail(){
    int vals[] = {0, 3, -153, 33895, 3049, 101010};
    Node *list = NULL;
    for(int i = 0 ; i < (int)getArrLen(vals) ; i++){
        list = addToTail(list, vals[i]);
    }
    DArray test = arrayify(list);
    assert(test.size == (int)getArrLen(vals));
    for(int i = 0 ; i < (int)getArrLen(vals) ; i++){
        assert(test.contents[i] == vals[i]);
    }
    free(test.contents);
    delList(list);
    printf(">> Test add to tail completed! <<\n");
}
コード例 #3
0
ファイル: input.c プロジェクト: cheusov/nbase
/*
 * Eat all of the lines in the input file, attempting to categorize
 * them by their various flavors
 */
void
eaterrors(int *r_errorc, Eptr **r_errorv)
{
	Errorclass errorclass = C_SYNC;
	char *line;
	const char *inbuffer;
	size_t inbuflen;

    for (;;) {
	if ((inbuffer = fgetln(errorfile, &inbuflen)) == NULL)
		break;
	line = Calloc(inbuflen + 1, sizeof(char));
	memcpy(line, inbuffer, inbuflen);
	line[inbuflen] = '\0';
	wordvbuild(line, &cur_wordc, &cur_wordv);

	/*
	 * for convenience, convert cur_wordv to be 1 based, instead
	 * of 0 based.
	 */
	cur_wordv -= 1;
	if (cur_wordc > 0 &&
	   ((( errorclass = onelong() ) != C_UNKNOWN)
	   || (( errorclass = cpp() ) != C_UNKNOWN)
	   || (( errorclass = gcc45ccom() ) != C_UNKNOWN)
	   || (( errorclass = pccccom() ) != C_UNKNOWN)
	   || (( errorclass = richieccom() ) != C_UNKNOWN)
	   || (( errorclass = lint0() ) != C_UNKNOWN)
	   || (( errorclass = lint1() ) != C_UNKNOWN)
	   || (( errorclass = lint2() ) != C_UNKNOWN)
	   || (( errorclass = lint3() ) != C_UNKNOWN)
	   || (( errorclass = make() ) != C_UNKNOWN)
	   || (( errorclass = f77() ) != C_UNKNOWN)
	   || ((errorclass = pi() ) != C_UNKNOWN)
	   || (( errorclass = ri() )!= C_UNKNOWN)
	   || (( errorclass = mod2() )!= C_UNKNOWN)
	   || (( errorclass = troff() )!= C_UNKNOWN))
	) ;
	else
		errorclass = catchall();
	if (cur_wordc)
		erroradd(cur_wordc, cur_wordv+1, errorclass, C_UNKNOWN);
    }
#ifdef FULLDEBUG
    printf("%d errorentrys\n", nerrors);
#endif
    arrayify(r_errorc, r_errorv, er_head);
}
コード例 #4
0
ファイル: errorinput.c プロジェクト: kcrca/kcrca
void
eaterrors(int *r_errorc, Eptr **r_errorv)
{
	Errorclass	errorclass = C_SYNC;

	for (;;) {
		if (fgets(inbuffer, BUFSIZ, errorfile) == NULL)
			break;
		wordvbuild(inbuffer, &wordc, &wordv);
		/*
		 * for convenience, convert wordv to be 1 based, instead
		 * of 0 based.
		 */
		wordv -= 1;
		/*
		 * check for sunf77 errors has to be done before
		 * pccccom to be able to distingush between the two
		 */
		if ((wordc > 0) &&
		    (((errorclass = onelong()) != C_UNKNOWN) ||
		    ((errorclass = cpp()) != C_UNKNOWN) ||
		    ((errorclass = sunf77()) != C_UNKNOWN) ||
		    ((errorclass = pccccom()) != C_UNKNOWN) ||
		    ((errorclass = richieccom()) != C_UNKNOWN) ||
		    ((errorclass = lint0()) != C_UNKNOWN) ||
		    ((errorclass = lint1()) != C_UNKNOWN) ||
		    ((errorclass = lint2()) != C_UNKNOWN) ||
		    ((errorclass = lint3()) != C_UNKNOWN) ||
		    ((errorclass = make()) != C_UNKNOWN) ||
		    ((errorclass = f77()) != C_UNKNOWN) ||
		    ((errorclass = pi()) != C_UNKNOWN) ||
		    ((errorclass = ri()) != C_UNKNOWN) ||
		    ((errorclass = troff()) != C_UNKNOWN) ||
		    ((errorclass = mod2()) != C_UNKNOWN) ||
		    ((errorclass = troff()) != C_UNKNOWN))) {
		    /* EMPTY */
		} else {
			errorclass = catchall();
		}
		if (wordc)
			erroradd(wordc, wordv+1, errorclass, C_UNKNOWN);
	}
#ifdef FULLDEBUG
	printf("%d errorentrys\n", nerrors);
#endif
	arrayify(r_errorc, r_errorv, er_head);
}
コード例 #5
0
ファイル: main.c プロジェクト: nchen24/LinkedListExample
void testChangeValueAtN(){
    int vals[] = {16,   1024,   99, -10,    -54098};
    int poss[] = {0,    40,     22, 99,     32};
    Node *list = makeRandListOfSizeN(100);

    changeValueAtN(list, 0, -1);  // Should cause an error in your way of choice!
    changeValueAtN(list, 0, 300);

    for(int i = 0 ; i < (int)getArrLen(vals) ; i++){
        changeValueAtN(list, vals[i], poss[i]);
    }

    DArray arr = arrayify(list);

    for(int i = 0 ; i < (int)getArrLen(vals) ; i++){
        assert(arr.contents[i] == arr.contents[i]);
        printf("Test %d in testChangeValueAtN passed!\n", i);
    }

    free(arr.contents);
    delList(list);

    printf(">> Test change value at n completed! <<\n");
}