forked from bangoc/cgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_executable(rbm_rand_i_ut rbm_rand_i_ut.c) | ||
|
||
foreach (p rbm_rand_i_ut) | ||
target_link_libraries(${p} bkc) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
(C) Nguyen Ba Ngoc 2022 | ||
Kiểm tra kịch bản ánh xạ chuỗi -> chuỗi | ||
*/ | ||
|
||
#include "cgen.h" | ||
#include "tests/base/utils.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
#define BUFF_SIZE 32 | ||
char buff[BUFF_SIZE] = {0}; | ||
|
||
void gen_buff() { | ||
for (int i = 0; i < BUFF_SIZE - 1; ++i) { | ||
buff[i] = 'a' + rand() % ('z' - 'a' + 1); | ||
buff[BUFF_SIZE - 1]; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int n; | ||
sscanf(argv[1], "%d", &n); | ||
rbm_t map = rbm_create(gtype_cmp_s, gtype_free_s, gtype_free_s); | ||
srand(time(NULL)); | ||
char **keys = malloc(n * sizeof(char *)), | ||
**values = malloc(n * sizeof(char *)); | ||
long cc = 0; | ||
for (int i = 0; i < n; ++i) { | ||
gen_buff(); | ||
char *tmp = strdup(buff); | ||
rbm_ires ires = rbm_insert(map, gtype_s(tmp), gtype_s(NULL)); | ||
if (!ires.inserted) { | ||
CHECK_MSG(rbm_size(map) == bn_size((bn_tree_t)map), "Size equal bn_size"); | ||
CHECK_MSG(rbm_size(map) == cc, "size == cc"); | ||
free(tmp); | ||
continue; | ||
} | ||
keys[cc] = tmp; | ||
gen_buff(); | ||
values[cc] = strdup(buff); | ||
ires.value->s = values[cc]; | ||
++cc; | ||
CHECK_MSG(rbm_size(map) == bn_size((bn_tree_t)map), "Size equal bn_size"); | ||
CHECK_MSG(rbm_size(map) == cc, "size == cc"); | ||
} | ||
int sz = cc; | ||
for (int i = 0; i < sz; ++i) { | ||
CHECK_MSG(rbm_value(map, gtype_s(keys[i]))->s == values[i], "Point to the same place"); | ||
CHECK_MSG(rbm_remove(map, gtype_s(keys[i])) == 1, "Remove key i"); | ||
--cc; | ||
CHECK_MSG(rbm_size(map) == bn_size((bn_tree_t)map), "Size equal bn_size"); | ||
CHECK_MSG(rbm_size(map) == cc, "size == cc"); | ||
} | ||
rbm_free(map); | ||
free(keys); | ||
free(values); | ||
TEST_OK(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
add_executable(rbs_i_ut rbs_i_ut.c) | ||
add_executable(rbs_str_ut rbs_str_ut.c) | ||
add_executable(rbs_rand_ut rbs_rand_ut.c) | ||
|
||
foreach (p rbs_i_ut rbs_str_ut) | ||
foreach (p rbs_i_ut rbs_str_ut rbs_rand_ut) | ||
target_link_libraries(${p} bkc) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
(C) Nguyen Ba Ngoc 2022 | ||
Kiểm tra kịch bản ánh xạ chuỗi -> chuỗi | ||
*/ | ||
|
||
#include "cgen.h" | ||
#include "tests/base/utils.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
#define BUFF_SIZE 32 | ||
char buff[BUFF_SIZE] = {0}; | ||
|
||
void gen_buff() { | ||
for (int i = 0; i < BUFF_SIZE - 1; ++i) { | ||
buff[i] = 'a' + rand() % ('z' - 'a' + 1); | ||
buff[BUFF_SIZE - 1]; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int n; | ||
sscanf(argv[1], "%d", &n); | ||
rbs_t s = rbs_create(gtype_cmp_s, gtype_free_s); | ||
srand(time(NULL)); | ||
char **keys = malloc(n * sizeof(char *)); | ||
long cc = 0; | ||
for (int i = 0; i < n; ++i) { | ||
gen_buff(); | ||
char *tmp = strdup(buff); | ||
if (!rbs_insert(s, gtype_s(tmp))) { | ||
CHECK_MSG(rbs_size(s) == bn_size((bn_tree_t)s), "Size equal bn_size"); | ||
CHECK_MSG(rbs_size(s) == cc, "size == cc"); | ||
free(tmp); | ||
continue; | ||
} | ||
keys[cc] = tmp; | ||
++cc; | ||
CHECK_MSG(rbs_size(s) == bn_size((bn_tree_t)s), "Size equal bn_size"); | ||
CHECK_MSG(rbs_size(s) == cc, "size == cc"); | ||
} | ||
int sz = cc; | ||
for (int i = 0; i < sz; ++i) { | ||
CHECK_MSG(rbs_remove(s, gtype_s(keys[i])) == 1, "Remove key i"); | ||
--cc; | ||
CHECK_MSG(rbs_size(s) == bn_size((bn_tree_t)s), "Size equal bn_size"); | ||
CHECK_MSG(rbs_size(s) == cc, "size == cc"); | ||
} | ||
rbs_free(s); | ||
free(keys); | ||
TEST_OK(); | ||
} |