diff --git a/Makefile b/Makefile index 04fbe6d..916f97f 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ $(OBJ_DIR_TESTS): $(OBJ_DIR_TESTS)/main.o: $(DIR_TESTS)/main.c | $(OBJ_DIR_TESTS) $(CC) $(CC_FLAGS) -c $< -o $@ -$(OBJ_DIR_TESTS)/test_tensor.o: $(DIR_TESTS)/test_tensor.c $(DIR_TESTS)/test_tensor.h | $(OBJ_DIR_TESTS) +$(OBJ_DIR_TESTS)/tensor_test.o: $(DIR_TESTS)/tensor_test.c $(DIR_TESTS)/tensor_test.h | $(OBJ_DIR_TESTS) $(CC) $(CC_FLAGS) -c $< -o $@ diff --git a/tests/main.c b/tests/main.c index 74b21a4..78d084a 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,8 +1,35 @@ -#include "test_tensor.h" +#include "main.h" int main(void) { - test_tensor_run_all(); + tensor_test_run_all(); return 0; } +void tensor_test_run_all(void) +{ + int i; + void (*test_func[NUM_TEST_FUNC])(void) = { + &tensor_test_is_empty, + &tensor_test_is_equal, + &tensor_test_check_size, + &tensor_test_set_size, + &tensor_test_set, + &tensor_test_get, + &tensor_test_init_one, + &tensor_test_init_zero, + &tensor_test_init_rand, + &tensor_test_cpy, + &tensor_test_add_inplace, + &tensor_test_sub_inplace, + &tensor_test_add, + &tensor_test_sub, + }; + + printf("\n### Running tests... ###\n\n"); + for(i = 0; i < NUM_TEST_FUNC; i++) { + test_func[i](); + } + printf("\n### %i functions tested. ###\n\n", NUM_TEST_FUNC); +} + diff --git a/tests/main.h b/tests/main.h new file mode 100644 index 0000000..a1fac36 --- /dev/null +++ b/tests/main.h @@ -0,0 +1,12 @@ +#ifndef _MAIN_H_INCLUDED_ +#define _MAIN_H_INCLUDED_ + + +#include "tensor_test.h" + +#define NUM_TEST_FUNC 14 + + +void tensor_test_run_all(void); + +#endif // _MAIN_H_INCLUDED_ diff --git a/tests/test_tensor.h b/tests/tensor_assert.h similarity index 63% rename from tests/test_tensor.h rename to tests/tensor_assert.h index a6e1050..fcf5ed2 100644 --- a/tests/test_tensor.h +++ b/tests/tensor_assert.h @@ -1,12 +1,6 @@ -#ifndef _TEST_TENSOR_H_INCLUDED_ -#define _TEST_TENSOR_H_INCLUDED_ +#ifndef _TENSOR_ASSERT_H_INCLUDED_ +#define _TENSOR_ASSERT_H_INCLUDED_ -#include -#include -#include -#include "../tensor.h" - -#define NUM_TEST_FUNC 14 #define ANSI_COLOR_GREEN "\x1b[32m" #define ANSI_COLOR_RESET "\x1b[0m" @@ -16,13 +10,13 @@ #define tensor_assert(X, msg) do{ \ FILE* stream = stderr; \ - if (!(X)) { \ + if (!(X)) { \ fputs(ANSI_COLOR_RED "Assertion failed: " ANSI_COLOR_RESET, stream); \ fprintf(stream, \ "function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \ fputs((msg), stream); \ fputc('\n', stream); \ - } else if (strcmp((msg), "mute") != 0) { \ + } else if (strcmp((msg), "mute") != 0) { \ fputs(ANSI_COLOR_GREEN "Assertion succeeded: " ANSI_COLOR_RESET, stream); \ fprintf(stream, \ "function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \ @@ -34,21 +28,4 @@ #define tensor_assert_ne(X, Y) tensor_assert(!tensor_is_equal((X), (Y)), "(tensor_assert_ne)") -void test_tensor_run_all(void); - -void test_tensor_is_empty(void); -void test_tensor_is_equal(void); -void test_tensor_check_size(void); -void test_tensor_set_size(void); -void test_tensor_set(void); -void test_tensor_get(void); -void test_tensor_init_one(void); -void test_tensor_init_zero(void); -void test_tensor_init_rand(void); -void test_tensor_cpy(void); -void test_tensor_add_inplace(void); -void test_tensor_sub_inplace(void); -void test_tensor_add(void); -void test_tensor_sub(void); - -#endif // _TEST_TENSOR_H_INCLUDED_ +#endif // _TENSOR_ASSERT_H_INCLUDED_ diff --git a/tests/test_tensor.c b/tests/tensor_test.c similarity index 80% rename from tests/test_tensor.c rename to tests/tensor_test.c index 22bc2cb..3effc36 100644 --- a/tests/test_tensor.c +++ b/tests/tensor_test.c @@ -1,34 +1,6 @@ -#include "test_tensor.h" -#include +#include "tensor_test.h" -void test_tensor_run_all(void) -{ - int i; - void (*test_func[NUM_TEST_FUNC])(void) = { - &test_tensor_is_empty, - &test_tensor_is_equal, - &test_tensor_check_size, - &test_tensor_set_size, - &test_tensor_set, - &test_tensor_get, - &test_tensor_init_one, - &test_tensor_init_zero, - &test_tensor_init_rand, - &test_tensor_cpy, - &test_tensor_add_inplace, - &test_tensor_sub_inplace, - &test_tensor_add, - &test_tensor_sub, - }; - - printf("\n### Running tests... ###\n\n"); - for(i = 0; i < NUM_TEST_FUNC; i++) { - test_func[i](); - } - printf("\n### %i functions tested. ###\n\n", NUM_TEST_FUNC); -} - -void test_tensor_is_empty(void) +void tensor_test_is_empty(void) { /* Depends on tensor_init_zero */ uint32_t s[4] = {2, 5, 3, 7}; @@ -44,7 +16,7 @@ void test_tensor_is_empty(void) tensor_destroy(t2); } -void test_tensor_is_equal(void) +void tensor_test_is_equal(void) { /* Depends on tensor_cpy, tensor_is_equal, tensor_init_zero, tensor_init_rand */ uint32_t s[4] = {2, 5, 3, 7}; @@ -63,7 +35,7 @@ void test_tensor_is_equal(void) tensor_destroy(t2); } -void test_tensor_check_size(void) +void tensor_test_check_size(void) { uint32_t size[] = {3, 2, 5, 0}; tensor_assert(_tensor_check_size(size, 3), "(valid size declared as invalid)"); @@ -72,7 +44,7 @@ void test_tensor_check_size(void) tensor_assert(!_tensor_check_size(size, -3), "(rank should be non negative)"); } -void test_tensor_set_size(void) +void tensor_test_set_size(void) { uint32_t size[] = {3, 2, 7}; tensor t = tensor_new(); @@ -83,7 +55,7 @@ void test_tensor_set_size(void) tensor_destroy(t); } -void test_tensor_set(void) +void tensor_test_set(void) { /* Depends on tensor_is_equal, tensor_init_zero, tensor_init_rand */ uint32_t s[4] = {2, 5, 3, 7}; @@ -109,7 +81,7 @@ void test_tensor_set(void) tensor_destroy(t2); } -void test_tensor_get(void) +void tensor_test_get(void) { /* Depends on tensor_is_equal, tensor_set, tensor_init_zero, tensor_init_rand */ bool status; @@ -137,7 +109,7 @@ void test_tensor_get(void) tensor_destroy(t2); } -void test_tensor_init_one(void) +void tensor_test_init_one(void) { /* Depends on tensor_is_equal, tensor_set, tensor_init_rand */ uint32_t s[3] = {2, 5, 7}; @@ -161,7 +133,7 @@ void test_tensor_init_one(void) tensor_destroy(t2); } -void test_tensor_init_zero(void) +void tensor_test_init_zero(void) { /* Depends on tensor_is_equal, tensor_set, tensor_init_rand */ uint32_t s[3] = {2, 5, 7}; @@ -185,7 +157,7 @@ void test_tensor_init_zero(void) tensor_destroy(t2); } -void test_tensor_init_rand(void) +void tensor_test_init_rand(void) { /* Depends on tensor_is_equal, tensor_set, tensor_init_rand */ uint32_t s[3] = {2, 5, 7}; @@ -205,7 +177,7 @@ void test_tensor_init_rand(void) tensor_destroy(t1); } -void test_tensor_cpy(void) +void tensor_test_cpy(void) { /* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */ uint32_t s[3] = {2, 5, 7}; @@ -222,22 +194,22 @@ void test_tensor_cpy(void) tensor_destroy(t2); } -void test_tensor_add_inplace(void) +void tensor_test_add_inplace(void) { //TODO } -void test_tensor_sub_inplace(void) +void tensor_test_sub_inplace(void) { //TODO } -void test_tensor_add(void) +void tensor_test_add(void) { //TODO } -void test_tensor_sub(void) +void tensor_test_sub(void) { //TODO } diff --git a/tests/tensor_test.h b/tests/tensor_test.h new file mode 100644 index 0000000..45ca716 --- /dev/null +++ b/tests/tensor_test.h @@ -0,0 +1,27 @@ +#ifndef _TEST_TENSOR_H_INCLUDED_ +#define _TEST_TENSOR_H_INCLUDED_ + +#include +#include +#include + +#include "../tensor.h" +#include "tensor_assert.h" + + +void tensor_test_is_empty(void); +void tensor_test_is_equal(void); +void tensor_test_check_size(void); +void tensor_test_set_size(void); +void tensor_test_set(void); +void tensor_test_get(void); +void tensor_test_init_one(void); +void tensor_test_init_zero(void); +void tensor_test_init_rand(void); +void tensor_test_cpy(void); +void tensor_test_add_inplace(void); +void tensor_test_sub_inplace(void); +void tensor_test_add(void); +void tensor_test_sub(void); + +#endif // _TEST_TENSOR_H_INCLUDED_