Changeset - 8aa863ef2cc4
[Not reviewed]
longmem
0 2 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-08-12 12:53:13
hy@ozderya.net
improved addsamples tests and added data access
2 files changed with 61 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/chunkedbuffer.cpp
Show inline comments
 
@@ -83,6 +83,13 @@ QRectF ChunkedBuffer::boundingRect() con
 
        ymin = std::min(ymin, c->min());
 
        ymax = std::max(ymax, c->max());
 
    }
 

	
 
    return QRectF(0, ymax, _size, (ymax-ymin));
 
}
 

	
 
double ChunkedBuffer::sample(size_t i) const
 
{
 
    int chunk_index = i / CHUNK_SIZE;
 
    int chunk_offset = i % CHUNK_SIZE;
 
    return chunks[chunk_index]->sample(chunk_offset);
 
}
tests/test.cpp
Show inline comments
 
@@ -84,16 +84,66 @@ TEST_CASE("ChunkedBuffer created empty",
 
    ChunkedBuffer b;
 

	
 
    REQUIRE(b.size() == 0);
 
    REQUIRE(b.boundingRect() == QRectF(0,0,0,0));
 
}
 

	
 
TEST_CASE("ChunkedBuffer adding data", "[memory]")
 
TEST_CASE("ChunkedBuffer adding data and clearing", "[memory]")
 
{
 
    ChunkedBuffer b;
 

	
 
    // add some small data
 
    double samples[10] = {1,2,3,4,5,6,7,8,9,10};
 
    b.addSamples(samples, 10);
 
    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));
 

	
 
    REQUIRE(b.size() == 10);
 
    // TODO: 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);
 
}
0 comments (0 inline, 0 general)