static void test(void) { tap_plan(0); tap_plan(1); tap_plan(2); tap_skip_all(NULL); tap_skip_all("foo %s", "bar"); tap_skip(0, NULL); tap_skip(1, "foo %s", "bar"); tap_skip(2, NULL); tap_diag("foo"); tap_diag("foo %s", "bar"); tap_bail(NULL); tap_bail("foo %s", "bar"); tap_ok(0, NULL); tap_ok(1, NULL); tap_ok(0, "%s", "foo"); tap_ok(1, "%s", "foo"); tap_is_str("foo", "foo", NULL); tap_is_str("foo", "bar", NULL); tap_is_str("foo", "foo", "foo %s", "bar"); tap_is_str("foo", "bar", "foo %s", "bar"); tap_is_str(NULL, NULL, NULL); tap_is_str(NULL, "bar", NULL); tap_is_int(1, 1, NULL); tap_is_int(1, 0, NULL); tap_is_int(1, 1, "foo %s", "bar"); tap_is_int(1, 0, "foo %s", "bar"); tap_is_float(1.0, 1.0, 0.1, NULL); tap_is_float(1.0, 2.0, 0.1, NULL); tap_is_float(1.0, 1.0, 0.1, "foo %s", "bar"); tap_is_float(1.0, 2.0, 0.1, "foo %s", "bar"); tap_done_testing(); }
int main(void) { pu_log_action_t *a; tap_plan(31); tap_ok((a = pu_log_action_parse("installed pacutils (1.0.0)")) != NULL, "install"); tap_is_int(a->operation, PU_LOG_OPERATION_INSTALL, "operation"); tap_is_str(a->target, "pacutils", "package"); tap_is_str(a->new_version, "1.0.0", "new_version"); tap_is_str(a->old_version, NULL, "old_version"); pu_log_action_free(a); tap_ok((a = pu_log_action_parse("upgraded pacutils (1.0.0 -> 2.0.0)")) != NULL, "upgrade"); tap_is_int(a->operation, PU_LOG_OPERATION_UPGRADE, "operation"); tap_is_str(a->target, "pacutils", "package"); tap_is_str(a->new_version, "2.0.0", "new_version"); tap_is_str(a->old_version, "1.0.0", "old_version"); pu_log_action_free(a); tap_ok((a = pu_log_action_parse("downgraded pacutils (2.0.0 -> 1.0.0)")) != NULL, "downgrade"); tap_is_int(a->operation, PU_LOG_OPERATION_DOWNGRADE, "operation"); tap_is_str(a->target, "pacutils", "package"); tap_is_str(a->new_version, "1.0.0", "new_version"); tap_is_str(a->old_version, "2.0.0", "old_version"); pu_log_action_free(a); tap_ok((a = pu_log_action_parse("reinstalled pacutils (1.0.0)")) != NULL, "reinstall"); tap_is_int(a->operation, PU_LOG_OPERATION_REINSTALL, "operation"); tap_is_str(a->target, "pacutils", "package"); tap_is_str(a->new_version, "1.0.0", "new_version"); tap_is_str(a->old_version, "1.0.0", "old_version"); pu_log_action_free(a); tap_ok((a = pu_log_action_parse("removed pacutils (1.0.0)")) != NULL, "removed"); tap_is_int(a->operation, PU_LOG_OPERATION_REMOVE, "operation"); tap_is_str(a->target, "pacutils", "package"); tap_is_str(a->new_version, NULL, "new_version"); tap_is_str(a->old_version, "1.0.0", "old_version"); pu_log_action_free(a); tap_ok(pu_log_action_parse("") == NULL, "empty input"); tap_is_int(errno, EINVAL, "errno"); tap_ok(pu_log_action_parse(NULL) == NULL, "NULL input"); tap_is_int(errno, EINVAL, "errno"); tap_ok(pu_log_action_parse("not a valid action") == NULL, "invalid input"); tap_is_int(errno, EINVAL, "errno"); return tap_finish(); }
int main() { tap_plan(11); tap_ok(1==1, "1==1"); tap_not_ok(1==2, "1==2"); tap_is(1, 1, "1 is 1"); tap_is('a', 'a', "'a' is 'a'"); tap_is(4.0, 4.0, "4.0 is 4.0"); tap_isnt(1, 2, "1 isn't 2"); tap_isnt('a', 'b', "'a' isn't 'b'"); tap_isnt(2.0, 4.0, "2.0 isn't 4.0"); tap_like("foobar", "^foo", REG_EXTENDED, "\"foobar\" is like \"^foo\""); tap_unlike("foobar", "foo$", REG_EXTENDED, "\"foobar\" is unlike \"foo$\""); tap_pass("just passing"); return tap_status(); }
int main() { fgraph_heap_t *heap = 0; fgraph_return_t res = 0; unsigned long ulval = 0, *pulval = 0; tap_plan(48); res = fgraph_heap_init(&heap, 10); tap_ok(res == FGRAPH_SUCCESS, "heap inited ok"); tap_ok(heap != 0, "heap not null"); res = fgraph_heap_init(&heap, 20); tap_ok(res == FGRAPH_EINITED, "heap already inited"); res = fgraph_heap_max(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "max returned ok"); tap_ok(ulval == 9, "max-key is 9"); res = fgraph_heap_insert(&heap, 0, 10); tap_ok(res == FGRAPH_SUCCESS, "value added ok"); res = fgraph_heap_insert(&heap, 20, 3); tap_ok(res == FGRAPH_EBOUNDS, "value not added, out of bounds"); res = fgraph_heap_size(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "heap size returned ok"); tap_ok(ulval == 1, "heap size is 1"); res = fgraph_heap_insert(&heap, 1, 8); tap_ok(res == FGRAPH_SUCCESS, "value added ok"); res = fgraph_heap_insert(&heap, 2, 6); tap_ok(res == FGRAPH_SUCCESS, "value added ok"); res = fgraph_heap_insert(&heap, 2, 20); tap_ok(res == FGRAPH_EEXISTS, "key exists"); res = fgraph_heap_insert(&heap, 3, 20); tap_ok(res == FGRAPH_SUCCESS, "value added ok"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "value removed ok"); tap_ok(ulval == 2, "min-key is 2"); res = fgraph_heap_decrease(&heap, 3, 4); tap_ok(res == FGRAPH_SUCCESS, "key decreased ok"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "value removed ok"); tap_ok(ulval == 3, "min-key is 3"); res = fgraph_heap_size(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "size returned ok"); tap_ok(ulval == 2, "size is 2"); res = fgraph_heap_clear(&heap); tap_ok(res == FGRAPH_SUCCESS, "heap cleared ok"); tap_ok(heap == 0, "heap is null"); res = fgraph_heap_insert(&heap, 2, 2); tap_ok(res == FGRAPH_ENULL, "heap is null"); res = fgraph_heap_decrease(&heap, 2, 10); tap_ok(res == FGRAPH_ENULL, "heap is null"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_ENULL, "heap is null"); res = fgraph_heap_size(&heap, &ulval); tap_ok(res == FGRAPH_ENULL, "heap is null"); res = fgraph_heap_max(&heap, &ulval); tap_ok(res == FGRAPH_ENULL, "heap is null"); res = fgraph_heap_init(&heap, 4); tap_ok(res == FGRAPH_SUCCESS, "heap inited ok"); tap_ok(heap != 0, "heap not null"); res = fgraph_heap_insert(&heap, 0, 32); tap_ok(res == FGRAPH_SUCCESS, "inserted (0,32) ok"); res = fgraph_heap_insert(&heap, 1, 4); tap_ok(res == FGRAPH_SUCCESS, "inserted (1,4) ok"); res = fgraph_heap_insert(&heap, 2, 10); tap_ok(res == FGRAPH_SUCCESS, "inserted (2,10) ok"); res = fgraph_heap_insert(&heap, 3, 25); tap_ok(res == FGRAPH_SUCCESS, "inserted (3,25) ok"); res = fgraph_heap_insert(&heap, 4, 36); tap_ok(res == FGRAPH_EBOUNDS, "out of bounds"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "removed ok"); tap_ok(ulval == 1, "min-key is 1"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "removed ok"); tap_ok(ulval == 2, "min-key is 2"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "removed ok"); tap_ok(ulval == 3, "min-key is 3"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_SUCCESS, "removed ok"); tap_ok(ulval == 0, "min-key is 0"); res = fgraph_heap_remove(&heap, &ulval); tap_ok(res == FGRAPH_EEMPTY, "heap is empty"); res = fgraph_heap_max(&heap, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_heap_remove(&heap, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_heap_size(&heap, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_heap_clear(&heap); tap_ok(res == FGRAPH_SUCCESS, "cleared ok"); tap_ok(heap == 0, "heap is null"); return tap_status(); }
int main(int argc, char **argv) { tap_n((3+5)*4 + (2+5)*2 + (2+5)); if (argc > 1) { long s = atol(argv[1]); init_by_array((uint32_t*)&s, sizeof s / sizeof(uint32_t)); } else { time_t s = time(NULL); init_by_array((uint32_t*)&s, sizeof s / sizeof(uint32_t)); } void *data = malloc(DATA_LEN); random_fill(data, DATA_LEN); const size_t codepoints = DATA_LEN * CHAR_BIT / 21; const mushcell pos = MUSHCELL_MAX - WRAP_AFTER; mushcoords beg = MUSHCOORDS(pos,pos,pos), end; void *space_buf = malloc(mushspace_sizeof); mushspace *space; bool ok; mushbounds bounds, expected_loose, expected_tight; size_t spaces_beg, spaces_end; codepoint_reader cp_reader; #define BOUNDS_CHECK \ mushspace_get_loose_bounds(space, &bounds); \ \ tap_leqcos(bounds.beg, expected_loose.beg, \ "get_loose_bounds reports appropriate beg", \ "get_loose_bounds reports too large beg"); \ tap_geqcos(bounds.end, expected_loose.end, \ "get_loose_bounds reports appropriate end", \ "get_loose_bounds reports too small end"); \ \ ok = mushspace_get_tight_bounds(space, &bounds); \ tap_bool(ok, "get_tight_bounds says that the space is nonempty", \ "get_tight_bounds says that the space is empty"); \ \ tap_eqcos(bounds.beg, expected_tight.beg, \ "get_tight_bounds reports correct beg", \ "get_tight_bounds reports incorrect beg"); \ tap_eqcos(bounds.end, expected_tight.end, \ "get_tight_bounds reports correct end", \ "get_tight_bounds reports incorrect end"); \ #define LOAD_STRING(suf, T, ENCODER, BLOWUP, FOREACH_CP) \ space = mushspace_init(space_buf, NULL); \ if (!space) { \ tap_not_ok("init returned null"); \ tap_skip_remaining("init failed"); \ return 1; \ } \ tap_ok("init succeeded"); \ \ T *encoded_data##suf = (T*)data; \ size_t encoded_len##suf = DATA_LEN / sizeof *encoded_data##suf; \ if (BLOWUP) { \ encoded_data##suf = \ malloc((codepoints * BLOWUP) * sizeof *encoded_data##suf); \ encoded_len##suf = ENCODER(data, encoded_data##suf, codepoints); \ } \ \ mushspace_load_string##suf( \ space, encoded_data##suf, encoded_len##suf, &end, beg, true); \ \ if (BLOWUP) \ free(encoded_data##suf); \ \ size_t ii##suf = 0; \ mushcell cp##suf; \ \ spaces_beg = 0; \ spaces_end = 0; \ \ FOREACH_CP(suf) { \ if (ii##suf <= WRAP_AFTER) { \ if (cp##suf == ' ') \ ++spaces_end; \ else \ spaces_end = 0; \ continue; \ } \ if (cp##suf == ' ') \ ++spaces_beg; \ else \ break; \ } \ \ expected_loose.beg = expected_tight.beg = \ MUSHCOORDS(MUSHCELL_MIN, beg.y, beg.z); \ expected_loose.end = expected_tight.end = \ MUSHCOORDS(MUSHCELL_MAX, beg.y, beg.z); \ \ expected_loose.beg.x = expected_tight.beg.x += spaces_beg; \ expected_loose.end.x = expected_tight.end.x -= spaces_end; \ \ tap_eqcos(end, expected_tight.end, \ "load_string" #suf " reports correct end", \ "load_string" #suf " reports incorrect end"); \ \ ok = true; \ FOREACH_CP(suf) { \ mushcell gc = \ mushspace_get(space, mushcoords_add(beg, MUSHCOORDS(ii##suf,0,0))); \ if (gc == cp##suf) \ continue; \ ok = false; \ tap_not_ok("get doesn't match data given to load_string" #suf); \ printf(" ---\n" \ " failed index: %zu\n" \ " expected: %" MUSHCELL_PRIx "\n" \ " got: %" MUSHCELL_PRIx "\n" \ " ...\n", \ ii##suf, cp##suf, gc); \ break; \ } \ if (ok) \ tap_ok("get matches data given to load_string" #suf); \ \ BOUNDS_CHECK; \ mushspace_free(space); #define DIRECT_FOREACH_CP(s) \ ii##s = 0; \ for (; ii##s < encoded_len##s && (cp##s = encoded_data##s[ii##s], true); \ ++ii##s) #define READER_FOREACH_CP(s) \ cp_reader = make_codepoint_reader(data, codepoints); \ for (ii##s = 0; (cp##s = next_codepoint(&cp_reader)) != UINT32_MAX; ++ii##s) LOAD_STRING(, unsigned char, dummy, 0, DIRECT_FOREACH_CP); LOAD_STRING(_cell, mushcell, dummy, 0, DIRECT_FOREACH_CP); LOAD_STRING(_utf8, uint8_t, encode_utf8, 4, READER_FOREACH_CP); LOAD_STRING(_utf16, uint16_t, encode_utf16, 2, READER_FOREACH_CP); const mushcell *data_cell = (const mushcell*)data; const size_t data_cell_count = DATA_LEN / sizeof *data_cell; spaces_beg = 0; spaces_end = 0; for (size_t i = WRAP_AFTER+1; i < data_cell_count && data_cell[i++] == ' ';) ++spaces_beg; for (size_t i = WRAP_AFTER+1; i-- > 0 && data_cell[i] == ' ';) ++spaces_end; expected_loose.beg = expected_tight.beg = MUSHCOORDS(MUSHCELL_MIN, beg.y, beg.z); expected_loose.end = expected_tight.end = MUSHCOORDS(MUSHCELL_MAX, beg.y, beg.z); expected_loose.beg.x = expected_tight.beg.x += spaces_beg; expected_loose.end.x = expected_tight.end.x -= spaces_beg; #define PUT(FOREACH_CELL, S) \ space = mushspace_init(space_buf, NULL); \ if (!space) { \ tap_not_ok("init returned null"); \ tap_skip_remaining("init failed"); \ return 1; \ } \ tap_ok("init succeeded"); \ FOREACH_CELL { \ mushspace_put(space, mushcoords_add(beg, MUSHCOORDS(i, 0, 0)), \ data_cell[i]); \ } \ \ ok = true; \ for (size_t i = 0; i < data_cell_count; ++i) { \ mushcell dc = data_cell[i], \ gc = mushspace_get(space, \ mushcoords_add(beg, MUSHCOORDS(i, 0, 0))); \ if (gc == dc) \ continue; \ ok = false; \ tap_not_ok("get doesn't match what was put" S); \ printf(" ---\n" \ " failed index: %zu\n" \ " expected: %" MUSHCELL_PRIx "\n" \ " got: %" MUSHCELL_PRIx "\n" \ " ...\n", \ i, dc, gc); \ break; \ } \ if (ok) \ tap_ok("get matches what was put" S); \ \ BOUNDS_CHECK; #define FORWARD for (size_t i = 0; i < data_cell_count; ++i) #define REVERSE for (size_t i = data_cell_count; i--;) PUT(FORWARD, " (forward order)"); mushspace_free(space); PUT(REVERSE, " (reverse order)"); if (!ok) { tap_skip_remaining("won't copy bad space"); return 1; } void *space_buf2 = malloc(mushspace_sizeof); mushspace *space2 = mushspace_copy(space_buf2, space, NULL); mushspace_free(space); free(space_buf); space = space2; if (!space) { tap_not_ok("copy returned null"); tap_skip_remaining("copy failed"); return 1; } tap_ok("copy succeeded"); ok = true; for (size_t i = 0; i < DATA_LEN / sizeof *data_cell; ++i) { mushcell dc = data_cell[i], gc = mushspace_get(space, mushcoords_add(beg, MUSHCOORDS(i, 0, 0))); if (gc == dc) continue; ok = false; tap_not_ok("get in copy doesn't match data"); printf(" ---\n" " failed index: %zu\n" " expected: %" MUSHCELL_PRIx "\n" " got: %" MUSHCELL_PRIx "\n" " ...\n", i, dc, gc); break; } if (ok) tap_ok("get in copy matched data"); BOUNDS_CHECK; free(data); mushspace_free(space); free(space_buf2); }
int main(int argc, char **argv) { // We don't check bounds here: we'd end up essentially duplicating the logic // from load_string, and there's little point in that. tap_n(2*4 + 2*2 + 2); if (argc > 1) { long s = atol(argv[1]); init_by_array((uint32_t*)&s, sizeof s / sizeof(uint32_t)); } else { time_t s = time(NULL); init_by_array((uint32_t*)&s, sizeof s / sizeof(uint32_t)); } void *data = malloc(DATA_LEN); random_fill(data, DATA_LEN); const size_t codepoints = DATA_LEN * CHAR_BIT / 21; mushcoords beg = MUSHCOORDS(MUSHCELL_MAX-WRAP_AFTER, MUSHCELL_MAX-WRAP_AFTER, MUSHCELL_MAX-WRAP_AFTER), end; void *space_buf = malloc(mushspace_sizeof); mushspace *space; bool ok; codepoint_reader cp_reader; mushcoords pos, pos_next; bool cr; #define POS_INIT \ pos_next = beg; \ cr = false; #define CP_POS(cp) \ pos = pos_next; \ switch (cp) { \ default: \ if (MUSHSPACE_DIM > 1 && cr) { \ cr = false; \ pos = MUSHCOORDS(beg.x, pos.y + 1, pos.z); \ } \ pos_next = MUSHCOORDS(pos.x + 1, pos.y, pos.z); \ break; \ case '\r': \ if (MUSHSPACE_DIM > 1) { \ if (cr) \ pos_next = pos = MUSHCOORDS(beg.x, pos.y + 1, pos.z); \ cr = true; \ } \ continue; \ case '\n': \ if (MUSHSPACE_DIM > 1) { \ cr = false; \ pos_next = pos = MUSHCOORDS(beg.x, pos.y + 1, pos.z); \ } \ continue; \ case '\f': \ if (MUSHSPACE_DIM > 2) { \ cr = false; \ pos_next = pos = MUSHCOORDS(beg.x, beg.y, pos.z + 1); \ } else if (cr) { \ cr = false; \ pos_next = pos = MUSHCOORDS(beg.x, pos.y + 1, pos.z); \ } \ continue; \ } #define LOAD_STRING(suf, T, ENCODER, BLOWUP, FOREACH_CP) \ space = mushspace_init(space_buf, NULL); \ if (!space) { \ tap_not_ok("init returned null"); \ tap_skip_remaining("init failed"); \ return 1; \ } \ tap_ok("init succeeded"); \ \ T *encoded_data##suf = (T*)data; \ size_t encoded_len##suf = DATA_LEN / sizeof *encoded_data##suf; \ if (BLOWUP) { \ encoded_data##suf = \ malloc((codepoints * BLOWUP) * sizeof *encoded_data##suf); \ encoded_len##suf = ENCODER(data, encoded_data##suf, codepoints); \ } \ \ mushspace_load_string##suf( \ space, encoded_data##suf, encoded_len##suf, &end, beg, false); \ \ if (BLOWUP) \ free(encoded_data##suf); \ \ ok = true; \ POS_INIT; \ FOREACH_CP(suf) { \ CP_POS(cp##suf); \ mushcell gc = mushspace_get(space, pos); \ if (gc == cp##suf) \ continue; \ ok = false; \ tap_not_ok("get doesn't match data given to load_string" #suf); \ printf(" ---\n" \ " expected: %" MUSHCELL_PRIx "\n" \ " got: %" MUSHCELL_PRIx "\n" \ " failed index: %zu\n", \ cp##suf, gc, ii##suf); \ printf(" failed pos relative to min: ("); \ for (uint8_t i = 0; i < MUSHSPACE_DIM; ++i) \ printf(" %" MUSHCELL_PRId, mushcell_sub(pos.v[i], MUSHCELL_MIN)); \ printf(" )\n" \ " ...\n"); \ break; \ } \ if (ok) \ tap_ok("get matches data given to load_string" #suf); \ \ mushspace_free(space); #define DIRECT_FOREACH_CP(s) \ mushcell cp##s; \ size_t ii##s = 0; \ for (; ii##s < encoded_len##s && (cp##s = encoded_data##s[ii##s], true); \ ++ii##s) #define READER_FOREACH_CP(s) \ cp_reader = make_codepoint_reader(data, codepoints); \ size_t ii##s = 0; \ for (mushcell cp##s; (cp##s = next_codepoint(&cp_reader)) != UINT32_MAX; \ ++ii##s) LOAD_STRING(, unsigned char, dummy, 0, DIRECT_FOREACH_CP); LOAD_STRING(_cell, mushcell, dummy, 0, DIRECT_FOREACH_CP); LOAD_STRING(_utf8, uint8_t, encode_utf8, 4, READER_FOREACH_CP); LOAD_STRING(_utf16, uint16_t, encode_utf16, 2, READER_FOREACH_CP); const mushcell *data_cell = (const mushcell*)data; const size_t data_cell_count = DATA_LEN / sizeof *data_cell; mushcoords *saved_pos = malloc(data_cell_count * sizeof *saved_pos); #define PUT(FOREACH_CELL, S, GET_POS, SAVE_POS) \ space = mushspace_init(space_buf, NULL); \ if (!space) { \ tap_not_ok("init returned null"); \ tap_skip_remaining("init failed"); \ free(saved_pos); \ return 1; \ } \ tap_ok("init succeeded"); \ POS_INIT; \ FOREACH_CELL { \ GET_POS(data_cell[i]); \ if (SAVE_POS) \ saved_pos[i] = pos; \ mushspace_put(space, pos, data_cell[i]); \ } \ \ ok = true; \ POS_INIT; \ for (size_t i = 0; i < data_cell_count; ++i) { \ mushcell dc = data_cell[i]; \ GET_POS(dc); \ mushcell gc = mushspace_get(space, pos); \ if (gc == dc) \ continue; \ ok = false; \ tap_not_ok("get doesn't match what was put" S); \ printf(" ---\n" \ " failed index: %zu\n" \ " expected: %" MUSHCELL_PRIx "\n" \ " got: %" MUSHCELL_PRIx "\n", \ i, dc, gc); \ printf(" failed pos relative to min: ("); \ for (uint8_t j = 0; j < MUSHSPACE_DIM; ++j) \ printf(" %" MUSHCELL_PRId, mushcell_sub(pos.v[j], MUSHCELL_MIN)); \ printf(" )\n" \ " ...\n"); \ break; \ } \ if (ok) \ tap_ok("get matches what was put" S); #define FORWARD for (size_t i = 0; i < data_cell_count; ++i) #define REVERSE for (size_t i = data_cell_count; i--;) #define SAVED_POS(_) pos = saved_pos[i]; PUT(FORWARD, " (forward order)", CP_POS, true); mushspace_free(space); PUT(REVERSE, " (reverse order)", SAVED_POS, false); free(saved_pos); if (!ok) { tap_skip_remaining("won't copy bad space"); return 1; } void *space_buf2 = malloc(mushspace_sizeof); mushspace *space2 = mushspace_copy(space_buf2, space, NULL); mushspace_free(space); free(space_buf); space = space2; if (!space) { tap_not_ok("copy returned null"); tap_skip_remaining("copy failed"); return 1; } tap_ok("copy succeeded"); ok = true; POS_INIT; for (size_t i = 0; i < DATA_LEN / sizeof *data_cell; ++i) { mushcell dc = data_cell[i]; CP_POS(dc); mushcell gc = mushspace_get(space, pos); if (gc == dc) continue; ok = false; tap_not_ok("get in copy doesn't match data"); printf(" ---\n" " failed index: %zu\n" " expected: %" MUSHCELL_PRIx "\n" " got: %" MUSHCELL_PRIx "\n", i, dc, gc); printf(" failed pos relative to min: ("); for (uint8_t j = 0; j < MUSHSPACE_DIM; ++j) printf(" %" MUSHCELL_PRId, mushcell_sub(pos.v[j], MUSHCELL_MIN)); \ printf(" )\n" " ...\n"); break; } if (ok) tap_ok("get in copy matched data"); free(data); mushspace_free(space); free(space_buf2); }
int main() { fgraph_t *graph = 0; fgraph_return_t res = 0; fgraph_edge_weight_t wval = 0, *pwval = 0; fgraph_option_t oval = 0, *poval = 0; unsigned long ulval = 0, *pulval = 0; int ival = 0, *pival = 0; tap_plan(52); res = fgraph_init(&graph, 8, FGRAPH_ODIRECTED); tap_ok(res == FGRAPH_SUCCESS, "inited ok"); tap_ok(graph != 0, "graph not null"); res = fgraph_size(&graph, &ulval); tap_ok(res == FGRAPH_SUCCESS, "got graph size ok"); tap_ok(ulval == 8, "graph size is 8"); res = fgraph_size(&graph, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_options(&graph, &oval); tap_ok(res == FGRAPH_SUCCESS, "got graph options ok"); tap_ok(oval == FGRAPH_ODIRECTED, "options ok"); res = fgraph_options(&graph, poval); tap_ok(res == FGRAPH_ENULL, "poval is null"); res = fgraph_edge_add(&graph, 0, 1, 8); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 0, 2, 2); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 1, 5, 7); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 1, 2, 3); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 2, 4, 1); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 2, 3, 5); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 3, 6, 3); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 3, 7, 1); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 4, 5, 2); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 4, 6, 6); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 5, 7, 4); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_add(&graph, 6, 7, 2); tap_ok(res == FGRAPH_SUCCESS, "edge added ok"); res = fgraph_edge_count_all(&graph, &ulval); tap_ok(res == FGRAPH_SUCCESS, "got count ok"); tap_ok(ulval == 12, "edge count is 12"); res = fgraph_edge_count_all(&graph, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_edge_count(&graph, 0, &ulval); tap_ok(res == FGRAPH_SUCCESS, "got count ok"); tap_ok(ulval == 2, "edge count is 2"); res = fgraph_edge_count(&graph, 0, pulval); tap_ok(res == FGRAPH_ENULL, "pulval is null"); res = fgraph_edge_count(&graph, 5, &ulval); tap_ok(res == FGRAPH_SUCCESS, "got count ok"); tap_ok(ulval == 1, "edge count is 1"); res = fgraph_edge_count(&graph, 20, &ulval); tap_ok(res == FGRAPH_ENOVTX, "no such vertex"); res = fgraph_edge_get_weight(&graph, 5, 7, &wval); tap_ok(res == FGRAPH_SUCCESS, "got weight ok"); tap_ok(wval == 4, "weight is 4"); res = fgraph_edge_get_weight(&graph, 5, 7, pwval); tap_ok(res == FGRAPH_ENULL, "pwval is null"); res = fgraph_edge_get_weight(&graph, 7, 5, &wval); tap_ok(res == FGRAPH_ENOEDGE, "no such edge"); res = fgraph_edge_get_weight(&graph, 4, 6, &wval); tap_ok(res == FGRAPH_SUCCESS, "got weight ok"); tap_ok(wval == 6, "weight is 6"); res = fgraph_edge_set_weight(&graph, 4, 6, 10); tap_ok(res == FGRAPH_SUCCESS, "set weight ok"); res = fgraph_edge_set_weight(&graph, 6, 4, 10); tap_ok(res == FGRAPH_ENOEDGE, "no such edge"); res = fgraph_edge_get_weight(&graph, 4, 6, &wval); tap_ok(res == FGRAPH_SUCCESS, "got weight ok"); tap_ok(wval == 10, "weight is 10"); res = fgraph_edge_exists(&graph, 2, 4, &ival); tap_ok(res == FGRAPH_SUCCESS, "checked for edge ok"); tap_ok(ival, "edge exists"); res = fgraph_edge_exists(&graph, 2, 4, pival); tap_ok(res == FGRAPH_ENULL, "pival is null"); res = fgraph_edge_exists(&graph, 4, 2, &ival); tap_ok(res == FGRAPH_SUCCESS, "checked for edge ok"); tap_ok(!ival, "no such edge"); res = fgraph_edge_remove(&graph, 2, 4); tap_ok(res == FGRAPH_SUCCESS, "removed edge ok"); res = fgraph_edge_remove(&graph, 4, 2); tap_ok(res == FGRAPH_ENOEDGE, "no such edge"); res = fgraph_edge_get_weight(&graph, 2, 4, &wval); tap_ok(res == FGRAPH_ENOEDGE, "no such edge"); res = fgraph_edge_set_weight(&graph, 2, 4, 10); tap_ok(res == FGRAPH_ENOEDGE, "no such edge"); res = fgraph_edge_exists(&graph, 2, 4, &ival); tap_ok(res == FGRAPH_SUCCESS, "checked for edge ok"); tap_ok(!ival, "edge does not exist"); res = fgraph_clear(&graph); tap_ok(res == FGRAPH_SUCCESS, "cleared graph ok"); tap_ok(graph == 0, "graph is null"); return tap_status(); }