Added more tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_run_all();
|
test_tensor_run_all();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,24 @@
|
|||||||
#include "test_tensor.h"
|
#include "test_tensor.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void test_run_all(void)
|
void test_tensor_run_all(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
void (*test_func[NUM_TEST_FUNC])(void) = {
|
void (*test_func[NUM_TEST_FUNC])(void) = {
|
||||||
|
&test_tensor_is_empty,
|
||||||
&test_tensor_is_equal,
|
&test_tensor_is_equal,
|
||||||
|
&test_tensor_check_size,
|
||||||
|
&test_tensor_set_size,
|
||||||
&test_tensor_set,
|
&test_tensor_set,
|
||||||
&test_tensor_get,
|
&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");
|
printf("\n### Running tests... ###\n\n");
|
||||||
@@ -17,6 +28,19 @@ void test_run_all(void)
|
|||||||
printf("\n### %i functions tested. ###\n\n", NUM_TEST_FUNC);
|
printf("\n### %i functions tested. ###\n\n", NUM_TEST_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_tensor_is_empty(void)
|
||||||
|
{
|
||||||
|
/* Depends on tensor_init_zero */
|
||||||
|
uint32_t s[4] = {2, 5, 3, 7};
|
||||||
|
tensor t1 = tensor_new();
|
||||||
|
tensor t2 = tensor_new();
|
||||||
|
|
||||||
|
tensor_init_zero(t2, s, 4);
|
||||||
|
|
||||||
|
tensor_assert(tensor_is_empty(t1), "(empty tensor not detected)");
|
||||||
|
tensor_assert(!tensor_is_empty(t2), "(non empty tensor not detected)");
|
||||||
|
}
|
||||||
|
|
||||||
void test_tensor_is_equal(void)
|
void test_tensor_is_equal(void)
|
||||||
{
|
{
|
||||||
/* Depends on tensor_cpy, tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
/* Depends on tensor_cpy, tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
||||||
@@ -35,6 +59,24 @@ void test_tensor_is_equal(void)
|
|||||||
tensor_destroy(t2);
|
tensor_destroy(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_tensor_check_size(void)
|
||||||
|
{
|
||||||
|
uint32_t size[] = {3, 2, 5, 0};
|
||||||
|
tensor_assert(_tensor_check_size(size, 3), "(valid size declared as invalid)");
|
||||||
|
tensor_assert(!_tensor_check_size(size, 5), "(no dimension should be 0)");
|
||||||
|
tensor_assert(_tensor_check_size(size, 0), "(rank can be 0)");
|
||||||
|
tensor_assert(!_tensor_check_size(size, -3), "(rank should be non negative)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_set_size(void)
|
||||||
|
{
|
||||||
|
uint32_t size[] = {3, 2, 7};
|
||||||
|
tensor t = tensor_new();
|
||||||
|
|
||||||
|
tensor_assert(_tensor_set_size(t, size, 3), "(size should be set without error)");
|
||||||
|
tensor_assert(t->num_elem == 3 * 2 * 7, "(wrong number of elements)");
|
||||||
|
}
|
||||||
|
|
||||||
void test_tensor_set(void)
|
void test_tensor_set(void)
|
||||||
{
|
{
|
||||||
/* Depends on tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
/* Depends on tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
||||||
@@ -63,7 +105,7 @@ void test_tensor_set(void)
|
|||||||
void test_tensor_get(void)
|
void test_tensor_get(void)
|
||||||
{
|
{
|
||||||
/* Depends on tensor_is_equal, tensor_set, tensor_init_zero, tensor_init_rand */
|
/* Depends on tensor_is_equal, tensor_set, tensor_init_zero, tensor_init_rand */
|
||||||
uint8_t status;
|
bool status;
|
||||||
uint32_t s[4] = {2, 5, 3, 7};
|
uint32_t s[4] = {2, 5, 3, 7};
|
||||||
uint32_t index[4] = {0, 0, 0, 0};
|
uint32_t index[4] = {0, 0, 0, 0};
|
||||||
tensor t1 = tensor_new();
|
tensor t1 = tensor_new();
|
||||||
@@ -87,3 +129,43 @@ void test_tensor_get(void)
|
|||||||
tensor_destroy(t2);
|
tensor_destroy(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_tensor_init_one(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_init_zero(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_init_rand(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_cpy(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_add_inplace(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_sub_inplace(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_add(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tensor_sub(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "../tensor.h"
|
#include "../tensor.h"
|
||||||
|
|
||||||
#define NUM_TEST_FUNC 3
|
#define NUM_TEST_FUNC 14
|
||||||
|
|
||||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||||
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
#define tensor_assert(X, msg) do{ \
|
#define tensor_assert(X, msg) do{ \
|
||||||
FILE* stream = stderr; \
|
FILE* stream = stderr; \
|
||||||
if (!X) { \
|
if (!(X)) { \
|
||||||
fputs(ANSI_COLOR_RED "Assertion failed: " ANSI_COLOR_RESET, stream); \
|
fputs(ANSI_COLOR_RED "Assertion failed: " ANSI_COLOR_RESET, stream); \
|
||||||
fprintf(stream, \
|
fprintf(stream, \
|
||||||
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
|
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
|
||||||
fputs(msg, stream); \
|
fputs((msg), stream); \
|
||||||
fputc('\n', 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); \
|
fputs(ANSI_COLOR_GREEN "Assertion succeeded: " ANSI_COLOR_RESET, stream); \
|
||||||
fprintf(stream, \
|
fprintf(stream, \
|
||||||
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
|
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
|
||||||
@@ -33,11 +33,22 @@
|
|||||||
#define tensor_assert_eq(X, Y) tensor_assert(tensor_is_equal((X), (Y)), "(tensor_assert_eq)")
|
#define tensor_assert_eq(X, Y) tensor_assert(tensor_is_equal((X), (Y)), "(tensor_assert_eq)")
|
||||||
#define tensor_assert_ne(X, Y) tensor_assert(!tensor_is_equal((X), (Y)), "(tensor_assert_ne)")
|
#define tensor_assert_ne(X, Y) tensor_assert(!tensor_is_equal((X), (Y)), "(tensor_assert_ne)")
|
||||||
|
|
||||||
void test_run_all(void);
|
|
||||||
|
|
||||||
|
void test_tensor_run_all(void);
|
||||||
|
|
||||||
|
void test_tensor_is_empty(void);
|
||||||
void test_tensor_is_equal(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_set(void);
|
||||||
void test_tensor_get(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
|
#endif // _TEST_TENSOR_H_INCLUDED_
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user