Added more tests.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#include "tensoriterator.h"
|
#include "tensoriter.h"
|
||||||
|
|
||||||
tensoriter_scalar tensoriter_scalar_create(tensor t)
|
tensoriter_scalar tensoriter_scalar_create(tensor t)
|
||||||
{
|
{
|
||||||
28
tests/main.c
28
tests/main.c
@@ -3,13 +3,14 @@
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tensor_test_run_all();
|
tensor_test_run_all();
|
||||||
|
tensoriter_test_run_all();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tensor_test_run_all(void)
|
void tensor_test_run_all(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
void (*test_func[NUM_TEST_FUNC])(void) = {
|
void (*test_func[NUM_TENSOR_TEST_FUNC])(void) = {
|
||||||
&tensor_test_is_empty,
|
&tensor_test_is_empty,
|
||||||
&tensor_test_is_equal,
|
&tensor_test_is_equal,
|
||||||
&tensor_test_check_size,
|
&tensor_test_check_size,
|
||||||
@@ -26,10 +27,29 @@ void tensor_test_run_all(void)
|
|||||||
&tensor_test_sub,
|
&tensor_test_sub,
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("\n### Running tests... ###\n\n");
|
printf("\n### Running tests for tensor.c ... ###\n\n");
|
||||||
for(i = 0; i < NUM_TEST_FUNC; i++) {
|
for(i = 0; i < NUM_TENSOR_TEST_FUNC; i++) {
|
||||||
test_func[i]();
|
test_func[i]();
|
||||||
}
|
}
|
||||||
printf("\n### %i functions tested. ###\n\n", NUM_TEST_FUNC);
|
printf("\n### %i functions tested. ###\n\n", NUM_TENSOR_TEST_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_run_all(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
void (*test_func[NUM_TENSORITER_TEST_FUNC])(void) = {
|
||||||
|
&tensoriter_test_scalar_next,
|
||||||
|
&tensoriter_test_scalar_get,
|
||||||
|
&tensoriter_test_scalar_map,
|
||||||
|
&tensoriter_test_scalar_map_add,
|
||||||
|
&tensoriter_test_scalar_map_sub,
|
||||||
|
&tensoriter_test_scalar_map_mul,
|
||||||
|
&tensoriter_test_scalar_map_div,
|
||||||
|
};
|
||||||
|
|
||||||
|
printf("\n### Running tests for tensoriter.c ... ###\n\n");
|
||||||
|
for(i = 0; i < NUM_TENSORITER_TEST_FUNC; i++) {
|
||||||
|
test_func[i]();
|
||||||
|
}
|
||||||
|
printf("\n### %i functions tested. ###\n\n", NUM_TENSORITER_TEST_FUNC);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "tensor_test.h"
|
#include "tensor_test.h"
|
||||||
|
#include "tensoriter_test.h"
|
||||||
|
|
||||||
#define NUM_TEST_FUNC 14
|
#define NUM_TENSOR_TEST_FUNC 14
|
||||||
|
#define NUM_TENSORITER_TEST_FUNC 7
|
||||||
|
|
||||||
|
|
||||||
void tensor_test_run_all(void);
|
void tensor_test_run_all(void);
|
||||||
|
void tensoriter_test_run_all(void);
|
||||||
|
|
||||||
#endif // _MAIN_H_INCLUDED_
|
#endif // _MAIN_H_INCLUDED_
|
||||||
|
|||||||
@@ -27,5 +27,7 @@
|
|||||||
#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)")
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#endif // _TENSOR_ASSERT_H_INCLUDED_
|
#endif // _TENSOR_ASSERT_H_INCLUDED_
|
||||||
|
|||||||
@@ -196,21 +196,103 @@ void tensor_test_cpy(void)
|
|||||||
|
|
||||||
void tensor_test_add_inplace(void)
|
void tensor_test_add_inplace(void)
|
||||||
{
|
{
|
||||||
//TODO
|
/* Depends on tensor_is_equal, tensor_init_one, tensor_set */
|
||||||
|
uint32_t s[3] = {3, 2, 4};
|
||||||
|
uint32_t index[3] = {0, 0, 0};
|
||||||
|
tensor t1 = tensor_new();
|
||||||
|
tensor t2 = tensor_new();
|
||||||
|
tensor t3 = tensor_new();
|
||||||
|
|
||||||
|
tensor_init_one(t1, s, 3);
|
||||||
|
tensor_init_one(t2, s, 3);
|
||||||
|
tensor_init_one(t3, s, 3);
|
||||||
|
|
||||||
|
for (index[0] = 0; index[0] < s[0]; ++index[0]) {
|
||||||
|
for (index[1] = 0; index[1] < s[1]; ++index[1]) {
|
||||||
|
for (index[2] = 0; index[2] < s[2]; ++index[2]) {
|
||||||
|
tensor_assert(tensor_set(t1, index, index[0] + index[1] + index[2]), "mute");
|
||||||
|
tensor_assert(tensor_set(t2, index, (s[0] + s[1] + s[2]) - (index[0] + index[1] + index[2])), "mute");
|
||||||
|
tensor_assert(tensor_set(t3, index, (s[0] + s[1] + s[2])), "mute");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tensor_add_inplace(t1, t2);
|
||||||
|
tensor_assert_eq(t1, t3);
|
||||||
|
|
||||||
|
tensor_destroy(t1);
|
||||||
|
tensor_destroy(t2);
|
||||||
|
tensor_destroy(t3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tensor_test_sub_inplace(void)
|
void tensor_test_sub_inplace(void)
|
||||||
{
|
{
|
||||||
//TODO
|
/* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */
|
||||||
|
uint32_t s[3] = {3, 2, 4};
|
||||||
|
tensor t1 = tensor_new();
|
||||||
|
tensor t2 = tensor_new();
|
||||||
|
tensor t3 = tensor_new();
|
||||||
|
|
||||||
|
tensor_init_one(t1, s, 3);
|
||||||
|
tensor_init_one(t2, s, 3);
|
||||||
|
tensor_init_zero(t3, s, 3);
|
||||||
|
|
||||||
|
tensor_sub_inplace(t1, t2);
|
||||||
|
tensor_assert_eq(t1, t3);
|
||||||
|
|
||||||
|
tensor_destroy(t1);
|
||||||
|
tensor_destroy(t2);
|
||||||
|
tensor_destroy(t3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tensor_test_add(void)
|
void tensor_test_add(void)
|
||||||
{
|
{
|
||||||
//TODO
|
/* Depends on tensor_is_equal, tensor_init_one, tensor_set */
|
||||||
|
uint32_t s[3] = {3, 2, 4};
|
||||||
|
uint32_t index[3] = {0, 0, 0};
|
||||||
|
tensor t1 = tensor_new();
|
||||||
|
tensor t2 = tensor_new();
|
||||||
|
tensor t3 = tensor_new();
|
||||||
|
|
||||||
|
tensor_init_one(t1, s, 3);
|
||||||
|
tensor_init_one(t2, s, 3);
|
||||||
|
tensor_init_one(t3, s, 3);
|
||||||
|
|
||||||
|
for (index[0] = 0; index[0] < s[0]; ++index[0]) {
|
||||||
|
for (index[1] = 0; index[1] < s[1]; ++index[1]) {
|
||||||
|
for (index[2] = 0; index[2] < s[2]; ++index[2]) {
|
||||||
|
tensor_assert(tensor_set(t1, index, index[0] + index[1] + index[2]), "mute");
|
||||||
|
tensor_assert(tensor_set(t2, index, (s[0] + s[1] + s[2]) - (index[0] + index[1] + index[2])), "mute");
|
||||||
|
tensor_assert(tensor_set(t3, index, (s[0] + s[1] + s[2])), "mute");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tensor t4 = tensor_add(t1, t2);
|
||||||
|
tensor_assert_eq(t4, t3);
|
||||||
|
|
||||||
|
tensor_destroy(t1);
|
||||||
|
tensor_destroy(t2);
|
||||||
|
tensor_destroy(t3);
|
||||||
|
tensor_destroy(t4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tensor_test_sub(void)
|
void tensor_test_sub(void)
|
||||||
{
|
{
|
||||||
//TODO
|
/* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */
|
||||||
}
|
uint32_t s[3] = {3, 2, 4};
|
||||||
|
tensor t1 = tensor_new();
|
||||||
|
tensor t2 = tensor_new();
|
||||||
|
tensor t3 = tensor_new();
|
||||||
|
|
||||||
|
tensor_init_one(t1, s, 3);
|
||||||
|
tensor_init_one(t2, s, 3);
|
||||||
|
tensor_init_zero(t3, s, 3);
|
||||||
|
|
||||||
|
tensor t4 = tensor_sub(t1, t2);
|
||||||
|
tensor_assert_eq(t4, t3);
|
||||||
|
|
||||||
|
tensor_destroy(t1);
|
||||||
|
tensor_destroy(t2);
|
||||||
|
tensor_destroy(t3);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#ifndef _TEST_TENSOR_H_INCLUDED_
|
#ifndef _TEST_TENSOR_H_INCLUDED_
|
||||||
#define _TEST_TENSOR_H_INCLUDED_
|
#define _TEST_TENSOR_H_INCLUDED_
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "../tensor.h"
|
#include "../tensor.h"
|
||||||
#include "tensor_assert.h"
|
#include "tensor_assert.h"
|
||||||
|
|||||||
36
tests/tensoriter_test.c
Normal file
36
tests/tensoriter_test.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include "tensoriter_test.h"
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_next(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_get(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_map(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_map_add(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_map_sub(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_map_mul(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_map_div(void)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
16
tests/tensoriter_test.h
Normal file
16
tests/tensoriter_test.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _TESNORITER_TEST_H_INCLUDED_
|
||||||
|
#define _TESNORITER_TEST_H_INCLUDED_
|
||||||
|
|
||||||
|
#include "../tensor.h"
|
||||||
|
#include "../tensoriter.h"
|
||||||
|
#include "tensor_assert.h"
|
||||||
|
|
||||||
|
void tensoriter_test_scalar_next(void);
|
||||||
|
void tensoriter_test_scalar_get(void);
|
||||||
|
void tensoriter_test_scalar_map(void);
|
||||||
|
void tensoriter_test_scalar_map_add(void);
|
||||||
|
void tensoriter_test_scalar_map_sub(void);
|
||||||
|
void tensoriter_test_scalar_map_mul(void);
|
||||||
|
void tensoriter_test_scalar_map_div(void);
|
||||||
|
|
||||||
|
#endif // _TESNORITER_TEST_H_INCLUDED_
|
||||||
Reference in New Issue
Block a user