improved buffer tests

This commit is contained in:
2025-10-30 19:03:25 +01:00
parent 7f66f9e60d
commit 87598b5d65
5 changed files with 85 additions and 28 deletions
+1 -2
View File
@@ -19,7 +19,7 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* File: dsp_ringbuffer.hpp * File: buffer.hpp.hpp
* Author Jens Ahrensfeld on 26.10.2025. * Author Jens Ahrensfeld on 26.10.2025.
*/ */
@@ -31,7 +31,6 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <dsp_types.hpp> #include <dsp_types.hpp>
#include <iostream>
namespace dsp { namespace dsp {
+1 -1
View File
@@ -19,7 +19,7 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* File: dsp_ringbuffer.hpp * File: buffer_multi.hpp
* Author Jens Ahrensfeld on 26.10.2025. * Author Jens Ahrensfeld on 26.10.2025.
*/ */
+1 -1
View File
@@ -19,7 +19,7 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* File: dsp_ringbuffer.hpp * File: buffer_view.hpp
* Author Jens Ahrensfeld on 26.10.2025. * Author Jens Ahrensfeld on 26.10.2025.
*/ */
+9 -14
View File
@@ -19,16 +19,11 @@ void print(dsp::BufferView<T> &v, size_t size)
} }
static void info() int test_buffer_1()
{ {
std::cout << "----------------------------------------------" << std::endl; std::cout << "----------------------------------------------" << std::endl;
std::cout << "Start test_buffer()" << std::endl; std::cout << "Start test_buffer_1" << std::endl;
std::cout << "----------------------------------------------" << std::endl; std::cout << "----------------------------------------------" << std::endl;
}
int test_buffer()
{
info();
dsp::Buffer<int> buffer(10); dsp::Buffer<int> buffer(10);
printf("Buffer capacity = %zu\n", buffer.capacity()); printf("Buffer capacity = %zu\n", buffer.capacity());
@@ -45,13 +40,7 @@ int test_buffer()
} }
auto v1 = dsp::BufferView<int>(buffer, 0); auto v1 = dsp::BufferView<int>(buffer, 0);
auto v2 = dsp::BufferView<int>(buffer, 5); auto v2 = dsp::BufferView<int>(buffer, -5);
buffer.reset();
v1[5] = 55;
print(v1, 10);
v2[2] = 77;
print(v2,10);
for(const auto&i : buffer) for(const auto&i : buffer)
{ {
@@ -60,3 +49,9 @@ int test_buffer()
return 0; return 0;
} }
int test_buffer()
{
test_buffer_1();
return 0;
}
+72 -9
View File
@@ -3,17 +3,14 @@
#include <iostream> #include <iostream>
static void info()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "Start test_buffer_multi()" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
}
int test_buffer_multi() int test_buffer_multi_1()
{ {
info(); std::cout << "----------------------------------------------" << std::endl;
dsp::BufferMulti<int>buffer(5, 20); std::cout << "Start test_buffer_multi_1()" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
dsp::BufferMulti<int>buffer(5, 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 < 10; i++)
@@ -42,3 +39,69 @@ int test_buffer_multi()
return 0; return 0;
} }
int test_buffer_multi_2()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "Start test_buffer_multi_2()" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
dsp::BufferMulti<int>buffer(5, 3);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < 10; i++)
{
for (int c=0; c < 5; c++)
{
buffer.at(c, 0) = i+1;
int v = buffer.at(c, -2);
printf("c=%d: i=%d: v=%d\n", c, i, v);
}
buffer += 1;
}
#if 0
buffer.reset();
for (int i=0; i < 10; i++)
{
for (int c=0; c < 5; c++)
{
int v = buffer.at(c, i);
printf("c=%d: i=%d: v=%d\n", c, i, v);
}
}
#endif
return 0;
}
int test_buffer_multi_3()
{
std::cout << "----------------------------------------------" << std::endl;
std::cout << "Start test_buffer_multi_3()" << std::endl;
std::cout << "----------------------------------------------" << std::endl;
dsp::BufferMulti<int>buffer(5, 10);
printf("Buffer capacity = %zu\n", buffer.capacity());
for (int i=0; i < 20; i++)
{
for (int c=0; c < 5; c++)
{
buffer.at(c, 0) = i+1;
int v = buffer.at(c, -c);
printf("c=%d: i=%d: v=%d\n", c, i, v);
}
buffer += 1;
}
return 0;
}
int test_buffer_multi()
{
test_buffer_multi_1();
test_buffer_multi_2();
test_buffer_multi_3();
return 0;
}