Beispiel #1
0
static void pl_iterator_test(void) {
	printsln((Any)__func__);
	
	// various ways of iterating a list:
	List ac = pl_create();
	pl_append(ac, "a");
	pl_append(ac, "b");
	pl_append(ac, "c");
	
	ListIterator iter = l_iterator(ac);
	while (l_has_next(iter)) {
		Any s = pl_next(&iter);
		printsln(s);
	}
	
	// PointerListNode *first = (PointerListNode*)ac->first;
	for (PointerListNode *node = ac->first; node != NULL; node = node->next) {
		Any s = node->value;
		printsln(s);
	}
	
#if 0
	while (iter = pl_next(iter)) {
		Any d = pl_current(iter);
		printiln(d);
	}
		
	for (AnyListIterator iter = pl_iterator(ac); pl_has_current(iter); iter = pl_next(iter)) {
		Any d = pl_current(iter);
		printiln(d);
	}
#endif
	
	l_free(ac);
}
Beispiel #2
0
static void dl_iterator_test(void) {
    printsln((String)__func__);
    List ac;

    ac = dl_of_string("1, 2, 3, 4, 5");

    // various ways of iterating a list:

    ListIterator iter = l_iterator(ac);
    while (l_has_next(iter)) {
        double i = dl_next(&iter);
        printiln(i);
    }

    // DoubleListNode *first = (DoubleListNode*)ac->first;
    for (DoubleListNode *node = ac->first; node != NULL; node = node->next) {
        double d = node->value;
        printiln(d);
    }

#if 0
    while (iter = dl_next(iter)) {
        double d = dl_current(iter);
        printiln(d);
    }

    for (DoubleListIterator iter = dl_iterator(ac); dl_has_current(iter); iter = dl_next(iter)) {
        double d = dl_current(iter);
        printiln(d);
    }
#endif

    l_free(ac);
}
Beispiel #3
0
static void pl_choose_test(void) {
	printsln((Any)__func__);
	List l, ac, ex;
	l = sl_of_string("10, 2, 30, 4, 50, 6");
	printiln(l_element_size(l));
	printiln(sizeof(Any));
	ac = pl_choose(l, ends_width_0_append, "x");
	ex = sl_of_string("10x, 30x, 50x");
	sl_check_expect(ac, ex);
	sl_free(l);
	sl_free(ac);
	sl_free(ex);
}
Beispiel #4
0
int main() {
    char bigAssBuffer[BIGASSBUFFERSIZE];
    char* hello = "HTTP GET test";
    Extent screenSize, textSize;
    screenSize = maGetScrSize();

    //Draw centered text
    println("");
    textSize = maDrawText(0, 0, hello);
    maSetColor(0);
    maFillRect(0, 0, EXTENT_X(textSize), EXTENT_Y(textSize));  //erase test text
    maDrawText((EXTENT_X(screenSize) - EXTENT_X(textSize)) / 2, 0, hello);
    maUpdateScreen();

    println("Connecting...");
    int res = maHttpGet("link.astando.se"
                        "/guido/LvRouting.asmx/GenerateRouteGuido?fromX=100502&fromY=77476&toX=100591&toY=77368",
                        //"wap.mopix.se/test/test.comb",
                        bigAssBuffer, BIGASSBUFFERSIZE);

    printiln("Got %i bytes", res);
    println(bigAssBuffer);
    println("PAK to quit");

    PAKAndRelease();
    maExit(0);
}
Beispiel #5
0
void ia_test_all(void) {
	ia_create_test();
	ia_range_test();
	ia_of_string_test();
	ia_fn_test();
	ia_of_da_test();
	ia_contains_test();
	ia_fill_test();
	ia_fill_from_to_test();
	ia_index_test();
	ia_index_from_test();
	ia_index_fn_test();
	ia_last_index_test();
	ia_last_index_from_test();
	ia_last_index_fn_test();
	ia_sort_test();
	ia_sort_dec_test();
	ia_insert_test();
	ia_remove_test();
	ia_each_test();
	ia_each_state_test();
	ia_foldl_test();
	ia_foldr_test();
	ia_filter_test();
	// ia_filter_state_test();
	ia_choose_test();
	ia_exists_test();
	ia_forall_test();
	
#if 0
	Array a = ia_fn(20, ia_rnd, 5);
	ia_println(a);

	// get number of different numbers in array
	ia_sort(a);
	ia_println(a);
	int n = a_length(a);
	int k = (n > 0) ? 1 : 0;
	for (int i = 1; i < n; i++) {
		if (ia_get(a, i-1) != ia_get(a, i)) {
			k++;
		}
	}
	printiln(k);
	a_free(a);
#endif

#if 0
	// timing
	int n = 2000000000;
	Array a = ia_create(n, 0);
	time_function(   ia_fill_fn(a, fn_id)   );
	a_free(a);
	a = ia_create(n, 0);
	time_function(   ia_id(a)   );
	a_free(a);
#endif
	
}
// Iterate over the multiples of 3, from 30 down to 3.
// Output the square of each of these values.
// should only be called from repeat (or from itself)
void repeat_rec(int i) {
    if (i >= 3) {
        assert(i >= 3);
        // printiln(i); // for inspecting the iteration variable
        printiln(i * i);
        repeat_rec(i - 3); // function calls itself
                           // with another argument
    }
}
int main(void) {
	// Iterate over the multiples of 3, from 30 down to 3.
	// Output the square of each of these values.
	for (int i = 30; i >= 3; i = i - 3) {
	    assert(i >= 3);
	    assert(i <= 30);
	    // printiln(i); // for inspecting the iteration variable
	    printiln(i * i); // square the iterated values
	}
	return 0;
}
int main(void) {
    // every_other_test();
    // return 0;

    Array temps = ia_of_string(
                      "7, 6, 5, 6, 6, 5, 6, 6, 6, 7, 7, 9, 10,"
                      "11, 11, 12, 13, 12, 10, 9, 9, 8, 7, 4");
    ia_println(temps);
    printiln(a_length(temps));
    printiln(ia_get(temps, 0));
    printiln(ia_get(temps, 23));

    printsln("contains_negative_test:");
    contains_negative_test();

    printsln("every_other_test:");
    every_other_test();

    a_free(temps);
    return 0;
}
int main(void) {
	printiln(inc());
	printiln(inc());
	printiln(inc());
	return 0;
}