Implemented more tests.
This commit is contained in:
@@ -39,6 +39,9 @@ void test_tensor_is_empty(void)
|
||||
|
||||
tensor_assert(tensor_is_empty(t1), "(empty tensor not detected)");
|
||||
tensor_assert(!tensor_is_empty(t2), "(non empty tensor not detected)");
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
|
||||
void test_tensor_is_equal(void)
|
||||
@@ -55,6 +58,7 @@ void test_tensor_is_equal(void)
|
||||
tensor_cpy(t2, t1);
|
||||
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
@@ -75,6 +79,8 @@ void test_tensor_set_size(void)
|
||||
|
||||
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)");
|
||||
|
||||
tensor_destroy(t);
|
||||
}
|
||||
|
||||
void test_tensor_set(void)
|
||||
@@ -98,6 +104,7 @@ void test_tensor_set(void)
|
||||
}
|
||||
}
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
@@ -125,28 +132,94 @@ void test_tensor_get(void)
|
||||
}
|
||||
}
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
|
||||
void test_tensor_init_one(void)
|
||||
{
|
||||
//TODO
|
||||
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||
uint32_t s[3] = {2, 5, 7};
|
||||
uint32_t index[3] = {0, 0, 0};
|
||||
tensor t1 = tensor_new();
|
||||
tensor t2 = tensor_new();
|
||||
|
||||
tensor_init_rand(t1, s, 3, 30);
|
||||
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_set(t1, index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tensor_assert(tensor_init_one(t2, s, 3), "(there should be no error when initing)");
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
|
||||
void test_tensor_init_zero(void)
|
||||
{
|
||||
//TODO
|
||||
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||
uint32_t s[3] = {2, 5, 7};
|
||||
uint32_t index[3] = {0, 0, 0};
|
||||
tensor t1 = tensor_new();
|
||||
tensor t2 = tensor_new();
|
||||
|
||||
tensor_init_rand(t1, s, 3, 30);
|
||||
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_set(t1, index, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tensor_assert(tensor_init_zero(t2, s, 3), "(there should be no error when initing)");
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
|
||||
void test_tensor_init_rand(void)
|
||||
{
|
||||
//TODO
|
||||
/* Depends on tensor_is_equal, tensor_set, tensor_init_rand */
|
||||
uint32_t s[3] = {2, 5, 7};
|
||||
uint32_t index[3] = {0, 0, 0};
|
||||
tensor t1 = tensor_new();
|
||||
|
||||
tensor_assert(tensor_init_rand(t1, s, 3, 30), "(there should be no error when initing)");
|
||||
|
||||
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, 0), "mute");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tensor_destroy(t1);
|
||||
}
|
||||
|
||||
void test_tensor_cpy(void)
|
||||
{
|
||||
//TODO
|
||||
/* Depends on tensor_is_equal, tensor_init_one, tensor_init_zero */
|
||||
uint32_t s[3] = {2, 5, 7};
|
||||
tensor t1 = tensor_new();
|
||||
tensor t2 = tensor_new();
|
||||
|
||||
tensor_init_one(t1, s, 3);
|
||||
tensor_init_zero(t2, s, 3);
|
||||
|
||||
tensor_assert(tensor_cpy(t1, t2), "(there should be no error when copying)");
|
||||
tensor_assert_eq(t1, t2);
|
||||
|
||||
tensor_destroy(t1);
|
||||
tensor_destroy(t2);
|
||||
}
|
||||
|
||||
void test_tensor_add_inplace(void)
|
||||
|
||||
Reference in New Issue
Block a user