forked from M-Labs/nac3
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <test/core.hpp>
|
|
#include <irrt_everything.hpp>
|
|
|
|
namespace test {
|
|
namespace ndarray_basic {
|
|
void test_calc_size_from_shape_normal() {
|
|
// Test shapes with normal values
|
|
BEGIN_TEST();
|
|
|
|
int32_t shape[4] = { 2, 3, 5, 7 };
|
|
assert_values_match(210, ndarray::basic::util::calc_size_from_shape<int32_t>(4, shape));
|
|
}
|
|
|
|
void test_calc_size_from_shape_has_zero() {
|
|
// Test shapes with 0 in them
|
|
BEGIN_TEST();
|
|
|
|
int32_t shape[4] = { 2, 0, 5, 7 };
|
|
assert_values_match(0, ndarray::basic::util::calc_size_from_shape<int32_t>(4, shape));
|
|
}
|
|
|
|
void test_set_strides_by_shape() {
|
|
// Test `set_strides_by_shape()`
|
|
BEGIN_TEST();
|
|
|
|
int32_t shape[4] = { 99, 3, 5, 7 };
|
|
int32_t strides[4] = { 0 };
|
|
ndarray::basic::util::set_strides_by_shape((int32_t) sizeof(int32_t), 4, strides, shape);
|
|
|
|
int32_t expected_strides[4] = {
|
|
105 * sizeof(int32_t),
|
|
35 * sizeof(int32_t),
|
|
7 * sizeof(int32_t),
|
|
1 * sizeof(int32_t)
|
|
};
|
|
assert_arrays_match(4, expected_strides, strides);
|
|
}
|
|
|
|
void run() {
|
|
test_calc_size_from_shape_normal();
|
|
test_calc_size_from_shape_has_zero();
|
|
test_set_strides_by_shape();
|
|
}
|
|
}
|
|
} |