Esempio n. 1
0
// ----------------------------------------------------------------
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;
}
Esempio n. 2
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;
}