Added tests on ordered-set
This commit is contained in:
parent
883088e2a5
commit
2e94e558c1
3 changed files with 57 additions and 0 deletions
|
@ -133,4 +133,5 @@ add_custom_target(uninstall
|
|||
|
||||
enable_testing()
|
||||
add_subdirectory(samples)
|
||||
add_subdirectory(test)
|
||||
|
||||
|
|
12
test/CMakeLists.txt
Normal file
12
test/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra")
|
||||
|
||||
include_directories(../include ../src)
|
||||
|
||||
set(TEST_SOURCES
|
||||
ordered-set.c
|
||||
)
|
||||
|
||||
add_executable(test_criterion ${TEST_SOURCES})
|
||||
target_link_libraries(test_criterion criterion)
|
||||
|
||||
add_test(test_criterion test_criterion)
|
44
test/ordered-set.c
Normal file
44
test/ordered-set.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <csptr/smart_ptr.h>
|
||||
|
||||
#include "criterion/criterion.h"
|
||||
#include "criterion/ordered-set.h"
|
||||
|
||||
int compare_gt(void *a, void *b) {
|
||||
int *ia = a, *ib = b;
|
||||
return *ia == *ib ? 0 : (*ia > *ib ? -1 : 1);
|
||||
}
|
||||
|
||||
int compare_lt(void *a, void *b) {
|
||||
int *ia = a, *ib = b;
|
||||
return *ia == *ib ? 0 : (*ia < *ib ? -1 : 1);
|
||||
}
|
||||
|
||||
Test(ordered_set, contract_lt) {
|
||||
smart struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL);
|
||||
|
||||
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
|
||||
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
|
||||
insert_ordered_set(set, &(int[1]) { 3 }, sizeof (int));
|
||||
|
||||
int *prev = NULL;
|
||||
FOREACH_SET(int *e, set) {
|
||||
if (prev)
|
||||
cr_assert_lt(*prev, *e);
|
||||
prev = e;
|
||||
}
|
||||
}
|
||||
|
||||
Test(ordered_set, contract_gt) {
|
||||
smart struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL);
|
||||
|
||||
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
|
||||
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
|
||||
insert_ordered_set(set, &(int[1]) { 3 }, sizeof (int));
|
||||
|
||||
int *prev = NULL;
|
||||
FOREACH_SET(int *e, set) {
|
||||
if (prev)
|
||||
cr_assert_gt(*prev, *e);
|
||||
prev = e;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue