First util functions, with corresponding unit test.
This commit is contained in:
@ -5,6 +5,7 @@ static void create_test_suite()
|
||||
add_node_suite();
|
||||
add_image_suite();
|
||||
add_tree_suite();
|
||||
add_util_suite();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -7,5 +7,6 @@
|
||||
void add_node_suite();
|
||||
void add_image_suite();
|
||||
void add_tree_suite();
|
||||
void add_util_suite();
|
||||
|
||||
#endif /*TEST_H_*/
|
||||
|
36
test/test_util.c
Normal file
36
test/test_util.c
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Unit test for util.h
|
||||
*
|
||||
* This test utiliy functions
|
||||
*/
|
||||
#include "test.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_div_up()
|
||||
{
|
||||
CU_ASSERT_EQUAL( div_up(1, 2), 1 );
|
||||
CU_ASSERT_EQUAL( div_up(2, 2), 1 );
|
||||
CU_ASSERT_EQUAL( div_up(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( div_up(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( div_up(3, 2), 2 );
|
||||
}
|
||||
|
||||
static void test_round_up()
|
||||
{
|
||||
CU_ASSERT_EQUAL( round_up(1, 2), 2 );
|
||||
CU_ASSERT_EQUAL( round_up(2, 2), 2 );
|
||||
CU_ASSERT_EQUAL( round_up(0, 2), 0 );
|
||||
CU_ASSERT_EQUAL( round_up(-1, 2), 0 );
|
||||
CU_ASSERT_EQUAL( round_up(3, 2), 4 );
|
||||
CU_ASSERT_EQUAL( round_up(15, 7), 21 );
|
||||
CU_ASSERT_EQUAL( round_up(13, 7), 14 );
|
||||
CU_ASSERT_EQUAL( round_up(14, 7), 14 );
|
||||
}
|
||||
|
||||
void add_util_suite()
|
||||
{
|
||||
CU_pSuite pSuite = CU_add_suite("UtilSuite", NULL, NULL);
|
||||
|
||||
CU_add_test(pSuite, "div_up()", test_div_up);
|
||||
CU_add_test(pSuite, "round_up()", test_round_up);
|
||||
}
|
Reference in New Issue
Block a user