コード例 #1
0
ファイル: test_maps_and_sets.c プロジェクト: graydon/miller
// ----------------------------------------------------------------
static char* test_lhmslv() {
	mu_assert_lf(0 == 0);

	return NULL;
}
コード例 #2
0
ファイル: test_maps_and_sets.c プロジェクト: graydon/miller
// ----------------------------------------------------------------
static char* test_slls() {
	slls_t* plist = slls_from_line(strdup(""), ',', FALSE);
	mu_assert_lf(plist->length == 0);

	plist = slls_from_line(strdup("a"), ',', FALSE);
	mu_assert_lf(plist->length == 1);

	plist = slls_from_line(strdup("c,d,a,e,b"), ',', FALSE);
	mu_assert_lf(plist->length == 5);

	sllse_t* pe = plist->phead;

	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "c")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "d")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "a")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "e")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "b")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	slls_sort(plist);

	mu_assert_lf(plist->length == 5);
	pe = plist->phead;

	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "a")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "b")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "c")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "d")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->value, "e")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	return NULL;
}
コード例 #3
0
ファイル: test_maps_and_sets.c プロジェクト: graydon/miller
// ----------------------------------------------------------------
static char* test_lhms2v() {
	mu_assert_lf(0 == 0);

	lhms2v_t *pmap = lhms2v_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "x", "3");
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "y", "5");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "x", "4");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "b", "z", "7");
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_remove(pmap, "a", "y");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_clear(pmap);
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_free(pmap);

	return NULL;
}
コード例 #4
0
ファイル: test_maps_and_sets.c プロジェクト: graydon/miller
// ----------------------------------------------------------------
static char* test_hss() {

	hss_t *pset = hss_alloc();
	mu_assert_lf(pset->num_occupied == 0);

	hss_add(pset, "x");
	mu_assert_lf(pset->num_occupied == 1);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "y");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "x");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_add(pset, "z");
	mu_assert_lf(pset->num_occupied == 3);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(hss_has(pset, "y"));
	mu_assert_lf(hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_remove(pset, "y");
	mu_assert_lf(pset->num_occupied == 2);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_clear(pset);
	mu_assert_lf(!hss_has(pset, "w"));
	mu_assert_lf(!hss_has(pset, "x"));
	mu_assert_lf(!hss_has(pset, "y"));
	mu_assert_lf(!hss_has(pset, "z"));
	mu_assert_lf(hss_check_counts(pset));

	hss_free(pset);

	return NULL;
}
コード例 #5
0
ファイル: test_maps_and_sets.c プロジェクト: graydon/miller
// ----------------------------------------------------------------
static char* test_lhmsi() {
	mu_assert_lf(0 == 0);

	lhmsi_t *pmap = lhmsi_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(!lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "x", 3);
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "y", 5);
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "x", 4);
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_put(pmap, "z", 7);
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(lhmsi_has_key(pmap, "y"));
	mu_assert_lf(lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_remove(pmap, "y");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_clear(pmap);
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmsi_has_key(pmap, "w"));
	mu_assert_lf(!lhmsi_has_key(pmap, "x"));
	mu_assert_lf(!lhmsi_has_key(pmap, "y"));
	mu_assert_lf(!lhmsi_has_key(pmap, "z"));
	mu_assert_lf(lhmsi_check_counts(pmap));

	lhmsi_free(pmap);

	return NULL;
}
コード例 #6
0
// ----------------------------------------------------------------
static char* test_sllv() {

	sllv_t* pa = sllv_alloc();
	sllv_add(pa, "a");
	sllv_add(pa, "b");
	sllv_add(pa, "c");
	mu_assert_lf(pa->length == 3);

	sllve_t* pe = pa->phead;

	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "a")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "b")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "c")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	sllv_t* pb = sllv_alloc();
	sllv_add(pb, "d");
	sllv_add(pb, "e");
	mu_assert_lf(pb->length == 2);

	pe = pb->phead;

	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "d")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "e")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	pa = sllv_append(pa, pb);

	mu_assert_lf(pa->length == 5);
	mu_assert_lf(pb->length == 2);

	pe = pa->phead;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "a")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "b")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "c")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "d")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "e")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	pe = pb->phead;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "d")); pe = pe->pnext;
	mu_assert_lf(pe != NULL); mu_assert_lf(streq(pe->pvdata, "e")); pe = pe->pnext;
	mu_assert_lf(pe == NULL);

	return NULL;
}
コード例 #7
0
ファイル: test_parse_trie.c プロジェクト: olorin/miller
// ----------------------------------------------------------------
static char* test_dkvp() {
	char* test_name = "dkvp";
	char* strings[] = { "=" , ",", "\r\n", "\xff" };
	const int PS_TOKEN  = 0;
	const int FS_TOKEN  = 1;
	const int RS_TOKEN  = 2;
	const int EOF_TOKEN = 3;
	int num_strings = sizeof(strings) / sizeof(strings[0]);
	char* buf =
		"abc=123,def=456\r\n"
		"ghi=789\xff";
	char* p = buf;

	printf("%s %s\n", sep, test_name);
	int stridx, matchlen, rc;

	parse_trie_t* ptrie = parse_trie_alloc();
	parse_trie_print(ptrie);
	for (stridx = 0; stridx < num_strings; stridx++) {
		printf("Adding string[%d] = [%s]\n", stridx, strings[stridx]);
		parse_trie_add_string(ptrie, strings[stridx], stridx);
	}
	parse_trie_print(ptrie);

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == PS_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[PS_TOKEN]));
	p += matchlen;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == FS_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[FS_TOKEN]));
	p += matchlen;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == PS_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[PS_TOKEN]));
	p += matchlen;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == RS_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[RS_TOKEN]));
	p += matchlen;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == PS_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[PS_TOKEN]));
	p += matchlen;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;
	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen); mu_assert_lf(rc == FALSE); p++;

	rc = parse_trie_match(ptrie, p, 0, strlen(p), 0xff, &stridx, &matchlen);
	mu_assert_lf(rc == TRUE);
	mu_assert_lf(stridx == EOF_TOKEN);
	mu_assert_lf(matchlen == strlen(strings[EOF_TOKEN]));
	p += matchlen;

	return 0;
}
コード例 #8
0
// ----------------------------------------------------------------
static char* test_dheap() {

	dheap_t *pdheap = dheap_alloc();
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 0);

	dheap_add(pdheap, 4.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 1);

	dheap_add(pdheap, 3.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 2);

	dheap_add(pdheap, 2.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 3);

	dheap_add(pdheap, 6.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 4);

	dheap_add(pdheap, 5.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 5);

	dheap_add(pdheap, 8.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 6);

	dheap_add(pdheap, 7.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 7);

	dheap_print(pdheap);

	mu_assert_lf(dheap_remove(pdheap) == 8.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 6);

	mu_assert_lf(dheap_remove(pdheap) == 7.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 5);

	mu_assert_lf(dheap_remove(pdheap) == 6.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 4);

	mu_assert_lf(dheap_remove(pdheap) == 5.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 3);

	mu_assert_lf(dheap_remove(pdheap) == 4.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 2);

	mu_assert_lf(dheap_remove(pdheap) == 3.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 1);

	mu_assert_lf(dheap_remove(pdheap) == 2.25);
	mu_assert_lf(dheap_check(pdheap, __FILE__,  __LINE__));
	mu_assert_lf(pdheap->n == 0);

	dheap_free(pdheap);

	return NULL;
}
コード例 #9
0
// ----------------------------------------------------------------
static char* test_top_keeper() {
	int capacity = 3;

	top_keeper_t* ptop_keeper = top_keeper_alloc(capacity);
	mu_assert_lf(ptop_keeper->size == 0);

	top_keeper_add(ptop_keeper, 5.0, NULL);
	top_keeper_print(ptop_keeper);
	mu_assert_lf(ptop_keeper->size == 1);
	mu_assert_lf(ptop_keeper->top_values[0] == 5.0);

	top_keeper_add(ptop_keeper, 6.0, NULL);
	top_keeper_print(ptop_keeper);
	mu_assert_lf(ptop_keeper->size == 2);
	mu_assert_lf(ptop_keeper->top_values[0] == 6.0);
	mu_assert_lf(ptop_keeper->top_values[1] == 5.0);

	top_keeper_add(ptop_keeper, 4.0, NULL);
	top_keeper_print(ptop_keeper);
	mu_assert_lf(ptop_keeper->size == 3);
	mu_assert_lf(ptop_keeper->top_values[0] == 6.0);
	mu_assert_lf(ptop_keeper->top_values[1] == 5.0);
	mu_assert_lf(ptop_keeper->top_values[2] == 4.0);

	top_keeper_add(ptop_keeper, 2.0, NULL);
	top_keeper_print(ptop_keeper);
	mu_assert_lf(ptop_keeper->size == 3);
	mu_assert_lf(ptop_keeper->top_values[0] == 6.0);
	mu_assert_lf(ptop_keeper->top_values[1] == 5.0);
	mu_assert_lf(ptop_keeper->top_values[2] == 4.0);

	top_keeper_add(ptop_keeper, 7.0, NULL);
	top_keeper_print(ptop_keeper);
	mu_assert_lf(ptop_keeper->size == 3);
	mu_assert_lf(ptop_keeper->top_values[0] == 7.0);
	mu_assert_lf(ptop_keeper->top_values[1] == 6.0);
	mu_assert_lf(ptop_keeper->top_values[2] == 5.0);

	top_keeper_free(ptop_keeper);
	return NULL;
}
コード例 #10
0
// ----------------------------------------------------------------
static char* test_lhmslv() {

	slls_t* aw = slls_alloc(); slls_add_no_free(aw, "a"); slls_add_no_free(aw, "w");
	slls_t* ax = slls_alloc(); slls_add_no_free(ax, "a"); slls_add_no_free(ax, "x");
	slls_t* ay = slls_alloc(); slls_add_no_free(ay, "a"); slls_add_no_free(ay, "y");
	slls_t* bz = slls_alloc(); slls_add_no_free(bz, "b"); slls_add_no_free(bz, "z");

	lhmslv_t *pmap = lhmslv_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, ax)); mu_assert_lf(lhmslv_get(pmap, ax) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, ay)); mu_assert_lf(lhmslv_get(pmap, ay) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, bz)); mu_assert_lf(lhmslv_get(pmap, bz) == NULL);
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_put(pmap, ax, "3");
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, ax)); mu_assert_lf(streq(lhmslv_get(pmap, ax), "3"));
	mu_assert_lf(!lhmslv_has_key(pmap, ay)); mu_assert_lf(lhmslv_get(pmap, ay) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, bz)); mu_assert_lf(lhmslv_get(pmap, bz) == NULL);
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_put(pmap, ay, "5");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, ax)); mu_assert_lf(streq(lhmslv_get(pmap, ax), "3"));
	mu_assert_lf( lhmslv_has_key(pmap, ay)); mu_assert_lf(streq(lhmslv_get(pmap, ay), "5"));
	mu_assert_lf(!lhmslv_has_key(pmap, bz)); mu_assert_lf(lhmslv_get(pmap, bz) == NULL);
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_put(pmap, ax, "4");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, ax)); mu_assert_lf(streq(lhmslv_get(pmap, ax), "4"));
	mu_assert_lf( lhmslv_has_key(pmap, ay)); mu_assert_lf(streq(lhmslv_get(pmap, ay), "5"));
	mu_assert_lf(!lhmslv_has_key(pmap, bz)); mu_assert_lf(lhmslv_get(pmap, bz) == NULL);
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_put(pmap, bz, "7");
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, ax)); mu_assert_lf(streq(lhmslv_get(pmap, ax), "4"));
	mu_assert_lf( lhmslv_has_key(pmap, ay)); mu_assert_lf(streq(lhmslv_get(pmap, ay), "5"));
	mu_assert_lf( lhmslv_has_key(pmap, bz)); mu_assert_lf(streq(lhmslv_get(pmap, bz), "7"));
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_remove(pmap, ay);
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, ax)); mu_assert_lf(streq(lhmslv_get(pmap, ax), "4"));
	mu_assert_lf(!lhmslv_has_key(pmap, ay)); mu_assert_lf(lhmslv_get(pmap, ay) == NULL);
	mu_assert_lf( lhmslv_has_key(pmap, bz)); mu_assert_lf(streq(lhmslv_get(pmap, bz), "7"));
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_clear(pmap);
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhmslv_has_key(pmap, aw)); mu_assert_lf(lhmslv_get(pmap, aw) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, ax)); mu_assert_lf(lhmslv_get(pmap, ax) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, ay)); mu_assert_lf(lhmslv_get(pmap, ay) == NULL);
	mu_assert_lf(!lhmslv_has_key(pmap, bz)); mu_assert_lf(lhmslv_get(pmap, bz) == NULL);
	mu_assert_lf(lhmslv_check_counts(pmap));

	lhmslv_free(pmap);

	return NULL;
}
コード例 #11
0
// ----------------------------------------------------------------
static char* test_lhms2v() {

	lhms2v_t *pmap = lhms2v_alloc();
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(lhms2v_get(pmap, "a", "x") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(lhms2v_get(pmap, "a", "y") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(lhms2v_get(pmap, "b", "z") == NULL);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "x", "3");
	mu_assert_lf(pmap->num_occupied == 1);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "x"), "3"));
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(lhms2v_get(pmap, "a", "y") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(lhms2v_get(pmap, "b", "z") == NULL);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "y", "5");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "x"), "3"));
	mu_assert_lf( lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "y"), "5"));
	mu_assert_lf(!lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(lhms2v_get(pmap, "b", "z") == NULL);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "a", "x", "4");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "x"), "4"));
	mu_assert_lf( lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "y"), "5"));
	mu_assert_lf(!lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(lhms2v_get(pmap, "b", "z") == NULL);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_put(pmap, "b", "z", "7");
	mu_assert_lf(pmap->num_occupied == 3);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "x"), "4"));
	mu_assert_lf( lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "y"), "5"));
	mu_assert_lf( lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(streq(lhms2v_get(pmap, "b", "z"), "7"));
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_remove(pmap, "a", "y");
	mu_assert_lf(pmap->num_occupied == 2);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(streq(lhms2v_get(pmap, "a", "x"), "4"));
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(lhms2v_get(pmap, "a", "y") == NULL);
	mu_assert_lf( lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(streq(lhms2v_get(pmap, "b", "z"), "7"));
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_clear(pmap);
	mu_assert_lf(pmap->num_occupied == 0);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "w")); mu_assert_lf(lhms2v_get(pmap, "a", "w") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "x")); mu_assert_lf(lhms2v_get(pmap, "a", "x") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "a", "y")); mu_assert_lf(lhms2v_get(pmap, "a", "y") == NULL);
	mu_assert_lf(!lhms2v_has_key(pmap, "b", "z")); mu_assert_lf(lhms2v_get(pmap, "b", "z") == NULL);
	mu_assert_lf(lhms2v_check_counts(pmap));

	lhms2v_free(pmap);

	return NULL;
}
コード例 #12
0
ファイル: test_argparse.c プロジェクト: 0-wiz-0/miller
static char * test2() {
	int     bflag1 = -4;
	int     bflag2 = -5;
	int     intv1  = -6;
	int     intv2  = -7;
	int     intv3  = -8;
	double  dblv   = -9.5;
	char*   string = NULL;
	slls_t* plist  = NULL;
	ap_state_t* pstate = ap_alloc();

	ap_define_true_flag(pstate,        "-t",   &bflag1);
	ap_define_false_flag(pstate,       "-f",   &bflag2);
	ap_define_int_value_flag(pstate,   "-100", 100, &intv1);
	ap_define_int_value_flag(pstate,   "-200", 200, &intv2);
	ap_define_int_flag(pstate,         "-i",   &intv3);
	ap_define_double_flag(pstate,      "-d",   &dblv);
	ap_define_string_flag(pstate,      "-s",   &string);
	ap_define_string_list_flag(pstate, "-S",   &plist);

	char* argv[] = {
		"test-verb",
		"-t",
		"-f",
		"-100",
		"-200",
		"-i", "555",
		"-d", "4.25",
		"-s", "hello",
		"-S", strdup("a,b,c,d,e"),
		"do", "re", "mi",
		NULL
	};
	int argc = compute_argc(argv);
	char* verb = argv[0];
	int argi = 1;
	mu_assert_lf(ap_parse(pstate, verb, &argi, argc, argv) == TRUE);
	mu_assert_lf(bflag1 == TRUE);
	mu_assert_lf(bflag2 == FALSE);
	mu_assert_lf(intv1 == 100);
	mu_assert_lf(intv2 == 200);
	mu_assert_lf(intv3 == 555);
	mu_assert_lf(dblv == 4.25);
	mu_assert_lf(string != NULL);
	mu_assert_lf(streq(string, "hello"));
	mu_assert_lf(plist != NULL);
	mu_assert_lf(slls_equals(plist, slls_from_line(strdup("a,b,c,d,e"), ',', FALSE)));
	mu_assert_lf(argi == 13);

	ap_free(pstate);
	return 0;
}