[test_buffer]
improved check()
This commit is contained in:
@@ -14,18 +14,21 @@ int test_buffer_1()
|
|||||||
|
|
||||||
dsp::Buffer<int> buffer(10);
|
dsp::Buffer<int> buffer(10);
|
||||||
printf("Buffer capacity = %zu\n", buffer.capacity());
|
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[i] = i+100;
|
||||||
}
|
}
|
||||||
buffer += 5;
|
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);
|
dsp::Buffer<int> res_buf(5);
|
||||||
for (int i=0; i < res_buf.capacity(); i++)
|
for (int i=0; i < res_buf.capacity(); i++)
|
||||||
{
|
{
|
||||||
int v = buffer[i-5];
|
int v = buffer[i-5];
|
||||||
res_buf[i] = v;
|
res_buf[i] = v;
|
||||||
printf("i=%d: v=%d\n", i, v);
|
|
||||||
}
|
}
|
||||||
dsp::Buffer<int> t_buf{100, 101, 102, 103, 104};
|
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 << "Start test_buffer_2" << std::endl;
|
||||||
std::cout << "----------------------------------------------" << std::endl;
|
std::cout << "----------------------------------------------" << std::endl;
|
||||||
|
|
||||||
dsp::Buffer<int> buffer(10);
|
dsp::Buffer<int> buffer(5);
|
||||||
printf("Buffer capacity = %zu\n", buffer.capacity());
|
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[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 v1 = dsp::Buffer<int>(buffer, -1);
|
||||||
const auto v2 = dsp::Buffer<int>(buffer, -5);
|
const auto v2 = dsp::Buffer<int>(buffer, -5);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <cmath>
|
||||||
#include <delay/buffer_multi.hpp>
|
#include <delay/buffer_multi.hpp>
|
||||||
#include <delay/buffer.hpp>
|
#include <delay/buffer.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -21,15 +22,38 @@ void print(const dsp::Buffer<T> &v, size_t size, std::string name=std::string(""
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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;
|
std::cout << "Check failed" << std::endl;
|
||||||
print(target, target.capacity(), "Target");
|
print(target, target.capacity(), "Target");
|
||||||
print(actual, actual.capacity(), "Actual");
|
print(actual, actual.capacity(), "Actual");
|
||||||
}
|
}
|
||||||
assert(target == actual);
|
assert(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user