diff options
Diffstat (limited to 'simclist-1.5/regrtest')
| -rw-r--r-- | simclist-1.5/regrtest/._printlist.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/._test1.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/._test2.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/._test3-dump.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/._test3-restore.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/._test4-seeker.c | bin | 0 -> 229 bytes | |||
| -rw-r--r-- | simclist-1.5/regrtest/printlist.c | 11 | ||||
| -rw-r--r-- | simclist-1.5/regrtest/test1.c | 120 | ||||
| -rw-r--r-- | simclist-1.5/regrtest/test2.c | 75 | ||||
| -rw-r--r-- | simclist-1.5/regrtest/test3-dump.c | 57 | ||||
| -rw-r--r-- | simclist-1.5/regrtest/test3-restore.c | 64 | ||||
| -rw-r--r-- | simclist-1.5/regrtest/test4-seeker.c | 53 |
12 files changed, 380 insertions, 0 deletions
diff --git a/simclist-1.5/regrtest/._printlist.c b/simclist-1.5/regrtest/._printlist.c Binary files differnew file mode 100644 index 0000000..041f2c1 --- /dev/null +++ b/simclist-1.5/regrtest/._printlist.c diff --git a/simclist-1.5/regrtest/._test1.c b/simclist-1.5/regrtest/._test1.c Binary files differnew file mode 100644 index 0000000..95f06ce --- /dev/null +++ b/simclist-1.5/regrtest/._test1.c diff --git a/simclist-1.5/regrtest/._test2.c b/simclist-1.5/regrtest/._test2.c Binary files differnew file mode 100644 index 0000000..0866fd9 --- /dev/null +++ b/simclist-1.5/regrtest/._test2.c diff --git a/simclist-1.5/regrtest/._test3-dump.c b/simclist-1.5/regrtest/._test3-dump.c Binary files differnew file mode 100644 index 0000000..d6eacff --- /dev/null +++ b/simclist-1.5/regrtest/._test3-dump.c diff --git a/simclist-1.5/regrtest/._test3-restore.c b/simclist-1.5/regrtest/._test3-restore.c Binary files differnew file mode 100644 index 0000000..b97c3f5 --- /dev/null +++ b/simclist-1.5/regrtest/._test3-restore.c diff --git a/simclist-1.5/regrtest/._test4-seeker.c b/simclist-1.5/regrtest/._test4-seeker.c Binary files differnew file mode 100644 index 0000000..02a536f --- /dev/null +++ b/simclist-1.5/regrtest/._test4-seeker.c diff --git a/simclist-1.5/regrtest/printlist.c b/simclist-1.5/regrtest/printlist.c new file mode 100644 index 0000000..bb4d0c7 --- /dev/null +++ b/simclist-1.5/regrtest/printlist.c @@ -0,0 +1,11 @@ +#include <stdio.h> + + +void printlist(list_t *l) { + int i; + + for (i = 0; i < list_size(l); i++) { + printf ("> %d\n", *(int *)list_get_at(l, i)); + } +} + diff --git a/simclist-1.5/regrtest/test1.c b/simclist-1.5/regrtest/test1.c new file mode 100644 index 0000000..3b93056 --- /dev/null +++ b/simclist-1.5/regrtest/test1.c @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <assert.h> +#include "../simclist.h" + +#include "printlist.c" + +#define N 250 + +#undef NDEBUG + +int main() { + list_t tl, tl2, tl3; + unsigned int pos; + int el, el2, i; + list_hash_t lhash1, lhash2; + + + list_init(&tl); + assert(list_size(&tl) == 0); + + printf("1\n"); + + lhash1 = list_hash(&tl); + + /* attributes */ + list_attributes_copy(&tl, list_meter_int32_t, 1); + list_attributes_comparator(&tl, list_comparator_int32_t); + list_attributes_hash_computer(&tl, list_hashcomputer_int32_t); + + /* insertion */ + srandom(time(NULL)); + printf("Inserting at: "); + for (i = 0; i < N; i++) { + pos = random() % (list_size(&tl) + 1); + printf("%u ", pos); + list_insert_at(&tl, &i, pos); + } + printf("\nDone.\n"); + assert(list_size(&tl) == N); + + /* min/max */ + printf("2\n"); + assert(*(int *)list_get_max(&tl) == N-1); + printf("3\n"); + assert(*(int *)list_get_min(&tl) == 0); + printf("4\n"); + + /* incorrect deletion */ + assert(list_insert_at(&tl, &el, N+1) < 0); + printf("5\n"); + assert(list_delete_at(&tl, N) < 0); + printf("6\n"); + assert(list_delete_range(&tl, 0, N+1) < 0); + printf("7\n"); + assert(list_delete_range(&tl, N, N/2) < 0); + + /* hashes */ + printf("8\n"); + lhash2 = list_hash(&tl); + assert(lhash2 != lhash1); + + /* find and contains */ + printf("9\n"); + el = N-1; + assert(list_contains(&tl, &el)); + + /* sorting */ + printf("10\n"); + list_sort(&tl, 1); + + /* iteration sessions */ + el2 = el = -1; + list_iterator_start(&tl); + while (list_iterator_hasnext(&tl)) { + el2 = *(int *)list_iterator_next(&tl); + if (el > el2) + break; + el = el2; + } + list_iterator_stop(&tl); + assert(el2 == N-1); + + /* legal deletion */ + printf("11\n"); + list_delete_range(&tl, 0, N/2); + assert(list_size(&tl) == (N-1)/2); + assert(*(int *)list_get_at(&tl, 0) == (N/2 +1)); + + /* concatenation, and hashes */ + printf("12\n"); + lhash1 = list_hash(&tl); + assert(lhash1 != lhash2); + + printf("13\n"); + list_init(&tl2); /* tl2 empty */ + list_concat(&tl, &tl2, &tl3); + list_attributes_hash_computer(&tl3, list_hashcomputer_int32_t); + assert(list_hash(&tl) == list_hash(&tl3)); + + printf("14\n"); + list_destroy(&tl3); + list_concat(&tl2, &tl, &tl3); + list_attributes_hash_computer(&tl3, list_hashcomputer_int32_t); + assert(list_hash(&tl) == list_hash(&tl3)); + + printf("15\n"); + list_delete_range(&tl3, 1, list_size(&tl3)-2); + el = 123; + list_append(&tl3, &el); + assert(list_size(&tl3) == 3 && list_find(&tl3, &el) == (list_size(&tl3)-1)); + + + list_destroy(&tl); + + printf("==========\nAll tests passed.\n"); + return 0; +} + diff --git a/simclist-1.5/regrtest/test2.c b/simclist-1.5/regrtest/test2.c new file mode 100644 index 0000000..a92c114 --- /dev/null +++ b/simclist-1.5/regrtest/test2.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <assert.h> + +#include "../simclist.h" + +#include "printlist.c" + +#define N 250 + +int main() { + list_t l; + int i, j, newpos, els[N]; + + srandom(time(NULL)); + list_init(&l); + + list_attributes_copy(&l, list_meter_int32_t, 1); + list_attributes_comparator(&l, list_comparator_int32_t); + + /* insert N zeros */ + printf("Test 1: head insertions ... "); + fflush(stdout); + j = 0; + for (i = 0; i < N; i++) { + list_insert_at(&l, &j, 0); + assert((int)list_size(&l) == i+1); + } + //list_clear(&l); + printf("passed.\n"); + + /* generate an unsorted list of values from 0 to N */ + printf("Test 2: random insertions and deletions ... "); + fflush(stdout); + els[0] = 0; + for (i = 1; i < N; i++) { + els[i] = i; + newpos = random() % (i + 1); + j = els[newpos]; + els[newpos] = i; + els[i] = j; + } + + for (i = 0; i < N; i++) { + list_insert_at(&l, & els[i], els[i]); + assert(*(int *)list_get_at(&l, els[i]) == els[i]); + assert(*(int *)list_get_at(&l, els[i]+1) == 0); + list_delete_range(&l, els[i]+1, els[i]+1); + } + printf("passed.\n"); + + printf("Test 3: positioning (The Revenge) ... "); + fflush(stdout); + for (i = 0; i < N; i++) { + assert(*(int *)list_get_at(&l, i) == i); + } + printf("passed.\n"); + + + printf("Test 4: sorting ... "); + fflush(stdout); + assert(list_sort(&l, -1) == 0); + for (i = 0; i < N; i++) { + assert(*(int *)list_get_at(&l, i) == N-1-i); + } + printf("passed.\n"); + + list_destroy(&l); + + printf("==========\nAll tests passed.\n"); + + return 0; +} + diff --git a/simclist-1.5/regrtest/test3-dump.c b/simclist-1.5/regrtest/test3-dump.c new file mode 100644 index 0000000..667b119 --- /dev/null +++ b/simclist-1.5/regrtest/test3-dump.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include "../simclist.h" + +#define N 123 + +#define hton64(x) (\ + htons(1) == 1 ? \ + (uint64_t)x /* big endian */ \ + : /* little endian */ \ + ((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \ + (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \ + (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \ + (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \ + (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \ + (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \ + (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \ + (((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \ + ) + + +size_t meter(const void *el) { + return sizeof(unsigned long long int); +} + +void *elserial(const void *el, uint32_t *len) { + unsigned long long *x; + + *len = sizeof(unsigned long long); + x = malloc(*len); + *x = hton64(*(unsigned long long *)el); + + return x; +} + +int main() { + list_t l; + unsigned long long int data; + + list_init(& l); + list_attributes_copy(&l, meter, 1); + list_attributes_serializer(&l, elserial); + + for (data = 1; data < N; data++) { + list_append(& l, & data); + } + if (list_dump_file(&l, "mylistdump.simc") == 0 && errno != 0) { + printf("fuck off\n"); + } + + list_destroy(& l); + + return 0; +} + diff --git a/simclist-1.5/regrtest/test3-restore.c b/simclist-1.5/regrtest/test3-restore.c new file mode 100644 index 0000000..6e143f6 --- /dev/null +++ b/simclist-1.5/regrtest/test3-restore.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <sys/types.h> +#include "../simclist.h" + +#define N 123 + +#define hton64(x) (\ + htons(1) == 1 ? \ + (uint64_t)x /* big endian */ \ + : /* little endian */ \ + ((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \ + (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \ + (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \ + (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \ + (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \ + (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \ + (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \ + (((uint64_t)(x) & 0x00000000000000ffULL) << 56))) \ + ) + + +void *elunserial(const void *el, uint32_t *len) { + unsigned long long *x; + + *len = sizeof(unsigned long long); + x = malloc(*len); + *x = hton64(*(unsigned long long *)el); + + return x; +} + +int main() { + list_t l; + unsigned long long int data, val; + unsigned int mem; + + list_init(& l); + list_attributes_unserializer(&l, elunserial); + + mem = list_restore_file(&l, "mylistdump.simc"); + if (mem == 0 && errno != 0) { + perror("open"); + printf("fuck off\n"); + } else { + printf("Restored successfully:\n"); + printf("N els: %u\nmemread: %u\n", list_size(&l), mem); + for (data = 1; data < N; data++) { + val = *(unsigned long long *)list_get_at(&l, (unsigned int)data-1); + if (data != val) { + printf("Wrong data. Pos %llu, expected %llu, got %llu\n", data-1, data, val); + return 0; + } + printf("%lld ", val); + } + printf("\n"); + } + + list_destroy(& l); + + return 0; +} + diff --git a/simclist-1.5/regrtest/test4-seeker.c b/simclist-1.5/regrtest/test4-seeker.c new file mode 100644 index 0000000..4b4b64a --- /dev/null +++ b/simclist-1.5/regrtest/test4-seeker.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> /* for srandom() */ +#include "../simclist.h" + +#define N 100000 +#define LEN 12 + +struct foo_s { + int a, b; + char c[LEN]; +}; + +int seeker(const void *el, const void *indicator) { + if (((struct foo_s *)el)->a == *(int *)indicator) + return 1; + return 0; +} + +size_t mymeter(const void *el) { + return (sizeof(struct foo_s)); +} + +int main() { + list_t l; + struct foo_s el; + int i, j; + + list_init(& l); + list_attributes_seeker(&l, seeker); + list_attributes_copy(&l, mymeter, 1); + + for (i = 0; i < N; i++) { + el.a = i; + el.b = 3*i; + snprintf(el.c, LEN, "%d-%d", el.a, el.b); + list_insert_at(& l, & el, i); + } + + srandom(time(NULL)); + + for (i = 0; i < N/4; i++) { + j = random() % list_size(&l); + el = *(struct foo_s *)list_seek(&l, &j); + if (el.a != j) { + printf("KO: %d retrieved %d\n", j, el.a); + return 1; + } + } + + list_destroy(& l); + return 0; +} |
