mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-23 20:07:59 +02:00
fix ci and add formatting (#48)
* add dependency * dont run blocking zmq example and add formatting * format files
This commit is contained in:
@ -1,116 +1,116 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "aare/CircularFifo.hpp"
|
||||
#include "aare/CircularFifo.hpp"
|
||||
|
||||
using aare::CircularFifo;
|
||||
using aare::CircularFifo;
|
||||
|
||||
// Only for testing. To make sure we can avoid copy constructor
|
||||
// and copy assignment
|
||||
// Only for testing. To make sure we can avoid copy constructor
|
||||
// and copy assignment
|
||||
|
||||
struct MoveOnlyInt {
|
||||
int value{};
|
||||
struct MoveOnlyInt {
|
||||
int value{};
|
||||
|
||||
MoveOnlyInt() = default;
|
||||
MoveOnlyInt(int i) : value(i){};
|
||||
MoveOnlyInt(const MoveOnlyInt &) = delete;
|
||||
MoveOnlyInt &operator=(const MoveOnlyInt &) = delete;
|
||||
MoveOnlyInt(MoveOnlyInt &&other) { std::swap(value, other.value); }
|
||||
MoveOnlyInt &operator=(MoveOnlyInt &&other) {
|
||||
std::swap(value, other.value);
|
||||
return *this;
|
||||
}
|
||||
bool operator==(int other) const { return value == other; }
|
||||
};
|
||||
MoveOnlyInt() = default;
|
||||
MoveOnlyInt(int i) : value(i){};
|
||||
MoveOnlyInt(const MoveOnlyInt &) = delete;
|
||||
MoveOnlyInt &operator=(const MoveOnlyInt &) = delete;
|
||||
MoveOnlyInt(MoveOnlyInt &&other) { std::swap(value, other.value); }
|
||||
MoveOnlyInt &operator=(MoveOnlyInt &&other) {
|
||||
std::swap(value, other.value);
|
||||
return *this;
|
||||
}
|
||||
bool operator==(int other) const { return value == other; }
|
||||
};
|
||||
|
||||
TEST_CASE("CircularFifo can be default constructed") { CircularFifo<MoveOnlyInt> f; }
|
||||
TEST_CASE("CircularFifo can be default constructed") { CircularFifo<MoveOnlyInt> f; }
|
||||
|
||||
TEST_CASE("Newly constructed fifo has the right size") {
|
||||
size_t size = 17;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
CHECK(f.numFreeSlots() == size);
|
||||
CHECK(f.numFilledSlots() == 0);
|
||||
}
|
||||
TEST_CASE("Newly constructed fifo has the right size") {
|
||||
size_t size = 17;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
CHECK(f.numFreeSlots() == size);
|
||||
CHECK(f.numFilledSlots() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Can fit size number of objects") {
|
||||
size_t size = 8;
|
||||
size_t numPushedItems = 0;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
MoveOnlyInt a;
|
||||
bool popped = f.try_pop_free(a);
|
||||
CHECK(popped);
|
||||
if (popped) {
|
||||
a.value = i;
|
||||
bool pushed = f.try_push_value(std::move(a));
|
||||
CHECK(pushed);
|
||||
if (pushed)
|
||||
numPushedItems++;
|
||||
}
|
||||
}
|
||||
CHECK(f.numFreeSlots() == 0);
|
||||
CHECK(f.numFilledSlots() == size);
|
||||
CHECK(numPushedItems == size);
|
||||
}
|
||||
TEST_CASE("Can fit size number of objects") {
|
||||
size_t size = 8;
|
||||
size_t numPushedItems = 0;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
MoveOnlyInt a;
|
||||
bool popped = f.try_pop_free(a);
|
||||
CHECK(popped);
|
||||
if (popped) {
|
||||
a.value = i;
|
||||
bool pushed = f.try_push_value(std::move(a));
|
||||
CHECK(pushed);
|
||||
if (pushed)
|
||||
numPushedItems++;
|
||||
}
|
||||
}
|
||||
CHECK(f.numFreeSlots() == 0);
|
||||
CHECK(f.numFilledSlots() == size);
|
||||
CHECK(numPushedItems == size);
|
||||
}
|
||||
|
||||
TEST_CASE("Push move only type") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
f.push_value(5);
|
||||
}
|
||||
TEST_CASE("Push move only type") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
f.push_value(5);
|
||||
}
|
||||
|
||||
TEST_CASE("Push pop") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
f.push_value(MoveOnlyInt(1));
|
||||
TEST_CASE("Push pop") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
f.push_value(MoveOnlyInt(1));
|
||||
|
||||
auto a = f.pop_value();
|
||||
CHECK(a == 1);
|
||||
}
|
||||
auto a = f.pop_value();
|
||||
CHECK(a == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Pop free and then push") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
TEST_CASE("Pop free and then push") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
|
||||
auto a = f.pop_free();
|
||||
a.value = 5;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
auto b = f.pop_value();
|
||||
auto a = f.pop_free();
|
||||
a.value = 5;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
auto b = f.pop_value();
|
||||
|
||||
CHECK(a == 0); // Moved from value
|
||||
CHECK(b == 5); // Original value
|
||||
}
|
||||
CHECK(a == 0); // Moved from value
|
||||
CHECK(b == 5); // Original value
|
||||
}
|
||||
|
||||
TEST_CASE("Skip the first value") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
TEST_CASE("Skip the first value") {
|
||||
CircularFifo<MoveOnlyInt> f;
|
||||
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
auto a = f.pop_free();
|
||||
a.value = i + 1;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
}
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
auto a = f.pop_free();
|
||||
a.value = i + 1;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
}
|
||||
|
||||
auto b = f.pop_value();
|
||||
CHECK(b == 1);
|
||||
f.next();
|
||||
auto c = f.pop_value();
|
||||
CHECK(c == 3);
|
||||
}
|
||||
auto b = f.pop_value();
|
||||
CHECK(b == 1);
|
||||
f.next();
|
||||
auto c = f.pop_value();
|
||||
CHECK(c == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Use in place and move to free") {
|
||||
size_t size = 18;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
TEST_CASE("Use in place and move to free") {
|
||||
size_t size = 18;
|
||||
CircularFifo<MoveOnlyInt> f(size);
|
||||
|
||||
//Push 10 values to the fifo
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
auto a = f.pop_free();
|
||||
a.value = i + 1;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
}
|
||||
// Push 10 values to the fifo
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
auto a = f.pop_free();
|
||||
a.value = i + 1;
|
||||
f.push_value(std::move(a)); // Explicit move since we can't copy
|
||||
}
|
||||
|
||||
auto b = f.frontPtr();
|
||||
CHECK(*b == 1);
|
||||
CHECK(f.numFilledSlots() == 10);
|
||||
CHECK(f.numFreeSlots() == size-10);
|
||||
f.next();
|
||||
auto c = f.frontPtr();
|
||||
CHECK(*c == 2);
|
||||
CHECK(f.numFilledSlots() == 9);
|
||||
CHECK(f.numFreeSlots() == size-9);
|
||||
}
|
||||
auto b = f.frontPtr();
|
||||
CHECK(*b == 1);
|
||||
CHECK(f.numFilledSlots() == 10);
|
||||
CHECK(f.numFreeSlots() == size - 10);
|
||||
f.next();
|
||||
auto c = f.frontPtr();
|
||||
CHECK(*c == 2);
|
||||
CHECK(f.numFilledSlots() == 9);
|
||||
CHECK(f.numFreeSlots() == size - 9);
|
||||
}
|
||||
|
@ -6,15 +6,13 @@
|
||||
using aare::DType;
|
||||
using aare::endian;
|
||||
|
||||
|
||||
|
||||
TEST_CASE("Construct from typeid") {
|
||||
REQUIRE(DType(typeid(int)) == typeid(int));
|
||||
REQUIRE(DType(typeid(int)) != typeid(double));
|
||||
}
|
||||
|
||||
TEST_CASE("Construct from string") {
|
||||
if (endian::native == endian::little){
|
||||
if (endian::native == endian::little) {
|
||||
REQUIRE(DType("<i1") == typeid(int8_t));
|
||||
REQUIRE(DType("<u1") == typeid(uint8_t));
|
||||
REQUIRE(DType("<i2") == typeid(int16_t));
|
||||
@ -30,7 +28,7 @@ TEST_CASE("Construct from string") {
|
||||
REQUIRE(DType("f8") == typeid(double));
|
||||
}
|
||||
|
||||
if (endian::native == endian::big){
|
||||
if (endian::native == endian::big) {
|
||||
REQUIRE(DType(">i1") == typeid(int8_t));
|
||||
REQUIRE(DType(">u1") == typeid(uint8_t));
|
||||
REQUIRE(DType(">i2") == typeid(int16_t));
|
||||
@ -45,14 +43,12 @@ TEST_CASE("Construct from string") {
|
||||
REQUIRE(DType("f4") == typeid(float));
|
||||
REQUIRE(DType("f8") == typeid(double));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Construct from string with endianess"){
|
||||
//TODO! handle big endian system in test!
|
||||
TEST_CASE("Construct from string with endianess") {
|
||||
// TODO! handle big endian system in test!
|
||||
REQUIRE(DType("<i4") == typeid(int32_t));
|
||||
REQUIRE_THROWS(DType(">i4") == typeid(int32_t));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Convert to string") { REQUIRE(DType(typeid(int)).str() == "<i4"); }
|
@ -3,7 +3,7 @@
|
||||
|
||||
using aare::Frame;
|
||||
|
||||
TEST_CASE("Construct a frame"){
|
||||
TEST_CASE("Construct a frame") {
|
||||
ssize_t rows = 10;
|
||||
ssize_t cols = 10;
|
||||
ssize_t bitdepth = 8;
|
||||
@ -13,20 +13,19 @@ TEST_CASE("Construct a frame"){
|
||||
REQUIRE(frame.rows() == rows);
|
||||
REQUIRE(frame.cols() == cols);
|
||||
REQUIRE(frame.bitdepth() == bitdepth);
|
||||
REQUIRE(frame.size() == rows*cols*bitdepth/8);
|
||||
|
||||
REQUIRE(frame.size() == rows * cols * bitdepth / 8);
|
||||
|
||||
// data should be initialized to 0
|
||||
for (int i = 0; i < rows; i++){
|
||||
for (int j = 0; j < cols; j++){
|
||||
uint8_t *data = (uint8_t*)frame.get(i, j);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
uint8_t *data = (uint8_t *)frame.get(i, j);
|
||||
REQUIRE(data != nullptr);
|
||||
REQUIRE(*data == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Set a value in a 8 bit frame"){
|
||||
TEST_CASE("Set a value in a 8 bit frame") {
|
||||
ssize_t rows = 10;
|
||||
ssize_t cols = 10;
|
||||
ssize_t bitdepth = 8;
|
||||
@ -37,13 +36,12 @@ TEST_CASE("Set a value in a 8 bit frame"){
|
||||
uint8_t value = 255;
|
||||
frame.set(5, 7, value);
|
||||
|
||||
|
||||
// only the value we did set should be non-zero
|
||||
for (int i = 0; i < rows; i++){
|
||||
for (int j = 0; j < cols; j++){
|
||||
uint8_t *data = (uint8_t*)frame.get(i, j);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
uint8_t *data = (uint8_t *)frame.get(i, j);
|
||||
REQUIRE(data != nullptr);
|
||||
if (i == 5 && j == 7){
|
||||
if (i == 5 && j == 7) {
|
||||
REQUIRE(*data == value);
|
||||
} else {
|
||||
REQUIRE(*data == 0);
|
||||
@ -52,7 +50,7 @@ TEST_CASE("Set a value in a 8 bit frame"){
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Set a value in a 64 bit frame"){
|
||||
TEST_CASE("Set a value in a 64 bit frame") {
|
||||
ssize_t rows = 10;
|
||||
ssize_t cols = 10;
|
||||
ssize_t bitdepth = 64;
|
||||
@ -63,13 +61,12 @@ TEST_CASE("Set a value in a 64 bit frame"){
|
||||
uint64_t value = 255;
|
||||
frame.set(5, 7, value);
|
||||
|
||||
|
||||
// only the value we did set should be non-zero
|
||||
for (int i = 0; i < rows; i++){
|
||||
for (int j = 0; j < cols; j++){
|
||||
uint64_t *data = (uint64_t*)frame.get(i, j);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
uint64_t *data = (uint64_t *)frame.get(i, j);
|
||||
REQUIRE(data != nullptr);
|
||||
if (i == 5 && j == 7){
|
||||
if (i == 5 && j == 7) {
|
||||
REQUIRE(*data == value);
|
||||
} else {
|
||||
REQUIRE(*data == 0);
|
||||
@ -78,28 +75,27 @@ TEST_CASE("Set a value in a 64 bit frame"){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Move construct a frame"){
|
||||
TEST_CASE("Move construct a frame") {
|
||||
ssize_t rows = 10;
|
||||
ssize_t cols = 10;
|
||||
ssize_t bitdepth = 8;
|
||||
|
||||
Frame frame(rows, cols, bitdepth);
|
||||
std::byte* data = frame.data();
|
||||
std::byte *data = frame.data();
|
||||
|
||||
Frame frame2(std::move(frame));
|
||||
|
||||
//state of the moved from object
|
||||
// state of the moved from object
|
||||
REQUIRE(frame.rows() == 0);
|
||||
REQUIRE(frame.cols() == 0);
|
||||
REQUIRE(frame.bitdepth() == 0);
|
||||
REQUIRE(frame.size() == 0);
|
||||
REQUIRE(frame.data() == nullptr);
|
||||
|
||||
//state of the moved to object
|
||||
// state of the moved to object
|
||||
REQUIRE(frame2.rows() == rows);
|
||||
REQUIRE(frame2.cols() == cols);
|
||||
REQUIRE(frame2.bitdepth() == bitdepth);
|
||||
REQUIRE(frame2.size() == rows*cols*bitdepth/8);
|
||||
REQUIRE(frame2.size() == rows * cols * bitdepth / 8);
|
||||
REQUIRE(frame2.data() == data);
|
||||
}
|
@ -1,67 +1,58 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "aare/NDArray.hpp"
|
||||
#include <array>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
using aare::NDArray;
|
||||
using aare::NDView;
|
||||
using aare::Shape;
|
||||
|
||||
|
||||
TEST_CASE("Initial size is zero if no size is specified")
|
||||
{
|
||||
TEST_CASE("Initial size is zero if no size is specified") {
|
||||
NDArray<double> a;
|
||||
REQUIRE(a.size() == 0);
|
||||
REQUIRE(a.shape() == Shape<2>{0,0});
|
||||
REQUIRE(a.shape() == Shape<2>{0, 0});
|
||||
}
|
||||
|
||||
TEST_CASE("Construct from a DataSpan") {
|
||||
std::vector<int> some_data(9, 42);
|
||||
NDView<int, 2> view(some_data.data(), Shape<2>{3, 3});
|
||||
|
||||
TEST_CASE("Construct from a DataSpan"){
|
||||
std::vector<int> some_data(9,42);
|
||||
NDView<int, 2> view(some_data.data(), Shape<2>{3,3});
|
||||
|
||||
NDArray<int,2> image(view);
|
||||
NDArray<int, 2> image(view);
|
||||
|
||||
REQUIRE(image.shape() == view.shape());
|
||||
REQUIRE(image.size() == view.size());
|
||||
REQUIRE(image.data() != view.data());
|
||||
|
||||
for (int i = 0; i<image.size(); ++i){
|
||||
for (int i = 0; i < image.size(); ++i) {
|
||||
REQUIRE(image(i) == view(i));
|
||||
}
|
||||
|
||||
//Changing the image doesn't change the view
|
||||
// Changing the image doesn't change the view
|
||||
image = 43;
|
||||
for (int i = 0; i<image.size(); ++i){
|
||||
for (int i = 0; i < image.size(); ++i) {
|
||||
REQUIRE(image(i) != view(i));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("1D image"){
|
||||
std::array<ssize_t, 1>shape{{20}};
|
||||
NDArray<short,1>img(shape,3);
|
||||
REQUIRE(img.size()==20);
|
||||
REQUIRE(img(5)==3);
|
||||
|
||||
TEST_CASE("1D image") {
|
||||
std::array<ssize_t, 1> shape{{20}};
|
||||
NDArray<short, 1> img(shape, 3);
|
||||
REQUIRE(img.size() == 20);
|
||||
REQUIRE(img(5) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Accessing a const object"){
|
||||
const NDArray<double, 3> img({3,4,5}, 0);
|
||||
REQUIRE(img(1,1,1)==0);
|
||||
REQUIRE(img.size() == 3*4*5);
|
||||
REQUIRE(img.shape() == Shape<3>{3,4,5});
|
||||
TEST_CASE("Accessing a const object") {
|
||||
const NDArray<double, 3> img({3, 4, 5}, 0);
|
||||
REQUIRE(img(1, 1, 1) == 0);
|
||||
REQUIRE(img.size() == 3 * 4 * 5);
|
||||
REQUIRE(img.shape() == Shape<3>{3, 4, 5});
|
||||
REQUIRE(img.shape(0) == 3);
|
||||
REQUIRE(img.shape(1) == 4);
|
||||
REQUIRE(img.shape(2) == 5);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Indexing of a 2D image")
|
||||
{
|
||||
std::array<ssize_t, 2>shape{{ 3, 7 }};
|
||||
NDArray<long> img( shape, 5 );
|
||||
TEST_CASE("Indexing of a 2D image") {
|
||||
std::array<ssize_t, 2> shape{{3, 7}};
|
||||
NDArray<long> img(shape, 5);
|
||||
for (int i = 0; i != img.size(); ++i) {
|
||||
REQUIRE(img(i) == 5);
|
||||
}
|
||||
@ -74,14 +65,13 @@ TEST_CASE("Indexing of a 2D image")
|
||||
REQUIRE(img(1, 0) == 7);
|
||||
}
|
||||
|
||||
TEST_CASE("Indexing of a 3D image")
|
||||
{
|
||||
NDArray<float, 3> img{ {{ 3, 4, 2 }}, 5.0f };
|
||||
TEST_CASE("Indexing of a 3D image") {
|
||||
NDArray<float, 3> img{{{3, 4, 2}}, 5.0f};
|
||||
for (int i = 0; i != img.size(); ++i) {
|
||||
REQUIRE(img(i) == 5.0f);
|
||||
}
|
||||
|
||||
//Double check general properties
|
||||
// Double check general properties
|
||||
REQUIRE(img.size() == 3 * 4 * 2);
|
||||
|
||||
for (int i = 0; i != img.size(); ++i) {
|
||||
@ -94,21 +84,19 @@ TEST_CASE("Indexing of a 3D image")
|
||||
REQUIRE(img(2, 3, 1) == 23);
|
||||
}
|
||||
|
||||
TEST_CASE("Divide double by int"){
|
||||
NDArray<double,1> a{{5}, 5};
|
||||
NDArray<int,1> b{{5},5};
|
||||
a /=b;
|
||||
for (auto it : a){
|
||||
TEST_CASE("Divide double by int") {
|
||||
NDArray<double, 1> a{{5}, 5};
|
||||
NDArray<int, 1> b{{5}, 5};
|
||||
a /= b;
|
||||
for (auto it : a) {
|
||||
REQUIRE(it == 1.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Elementwise multiplication of 3D image")
|
||||
{
|
||||
std::array<ssize_t, 3>shape{3, 4, 2};
|
||||
NDArray<double, 3> a{ shape };
|
||||
NDArray<double, 3> b{ shape };
|
||||
TEST_CASE("Elementwise multiplication of 3D image") {
|
||||
std::array<ssize_t, 3> shape{3, 4, 2};
|
||||
NDArray<double, 3> a{shape};
|
||||
NDArray<double, 3> b{shape};
|
||||
for (int i = 0; i != a.size(); ++i) {
|
||||
a(i) = i;
|
||||
b(i) = i;
|
||||
@ -121,55 +109,51 @@ TEST_CASE("Elementwise multiplication of 3D image")
|
||||
REQUIRE(c(2, 3, 1) == 23 * 23);
|
||||
}
|
||||
|
||||
TEST_CASE("Compare two images")
|
||||
{
|
||||
TEST_CASE("Compare two images") {
|
||||
NDArray<int> a;
|
||||
NDArray<int> b;
|
||||
CHECK(a == b);
|
||||
|
||||
a = NDArray<int>{ { 5, 10 }, 0 };
|
||||
a = NDArray<int>{{5, 10}, 0};
|
||||
CHECK(a != b);
|
||||
|
||||
b = NDArray<int>{ { 5, 10 }, 0 };
|
||||
b = NDArray<int>{{5, 10}, 0};
|
||||
CHECK(a == b);
|
||||
|
||||
b(3, 3) = 7;
|
||||
CHECK(a != b);
|
||||
}
|
||||
|
||||
TEST_CASE("Size and shape matches")
|
||||
{
|
||||
TEST_CASE("Size and shape matches") {
|
||||
ssize_t w = 15;
|
||||
ssize_t h = 75;
|
||||
std::array<ssize_t, 2> shape{ w, h };
|
||||
NDArray<double> a{ shape };
|
||||
std::array<ssize_t, 2> shape{w, h};
|
||||
NDArray<double> a{shape};
|
||||
REQUIRE(a.size() == w * h);
|
||||
REQUIRE(a.shape() == shape);
|
||||
}
|
||||
|
||||
TEST_CASE("Initial value matches for all elements")
|
||||
{
|
||||
TEST_CASE("Initial value matches for all elements") {
|
||||
double v = 4.35;
|
||||
NDArray<double> a{ { 5, 5 }, v };
|
||||
NDArray<double> a{{5, 5}, v};
|
||||
for (int i = 0; i < a.size(); ++i) {
|
||||
REQUIRE(a(i) == v);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Data layout of 3D image, fast index last"){
|
||||
NDArray<int,3> a{{3,3,3}, 0};
|
||||
REQUIRE(a.size()== 27);
|
||||
int* ptr = a.data();
|
||||
|
||||
for (int i = 0; i<9; ++i){
|
||||
*ptr++ = 10+i;
|
||||
REQUIRE(a(0,0,i) == 10+i);
|
||||
REQUIRE(a(i) == 10+i);
|
||||
TEST_CASE("Data layout of 3D image, fast index last") {
|
||||
NDArray<int, 3> a{{3, 3, 3}, 0};
|
||||
REQUIRE(a.size() == 27);
|
||||
int *ptr = a.data();
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
*ptr++ = 10 + i;
|
||||
REQUIRE(a(0, 0, i) == 10 + i);
|
||||
REQUIRE(a(i) == 10 + i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Bitwise and on data"){
|
||||
TEST_CASE("Bitwise and on data") {
|
||||
|
||||
NDArray<uint16_t, 1> a({3}, 0);
|
||||
uint16_t mask = 0x3FF;
|
||||
@ -182,7 +166,6 @@ TEST_CASE("Bitwise and on data"){
|
||||
REQUIRE(a(0) == 300);
|
||||
REQUIRE(a(1) == 300);
|
||||
REQUIRE(a(2) == 384);
|
||||
|
||||
}
|
||||
|
||||
// TEST_CASE("Benchmarks")
|
||||
@ -220,182 +203,173 @@ TEST_CASE("Bitwise and on data"){
|
||||
// }
|
||||
// }
|
||||
|
||||
TEST_CASE("Elementwise operatios on images")
|
||||
{
|
||||
std::array<ssize_t, 2> shape{ 5, 5 };
|
||||
TEST_CASE("Elementwise operatios on images") {
|
||||
std::array<ssize_t, 2> shape{5, 5};
|
||||
double a_val = 3.0;
|
||||
double b_val = 8.0;
|
||||
|
||||
SECTION("Add two images")
|
||||
{
|
||||
SECTION("Add two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
|
||||
auto C = A + B;
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val + b_val);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
|
||||
//Value of B is not changed
|
||||
// Value of B is not changed
|
||||
for (int i = 0; i < B.size(); ++i) {
|
||||
REQUIRE(B(i) == b_val);
|
||||
}
|
||||
|
||||
//A, B and C referes to different data
|
||||
// A, B and C referes to different data
|
||||
REQUIRE(A.data() != B.data());
|
||||
REQUIRE(B.data() != C.data());
|
||||
}
|
||||
SECTION("Subtract two images")
|
||||
{
|
||||
SECTION("Subtract two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A - B;
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val - b_val);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
|
||||
//Value of B is not changed
|
||||
// Value of B is not changed
|
||||
for (int i = 0; i < B.size(); ++i) {
|
||||
REQUIRE(B(i) == b_val);
|
||||
}
|
||||
|
||||
//A, B and C referes to different data
|
||||
// A, B and C referes to different data
|
||||
REQUIRE(A.data() != B.data());
|
||||
REQUIRE(B.data() != C.data());
|
||||
}
|
||||
SECTION("Multiply two images")
|
||||
{
|
||||
SECTION("Multiply two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A * B;
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val * b_val);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
|
||||
//Value of B is not changed
|
||||
// Value of B is not changed
|
||||
for (int i = 0; i < B.size(); ++i) {
|
||||
REQUIRE(B(i) == b_val);
|
||||
}
|
||||
|
||||
//A, B and C referes to different data
|
||||
// A, B and C referes to different data
|
||||
REQUIRE(A.data() != B.data());
|
||||
REQUIRE(B.data() != C.data());
|
||||
}
|
||||
SECTION("Divide two images")
|
||||
{
|
||||
SECTION("Divide two images") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
auto C = A / B;
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val / b_val);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
|
||||
//Value of B is not changed
|
||||
// Value of B is not changed
|
||||
for (int i = 0; i < B.size(); ++i) {
|
||||
REQUIRE(B(i) == b_val);
|
||||
}
|
||||
|
||||
//A, B and C referes to different data
|
||||
// A, B and C referes to different data
|
||||
REQUIRE(A.data() != B.data());
|
||||
REQUIRE(B.data() != C.data());
|
||||
}
|
||||
|
||||
SECTION("subtract scalar")
|
||||
{
|
||||
SECTION("subtract scalar") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
double v = 1.0;
|
||||
auto C = A - v;
|
||||
auto C = A - v;
|
||||
REQUIRE(C.data() != A.data());
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val - v);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
}
|
||||
SECTION("add scalar")
|
||||
{
|
||||
SECTION("add scalar") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
double v = 1.0;
|
||||
auto C = A + v;
|
||||
auto C = A + v;
|
||||
REQUIRE(C.data() != A.data());
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val + v);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
}
|
||||
SECTION("divide with scalar")
|
||||
{
|
||||
SECTION("divide with scalar") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
double v = 3.7;
|
||||
auto C = A / v;
|
||||
auto C = A / v;
|
||||
REQUIRE(C.data() != A.data());
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val / v);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
}
|
||||
SECTION("multiply with scalar")
|
||||
{
|
||||
SECTION("multiply with scalar") {
|
||||
NDArray<double> A(shape, a_val);
|
||||
NDArray<double> B(shape, b_val);
|
||||
double v = 3.7;
|
||||
auto C = A / v;
|
||||
auto C = A / v;
|
||||
REQUIRE(C.data() != A.data());
|
||||
|
||||
//Value of C matches
|
||||
// Value of C matches
|
||||
for (int i = 0; i < C.size(); ++i) {
|
||||
REQUIRE(C(i) == a_val / v);
|
||||
}
|
||||
|
||||
//Value of A is not changed
|
||||
// Value of A is not changed
|
||||
for (int i = 0; i < A.size(); ++i) {
|
||||
REQUIRE(A(i) == a_val);
|
||||
}
|
||||
|
@ -105,12 +105,12 @@ TEST_CASE("Multiply and divide with single value") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("elementwise assign"){
|
||||
TEST_CASE("elementwise assign") {
|
||||
std::vector<int> vec(25);
|
||||
NDView<int, 2> data(vec.data(), Shape<2>{5,5});
|
||||
NDView<int, 2> data(vec.data(), Shape<2>{5, 5});
|
||||
|
||||
data = 3;
|
||||
for (auto it : data){
|
||||
for (auto it : data) {
|
||||
REQUIRE(it == 3);
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ TEST_CASE("iterators") {
|
||||
for (auto ptr = data.begin(); ptr != data.end(); ++ptr) {
|
||||
*ptr += 1;
|
||||
}
|
||||
for (auto& item : data){
|
||||
for (auto &item : data) {
|
||||
++item;
|
||||
}
|
||||
|
||||
@ -142,54 +142,52 @@ TEST_CASE("iterators") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("shape from vector"){
|
||||
TEST_CASE("shape from vector") {
|
||||
std::vector<int> vec;
|
||||
for (int i = 0; i != 12; ++i) {
|
||||
vec.push_back(i);
|
||||
}
|
||||
std::vector<ssize_t> shape{3,4};
|
||||
NDView<int,2> data(vec.data(), shape);
|
||||
std::vector<ssize_t> shape{3, 4};
|
||||
NDView<int, 2> data(vec.data(), shape);
|
||||
}
|
||||
|
||||
TEST_CASE("divide with another span"){
|
||||
std::vector<int> vec0{9,12,3};
|
||||
std::vector<int> vec1{3,2,1};
|
||||
std::vector<int> result{3,6,3};
|
||||
TEST_CASE("divide with another span") {
|
||||
std::vector<int> vec0{9, 12, 3};
|
||||
std::vector<int> vec1{3, 2, 1};
|
||||
std::vector<int> result{3, 6, 3};
|
||||
|
||||
NDView<int, 1> data0(vec0.data(), Shape<1>{static_cast<ssize_t>(vec0.size())});
|
||||
NDView<int, 1> data1(vec1.data(), Shape<1>{static_cast<ssize_t>(vec1.size())});
|
||||
|
||||
data0 /= data1;
|
||||
|
||||
for(size_t i =0; i!=vec0.size(); ++i){
|
||||
REQUIRE(data0[i] == result[i] );
|
||||
|
||||
for (size_t i = 0; i != vec0.size(); ++i) {
|
||||
REQUIRE(data0[i] == result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Retrieve shape"){
|
||||
TEST_CASE("Retrieve shape") {
|
||||
std::vector<int> vec;
|
||||
for (int i = 0; i != 12; ++i) {
|
||||
vec.push_back(i);
|
||||
}
|
||||
NDView<int,2> data(vec.data(), Shape<2>{3,4});
|
||||
NDView<int, 2> data(vec.data(), Shape<2>{3, 4});
|
||||
REQUIRE(data.shape()[0] == 3);
|
||||
REQUIRE(data.shape()[1] == 4);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("compare two views"){
|
||||
TEST_CASE("compare two views") {
|
||||
std::vector<int> vec1;
|
||||
for (int i = 0; i != 12; ++i) {
|
||||
vec1.push_back(i);
|
||||
}
|
||||
NDView<int,2> view1(vec1.data(), Shape<2>{3,4});
|
||||
NDView<int, 2> view1(vec1.data(), Shape<2>{3, 4});
|
||||
|
||||
std::vector<int> vec2;
|
||||
for (int i = 0; i != 12; ++i) {
|
||||
vec2.push_back(i);
|
||||
}
|
||||
NDView<int,2> view2(vec2.data(), Shape<2>{3,4});
|
||||
NDView<int, 2> view2(vec2.data(), Shape<2>{3, 4});
|
||||
|
||||
REQUIRE(view1 == view2);
|
||||
}
|
@ -1,49 +1,49 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include "aare/ProducerConsumerQueue.hpp"
|
||||
#include "aare/ProducerConsumerQueue.hpp"
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
// using arve::SimpleQueue;
|
||||
TEST_CASE("push pop"){
|
||||
// using arve::SimpleQueue;
|
||||
TEST_CASE("push pop") {
|
||||
|
||||
folly::ProducerConsumerQueue<int> q(5);
|
||||
int a = 3;
|
||||
int b = 8;
|
||||
CHECK(q.sizeGuess() == 0);
|
||||
CHECK(q.write(a));
|
||||
CHECK(q.sizeGuess() == 1);
|
||||
CHECK(q.write(b));
|
||||
CHECK(q.sizeGuess() == 2);
|
||||
int c = 0;
|
||||
folly::ProducerConsumerQueue<int> q(5);
|
||||
int a = 3;
|
||||
int b = 8;
|
||||
CHECK(q.sizeGuess() == 0);
|
||||
CHECK(q.write(a));
|
||||
CHECK(q.sizeGuess() == 1);
|
||||
CHECK(q.write(b));
|
||||
CHECK(q.sizeGuess() == 2);
|
||||
int c = 0;
|
||||
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 3);
|
||||
CHECK(q.sizeGuess() == 1);
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 8);
|
||||
CHECK(q.sizeGuess() == 0);
|
||||
}
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 3);
|
||||
CHECK(q.sizeGuess() == 1);
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 8);
|
||||
CHECK(q.sizeGuess() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Cannot push to a full queue"){
|
||||
folly::ProducerConsumerQueue<int> q(3);
|
||||
int a = 3;
|
||||
int b = 4;
|
||||
int c = 0;
|
||||
CHECK(q.write(a));
|
||||
CHECK(q.write(b));
|
||||
CHECK_FALSE(q.write(a));
|
||||
TEST_CASE("Cannot push to a full queue") {
|
||||
folly::ProducerConsumerQueue<int> q(3);
|
||||
int a = 3;
|
||||
int b = 4;
|
||||
int c = 0;
|
||||
CHECK(q.write(a));
|
||||
CHECK(q.write(b));
|
||||
CHECK_FALSE(q.write(a));
|
||||
|
||||
//values are still ok
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 3);
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 4);
|
||||
}
|
||||
// values are still ok
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 3);
|
||||
CHECK(q.read(c));
|
||||
CHECK(c == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("Cannot pop from an empty queue"){
|
||||
folly::ProducerConsumerQueue<int> q(2);
|
||||
int a=0;
|
||||
CHECK_FALSE(q.read(a));
|
||||
}
|
||||
TEST_CASE("Cannot pop from an empty queue") {
|
||||
folly::ProducerConsumerQueue<int> q(2);
|
||||
int a = 0;
|
||||
CHECK_FALSE(q.read(a));
|
||||
}
|
||||
|
||||
// TEST_CASE("fail"){
|
||||
// CHECK(false);
|
||||
// }
|
||||
// TEST_CASE("fail"){
|
||||
// CHECK(false);
|
||||
// }
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "aare/defs.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <string>
|
||||
#include "aare/defs.hpp"
|
||||
TEST_CASE("Enum to string conversion"){
|
||||
//By the way I don't think the enum string conversions should be in the defs.hpp file
|
||||
//but let's use this to show a test
|
||||
TEST_CASE("Enum to string conversion") {
|
||||
// By the way I don't think the enum string conversions should be in the defs.hpp file
|
||||
// but let's use this to show a test
|
||||
REQUIRE(toString(aare::DetectorType::Jungfrau) == "Jungfrau");
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
#include <aare/NDView.hpp>
|
||||
#include <aare/Frame.hpp>
|
||||
#include <aare/NDView.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
using aare::Frame;
|
||||
using aare::NDView;
|
||||
using aare::NDArray;
|
||||
using aare::NDView;
|
||||
|
||||
TEST_CASE("Frame") {
|
||||
auto data = new uint16_t[100];
|
||||
|
Reference in New Issue
Block a user