예제 #1
0
파일: test_fss.c 프로젝트: PGer/pipelinedb
END_TEST

START_TEST(test_merge)
{
	TypeCacheEntry *typ = get_int8_type();
	FSS *fss1 = FSSCreate(K, typ);
	FSS *fss2 = FSSCreate(K, typ);
	int i, j;
	Datum *values1, *values2;
	uint64_t *freqs1, *freqs2;
	int soft_errors;

	for (j = 0; j < 10; j++)
	{
		FSS *tmp = FSSCreate(K, typ);

		for (i = 0; i < NUM_ITEMS; i++)
		{
			int value = 10 * gaussian();
			value %= 500;
			FSSIncrement(fss1, value);
			FSSIncrement(tmp, value);
			assert_sorted(fss1);
			assert_sorted(tmp);
		}

		fss2 = FSSMerge(fss2, tmp);
		FSSDestroy(tmp);
	}

	values1 = FSSTopK(fss1, K, NULL);
	freqs1 = FSSTopKCounts(fss1, K, NULL);
	values2 = FSSTopK(fss2, K, NULL);
	freqs2 = FSSTopKCounts(fss2, K, NULL);
	soft_errors = 0;

	for (i = 0; i < 10; i++)
	{
		int value1 = values1[i];
		int value2 = values2[i];

		ck_assert(value1 == value2);

		if (abs(freqs1[i] - freqs2[i]) > 10)
			soft_errors++;
	}

	ck_assert(soft_errors < 3);
}
예제 #2
0
void test_descending() {
  int i;
  for(i = 0; i < MAXN; i++)
    A[i] = -i;
  merge_sort(A, 0, MAXN, T);
  assert_sorted();
}
예제 #3
0
void test_random() {
  int i;
  for(i = 0; i < MAXN; i++)
    A[i] = (double)rand() / RAND_MAX * 1000000000;
  merge_sort(A, 0, MAXN, T);
  assert_sorted();
}
예제 #4
0
파일: test.c 프로젝트: gcms/gustavo
int main() {
    int i;
    Date *orig, *tosort;

    orig = malloc(SIZE * sizeof(Date));

    srand(time(NULL) + clock());

    for (i = 0; i < SIZE; i++) {
        orig[i].year = rand() % 1000 + 1000;
        orig[i].month = rand() % 12 + 1;
        orig[i].day = rand() % 30 + 1;
    }

    tosort = malloc(SIZE * sizeof(Date));

    memcpy(tosort, orig, sizeof(Date) * SIZE);
    run_sort(tosort, SIZE, sizeof(Date), myfunc, insertionsort, "insertionsort");
    assert_sorted(tosort, SIZE, sizeof(Date), myfunc);

    memcpy(tosort, orig, sizeof(Date) * SIZE);
    run_sort(tosort, SIZE, sizeof(Date), myfunc, mergesort_, "mergesort_");
    assert_sorted(tosort, SIZE, sizeof(Date), myfunc);

    memcpy(tosort, orig, sizeof(Date) * SIZE);
    run_sort(tosort, SIZE, sizeof(Date), myfunc, bubblesort, "bubblesort");
    assert_sorted(tosort, SIZE, sizeof(Date), myfunc);

    memcpy(tosort, orig, sizeof(Date) * SIZE);
    run_sort(tosort, SIZE, sizeof(Date), myfunc, quicksort, "quicksort");
    assert_sorted(tosort, SIZE, sizeof(Date), myfunc);

    memcpy(tosort, orig, sizeof(Date) * SIZE);
    run_sort(tosort, SIZE, sizeof(Date), myfunc, shellsort, "shellsort");
    assert_sorted(tosort, SIZE, sizeof(Date), myfunc);

    /*
    for (i = 0; i < 1000; i++) {
        printf("%02d/%02d/%04d\n", orig[i].day, orig[i].month, orig[i].year);
    }
    */

    return 0;
}
예제 #5
0
파일: test_fss.c 프로젝트: PGer/pipelinedb
END_TEST

START_TEST(test_weighted)
{
	TypeCacheEntry *typ = get_int8_type();
	FSS *fss = FSSCreate(K, typ);
	int i;
	int *counts = palloc0(sizeof(uint64_t) * 1000);
	Datum *values;
	uint64_t *freqs;
	int min_freq = NUM_ITEMS / fss->m;

	for (i = 0; i <= min_freq; i++)
	{
		FSSIncrementWeighted(fss, 1, 10);
		FSSIncrementWeighted(fss, 2, 20);
		FSSIncrementWeighted(fss, 3, 30);
		counts[1] += 10;
		counts[2] += 20;
		counts[3] += 30;
		assert_sorted(fss);
	}

	for (i = 0; i < NUM_ITEMS - (2 * min_freq); i++)
	{
		int value = (int) uniform() % 500 + 4;
		FSSIncrementWeighted(fss, value, 1);
		counts[value]++;
		assert_sorted(fss);
	}

	values = FSSTopK(fss, K, NULL);
	freqs = FSSTopKCounts(fss, K, NULL);

	for (i = 0; i < 3; i++)
	{
		int value = values[i];
		ck_assert(value == 1 || value == 2 || value == 3);
		ck_assert(abs(freqs[i] - counts[value]) == 0);
	}
}