[test_buffer]

improved check()
This commit is contained in:
2025-11-05 09:04:11 +01:00
parent bb873d49d4
commit 3ee368f484
2 changed files with 34 additions and 16 deletions
+7 -13
View File
@@ -14,18 +14,21 @@ int test_buffer_1()
dsp::Buffer<int> buffer(10);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < 10; i++)
for (int i=0; i < buffer.capacity(); i++)
{
buffer[i] = i+100;
}
buffer += 5;
{
dsp::Buffer<int> t_buf{105, 106, 107, 108, 109};
check(buffer, t_buf, t_buf.capacity());
}
dsp::Buffer<int> res_buf(5);
for (int i=0; i < res_buf.capacity(); i++)
{
int v = buffer[i-5];
res_buf[i] = v;
printf("i=%d: v=%d\n", i, v);
}
dsp::Buffer<int> t_buf{100, 101, 102, 103, 104};
@@ -47,21 +50,12 @@ int test_buffer_2()
std::cout << "Start test_buffer_2" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
dsp::Buffer<int> buffer(10);
dsp::Buffer<int> buffer(5);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < 10; i++)
for (int i=0; i < buffer.capacity(); i++)
{
buffer[i] = i+100;
}
buffer += 5;
for (int i=-5; i < 5; i++)
{
int v = buffer[i];
printf("i=%d: v=%d\n", i, v);
}
buffer.reset();
const auto v1 = dsp::Buffer<int>(buffer, -1);
const auto v2 = dsp::Buffer<int>(buffer, -5);
+27 -3
View File
@@ -1,3 +1,4 @@
#include <cmath>
#include <delay/buffer_multi.hpp>
#include <delay/buffer.hpp>
#include <cstdio>
@@ -21,15 +22,38 @@ void print(const dsp::Buffer<T> &v, size_t size, std::string name=std::string(""
}
template<typename T>
void check(const dsp::Buffer<T> &target, const dsp::Buffer<T> &actual)
void check(const dsp::Buffer<T> &target, const dsp::Buffer<T> &actual, size_t size=0)
{
if (!(target == actual))
bool success = false;
do
{
if (size == 0)
{
if (target.capacity() != actual.capacity())
{
break;
}
size = target.capacity();
}
for (int i=0; i < size; i++)
{
if (target[i] != actual[i])
{
break;
}
}
success = true;
} while(false);
if (!success)
{
std::cout << "Check failed" << std::endl;
print(target, target.capacity(), "Target");
print(actual, actual.capacity(), "Actual");
}
assert(target == actual);
assert(success);
}
#endif