improved buffer tests

This commit is contained in:
2025-11-05 09:23:35 +01:00
parent 3ee368f484
commit bc013ff352
+21 -25
View File
@@ -13,33 +13,37 @@ int test_buffer_1()
std::cout << "----------------------------------------------" << std::endl; std::cout << "----------------------------------------------" << std::endl;
dsp::Buffer<int> buffer(10); dsp::Buffer<int> buffer(10);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < buffer.capacity(); 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}; dsp::Buffer<int> t_buf{105, 106, 107, 108, 109};
check(buffer, t_buf, t_buf.capacity()); 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;
} }
dsp::Buffer<int> t_buf{100, 101, 102, 103, 104};
check(res_buf, t_buf); {
dsp::Buffer<int> t_buf{100, 101, 102, 103, 104};
check(res_buf, t_buf);
}
auto v1 = dsp::Buffer<int>(buffer, 0); buffer.reset();
auto v2 = dsp::Buffer<int>(buffer, -5); {
dsp::Buffer<int> t_buf{100, 101, 102, 103, 104, 105, 106, 107, 108, 109};
print(v1, v1.capacity(), "v1"); check(dsp::Buffer<int>(buffer, 0), t_buf);
print(v2, v2.capacity(), "v2"); }
{
dsp::Buffer<int> t_buf{0, 0, 0, 0, 0, 100, 101, 102, 103, 104};
check(dsp::Buffer<int>(buffer, -5), t_buf);
}
return 0; return 0;
} }
@@ -50,27 +54,20 @@ 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(5); dsp::Buffer<int> buffer(10);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < buffer.capacity(); i++) for (int i=0; i < buffer.capacity(); i++)
{ {
buffer[i] = i+100; buffer[i] = i+100;
} }
const auto v1 = dsp::Buffer<int>(buffer, -1);
const auto v2 = dsp::Buffer<int>(buffer, -5);
for(int i=0; i < buffer.capacity(); i++)
{ {
std::cout << buffer[i] << std::endl; dsp::Buffer<int> t_buf{0, 100, 101, 102, 103, 104, 105, 106, 107, 108};
check(dsp::Buffer<int>(buffer, -1), t_buf);
}
{
dsp::Buffer<int> t_buf{0, 0, 0, 0, 0, 100, 101, 102, 103, 104};
check(dsp::Buffer<int>(buffer, -5), t_buf);
} }
std::cout << "print(buffer, 10);" << std::endl;
print(buffer, 10);
std::cout << "print(v1, 10);" << std::endl;
print(v1, 10);
std::cout << "print(v2, 10);" << std::endl;
print(v2, 10);
return 0; return 0;
} }
@@ -82,7 +79,6 @@ int test_buffer_3()
std::cout << "----------------------------------------------" << std::endl; std::cout << "----------------------------------------------" << std::endl;
dsp::Buffer<int> buffer(50); dsp::Buffer<int> buffer(50);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < buffer.capacity(); i++) for (int i=0; i < buffer.capacity(); i++)
{ {
buffer[i] = i+100; buffer[i] = i+100;