Files
@ ec2bd041e1de
Branch filter:
Location: tempo-plotter/tests/test.cpp - annotation
ec2bd041e1de
3.9 KiB
text/x-c++hdr
added clear method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed a85782edc8e8 c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed c1dbdeb915ed a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 8aa863ef2cc4 a85782edc8e8 a85782edc8e8 a85782edc8e8 a85782edc8e8 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 a85782edc8e8 ec2bd041e1de ec2bd041e1de ec2bd041e1de a85782edc8e8 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 8aa863ef2cc4 | /*
Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "datachunk.h"
#include "chunkedbuffer.h"
TEST_CASE("DataChunk created empty", "[memory]")
{
DataChunk c(0, 1000);
REQUIRE(c.size() == 0);
REQUIRE(c.capacity() == 1000);
REQUIRE(c.start() == 0);
REQUIRE(c.end() == 0);
REQUIRE_FALSE(c.isFull());
REQUIRE(c.left() == 1000);
}
TEST_CASE("adding data to DataChunk", "[memory]")
{
DataChunk c(0, 1000);
double samples[10] = {1,2,3,4,5,6,7,8,9,10};
c.addSamples(samples, 10);
REQUIRE(c.size() == 10);
REQUIRE(c.capacity() == 1000);
REQUIRE(c.start() == 0);
REQUIRE(c.end() == 10);
REQUIRE(c.left() == 990);
for (int i = 0; i < 10; i++)
{
REQUIRE(c.sample(i) == samples[i]);
}
REQUIRE(c.min() == 1);
REQUIRE(c.max() == 10);
REQUIRE(c.avg() == Approx(5.5));
REQUIRE(c.meanSquare() == Approx(38.5));
}
TEST_CASE("filling data chunk", "[memory]")
{
DataChunk c(0, 1000);
for (int i = 0; i < 1000; i++)
{
double sample = i + 1;
c.addSamples(&sample, 1);
}
REQUIRE(c.size() == 1000);
REQUIRE(c.capacity() == 1000);
REQUIRE(c.start() == 0);
REQUIRE(c.end() == 1000);
REQUIRE(c.left() == 0);
REQUIRE(c.min() == 1);
REQUIRE(c.max() == 1000);
REQUIRE(c.avg() == Approx(500.5));
REQUIRE(c.meanSquare() == Approx(333833.5));
}
TEST_CASE("ChunkedBuffer created empty", "[memory]")
{
ChunkedBuffer b;
REQUIRE(b.size() == 0);
REQUIRE(b.boundingRect() == QRectF(0,0,0,0));
}
TEST_CASE("ChunkedBuffer adding data and clearing", "[memory]")
{
ChunkedBuffer b;
// add some small data
const int N = 10;
double samples[N] = {1,2,3,4,5,6,7,8,9,10};
b.addSamples(samples, N);
REQUIRE(b.size() == N);
REQUIRE(b.boundingRect() == QRectF(0,10,N,9));
// add data to fill the chunk
double samples2[CHUNK_SIZE-N] = {0};
b.addSamples(samples2, CHUNK_SIZE-N);
REQUIRE(b.size() == CHUNK_SIZE);
REQUIRE(b.boundingRect() == QRectF(0,10,CHUNK_SIZE,10));
// add data for second chunk
b.addSamples(samples, N);
REQUIRE(b.size() == CHUNK_SIZE+N);
REQUIRE(b.boundingRect() == QRectF(0,10,CHUNK_SIZE+N,10));
// add more data to make it 4 chunks
double samples3[CHUNK_SIZE*3-N] = {0};
b.addSamples(samples3, CHUNK_SIZE*3-N);
REQUIRE(b.size() == CHUNK_SIZE*4);
REQUIRE(b.boundingRect() == QRectF(0,10,CHUNK_SIZE*4,10));
// clear
b.clear();
REQUIRE(b.size() == 0);
}
TEST_CASE("ChunkedBuffer accessing data", "[memory]")
{
ChunkedBuffer b;
// prepare data
double samples[CHUNK_SIZE*3];
samples[0] = 10;
samples[10] = 20;
samples[CHUNK_SIZE-1] = 30;
samples[CHUNK_SIZE] = 40;
samples[CHUNK_SIZE+1] = 50;
samples[CHUNK_SIZE*2-1] = 60;
samples[CHUNK_SIZE*3-1] = 70;
// test
b.addSamples(samples, CHUNK_SIZE*3);
REQUIRE(b.size() == CHUNK_SIZE*3);
REQUIRE(b.sample(0) == 10);
REQUIRE(b.sample(10) == 20);
REQUIRE(b.sample(CHUNK_SIZE-1) == 30);
REQUIRE(b.sample(CHUNK_SIZE) == 40);
REQUIRE(b.sample(CHUNK_SIZE+1) == 50);
REQUIRE(b.sample(CHUNK_SIZE*2-1) == 60);
REQUIRE(b.sample(CHUNK_SIZE*3-1) == 70);
}
|