util/stack: extend stack api with r_stack_size core/graph: use RStack instead of a custom implementation util/graph: change implementation to use lists and extend api core/cmd_debug: avoid free r_graph_get_nodes core/graph: rename some functions and use typedefs for graph struct core/graph: use RGraph for the ascii art graph util/list: add const whenever possible util/graph: add const on r_graph_get_nodes/neighbours core/graph,core/cmd_debug: use const core/graph: clean the code (add comments, use const, remove magic nums) * use r_graph_node_iter for the current node * reset graph when reloading nodes * on callgraph edges printing, nth should be 0 * force seek of current node when reloading nodes * use graph_foreach_node * core/graph: remove get_current_node because useless
75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
#include <r_util.h>
|
|
|
|
void check (int n, int exp, char *descr) {
|
|
descr = descr == NULL ? "" : descr;
|
|
if (n == exp) {
|
|
printf("[+][%s] test passed (actual: %d; expected: %d)\n", descr, n, exp);
|
|
} else {
|
|
printf("[-][%s] test failed (actual: %d; expected: %d)\n", descr, n, exp);
|
|
}
|
|
}
|
|
|
|
void check_empty(RStack *s, int exp) {
|
|
if (r_stack_is_empty(s) == exp) {
|
|
printf("[+] test passed (stack empty status)\n");
|
|
} else {
|
|
printf("[-] test failed (stack empty status)\n");
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
RStack *s = r_stack_new(5);
|
|
int n;
|
|
|
|
check(r_stack_size(s), 0, "stack.0");
|
|
r_stack_push(s, (void *)10);
|
|
r_stack_push(s, (void *)1);
|
|
r_stack_push(s, (void *)2);
|
|
check(r_stack_size(s), 3, "stack.3");
|
|
r_stack_push(s, (void *)3);
|
|
r_stack_push(s, (void *)4);
|
|
r_stack_push(s, (void *)5);
|
|
r_stack_push(s, (void *)6);
|
|
r_stack_push(s, (void *)8);
|
|
r_stack_push(s, (void *)9);
|
|
r_stack_push(s, (void *)6);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 6, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 9, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 8, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 6, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 5, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 4, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 3, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 2, NULL);
|
|
|
|
check(r_stack_size(s), 2, "stack.2");
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 1, NULL);
|
|
check_empty(s, R_FALSE);
|
|
check(r_stack_size(s), 1, "stack.1");
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 10, NULL);
|
|
|
|
check(r_stack_size(s), 0, "stack.0.2");
|
|
check_empty(s, R_TRUE);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 0, NULL);
|
|
n = (int)r_stack_pop(s);
|
|
check(n, 0, NULL);
|
|
check_empty(s, R_TRUE);
|
|
|
|
r_stack_push(s, (void *)10);
|
|
r_stack_push(s, (void *)1);
|
|
check_empty(s, R_FALSE);
|
|
|
|
r_stack_free(s);
|
|
return 0;
|
|
}
|