Restructured and renamed some tests.
This commit is contained in:
2
Makefile
2
Makefile
@@ -37,7 +37,7 @@ $(OBJ_DIR_TESTS):
|
|||||||
$(OBJ_DIR_TESTS)/main.o: $(DIR_TESTS)/main.c | $(OBJ_DIR_TESTS)
|
$(OBJ_DIR_TESTS)/main.o: $(DIR_TESTS)/main.c | $(OBJ_DIR_TESTS)
|
||||||
$(CC) $(CC_FLAGS) -c $< -o $@
|
$(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 $@
|
$(CC) $(CC_FLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
31
tests/main.c
31
tests/main.c
@@ -1,8 +1,35 @@
|
|||||||
#include "test_tensor.h"
|
#include "main.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_tensor_run_all();
|
tensor_test_run_all();
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
12
tests/main.h
Normal file
12
tests/main.h
Normal file
@@ -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_
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
#ifndef _TEST_TENSOR_H_INCLUDED_
|
#ifndef _TENSOR_ASSERT_H_INCLUDED_
|
||||||
#define _TEST_TENSOR_H_INCLUDED_
|
#define _TENSOR_ASSERT_H_INCLUDED_
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include "../tensor.h"
|
|
||||||
|
|
||||||
#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"
|
||||||
@@ -34,21 +28,4 @@
|
|||||||
#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_tensor_run_all(void);
|
#endif // _TENSOR_ASSERT_H_INCLUDED_
|
||||||
|
|
||||||
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_
|
|
||||||
@@ -1,34 +1,6 @@
|
|||||||
#include "test_tensor.h"
|
#include "tensor_test.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
void test_tensor_run_all(void)
|
void tensor_test_is_empty(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)
|
|
||||||
{
|
{
|
||||||
/* Depends on tensor_init_zero */
|
/* Depends on tensor_init_zero */
|
||||||
uint32_t s[4] = {2, 5, 3, 7};
|
uint32_t s[4] = {2, 5, 3, 7};
|
||||||
@@ -44,7 +16,7 @@ void test_tensor_is_empty(void)
|
|||||||
tensor_destroy(t2);
|
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 */
|
/* Depends on tensor_cpy, tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
||||||
uint32_t s[4] = {2, 5, 3, 7};
|
uint32_t s[4] = {2, 5, 3, 7};
|
||||||
@@ -63,7 +35,7 @@ void test_tensor_is_equal(void)
|
|||||||
tensor_destroy(t2);
|
tensor_destroy(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_check_size(void)
|
void tensor_test_check_size(void)
|
||||||
{
|
{
|
||||||
uint32_t size[] = {3, 2, 5, 0};
|
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, 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)");
|
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};
|
uint32_t size[] = {3, 2, 7};
|
||||||
tensor t = tensor_new();
|
tensor t = tensor_new();
|
||||||
@@ -83,7 +55,7 @@ void test_tensor_set_size(void)
|
|||||||
tensor_destroy(t);
|
tensor_destroy(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_set(void)
|
void tensor_test_set(void)
|
||||||
{
|
{
|
||||||
/* Depends on tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
/* Depends on tensor_is_equal, tensor_init_zero, tensor_init_rand */
|
||||||
uint32_t s[4] = {2, 5, 3, 7};
|
uint32_t s[4] = {2, 5, 3, 7};
|
||||||
@@ -109,7 +81,7 @@ void test_tensor_set(void)
|
|||||||
tensor_destroy(t2);
|
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 */
|
/* Depends on tensor_is_equal, tensor_set, tensor_init_zero, tensor_init_rand */
|
||||||
bool status;
|
bool status;
|
||||||
@@ -137,7 +109,7 @@ void test_tensor_get(void)
|
|||||||
tensor_destroy(t2);
|
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 */
|
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||||
uint32_t s[3] = {2, 5, 7};
|
uint32_t s[3] = {2, 5, 7};
|
||||||
@@ -161,7 +133,7 @@ void test_tensor_init_one(void)
|
|||||||
tensor_destroy(t2);
|
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 */
|
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||||
uint32_t s[3] = {2, 5, 7};
|
uint32_t s[3] = {2, 5, 7};
|
||||||
@@ -185,7 +157,7 @@ void test_tensor_init_zero(void)
|
|||||||
tensor_destroy(t2);
|
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 */
|
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||||
uint32_t s[3] = {2, 5, 7};
|
uint32_t s[3] = {2, 5, 7};
|
||||||
@@ -205,7 +177,7 @@ void test_tensor_init_rand(void)
|
|||||||
tensor_destroy(t1);
|
tensor_destroy(t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_cpy(void)
|
void tensor_test_cpy(void)
|
||||||
{
|
{
|
||||||
/* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */
|
/* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */
|
||||||
uint32_t s[3] = {2, 5, 7};
|
uint32_t s[3] = {2, 5, 7};
|
||||||
@@ -222,22 +194,22 @@ void test_tensor_cpy(void)
|
|||||||
tensor_destroy(t2);
|
tensor_destroy(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_add_inplace(void)
|
void tensor_test_add_inplace(void)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_sub_inplace(void)
|
void tensor_test_sub_inplace(void)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_add(void)
|
void tensor_test_add(void)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_tensor_sub(void)
|
void tensor_test_sub(void)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
27
tests/tensor_test.h
Normal file
27
tests/tensor_test.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef _TEST_TENSOR_H_INCLUDED_
|
||||||
|
#define _TEST_TENSOR_H_INCLUDED_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#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_
|
||||||
Reference in New Issue
Block a user