mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 02:23:20 +00:00
move manual tests to unit tests: checkpoint
This commit is contained in:
parent
25c964f7a2
commit
cc1ed4e33e
3 changed files with 33 additions and 15 deletions
|
|
@ -246,6 +246,7 @@ void* lhmslv_remove(lhmslv_t* pmap, slls_t* key) {
|
|||
void lhmslv_clear(lhmslv_t* pmap) {
|
||||
for (int i = 0; i < pmap->array_length; i++) {
|
||||
lhmslve_clear(&pmap->entries[i]);
|
||||
pmap->states[i] = EMPTY;
|
||||
}
|
||||
pmap->num_occupied = 0;
|
||||
pmap->num_freed = 0;
|
||||
|
|
@ -271,7 +272,7 @@ static void lhmslv_enlarge(lhmslv_t* pmap) {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void lhmslv_check_counts(lhmslv_t* pmap) {
|
||||
int lhmslv_check_counts(lhmslv_t* pmap) {
|
||||
int nocc = 0;
|
||||
int ndel = 0;
|
||||
for (int index = 0; index < pmap->array_length; index++) {
|
||||
|
|
@ -284,14 +285,15 @@ void lhmslv_check_counts(lhmslv_t* pmap) {
|
|||
fprintf(stderr,
|
||||
"occupancy-count mismatch: actual %d != cached %d\n",
|
||||
nocc, pmap->num_occupied);
|
||||
exit(1);
|
||||
return FALSE;
|
||||
}
|
||||
if (ndel != pmap->num_freed) {
|
||||
fprintf(stderr,
|
||||
"freed-count mismatch: actual %d != cached %d\n",
|
||||
ndel, pmap->num_freed);
|
||||
exit(1);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -49,4 +49,7 @@ void* lhmslv_remove(lhmslv_t* pmap, slls_t* key);
|
|||
void lhmslv_clear(lhmslv_t* pmap);
|
||||
int lhmslv_size(lhmslv_t* pmap);
|
||||
|
||||
// Unit-test hook
|
||||
int lhmslv_check_counts(lhmslv_t* pmap);
|
||||
|
||||
#endif // LHMSLV_H
|
||||
|
|
|
|||
|
|
@ -263,25 +263,38 @@ static char* test_lhms2v() {
|
|||
static char* test_lhmslv() {
|
||||
mu_assert_lf(0 == 0);
|
||||
|
||||
slls_t* ax = slls_alloc();
|
||||
slls_add_no_free(ax, "a");
|
||||
slls_add_no_free(ax, "x");
|
||||
// xxx assertions here
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
// xxx more assertions here
|
||||
lhmslv_t *pmap = lhmslv_alloc();
|
||||
mu_assert_lf(pmap->num_occupied == 0);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_put(pmap, ax, "3");
|
||||
mu_assert_lf(pmap->num_occupied == 1);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_put(pmap, ay, "5");
|
||||
mu_assert_lf(pmap->num_occupied == 2);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_put(pmap, ax, "4");
|
||||
mu_assert_lf(pmap->num_occupied == 2);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_put(pmap, bz, "7");
|
||||
mu_assert_lf(pmap->num_occupied == 3);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_remove(pmap, ay);
|
||||
mu_assert_lf(pmap->num_occupied == 2);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_clear(pmap);
|
||||
mu_assert_lf(pmap->num_occupied == 0);
|
||||
mu_assert_lf(lhmslv_check_counts(pmap));
|
||||
|
||||
lhmslv_free(pmap);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue