openMSX
CircularBuffer_test.cc
Go to the documentation of this file.
1 #include "catch.hpp"
2 #include "CircularBuffer.hh"
3 
4 using namespace openmsx;
5 
6 TEST_CASE("CircularBuffer")
7 {
9  CHECK(buf.isEmpty());
10  CHECK(!buf.isFull());
11  CHECK(buf.size() == 0);
12 
13  buf.addBack(15);
14  CHECK(!buf.isEmpty());
15  CHECK(!buf.isFull());
16  CHECK(buf.size() == 1);
17  CHECK(buf[0] == 15);
18 
19  buf[0] = 25;
20  CHECK(buf[0] == 25);
21 
22  buf.addFront(17);
23  CHECK(!buf.isEmpty());
24  CHECK(buf.isFull());
25  CHECK(buf.size() == 2);
26  CHECK(buf[0] == 17);
27  CHECK(buf[1] == 25);
28 
29  buf[1] = 35;
30  CHECK(buf[0] == 17);
31  CHECK(buf[1] == 35);
32  buf[0] = 27;
33  CHECK(buf[0] == 27);
34  CHECK(buf[1] == 35);
35 
36  int a = buf.removeBack();
37  CHECK(a == 35);
38  CHECK(buf.size() == 1);
39  CHECK(buf[0] == 27);
40 
41  int b = buf.removeFront();
42  CHECK(b == 27);
43  CHECK(buf.isEmpty());
44 }
openmsx::CircularBuffer::addFront
void addFront(const T &element)
Definition: CircularBuffer.hh:14
openmsx::CircularBuffer
Definition: CircularBuffer.hh:9
openmsx::CircularBuffer::addBack
void addBack(const T &element)
Definition: CircularBuffer.hh:19
CHECK
CHECK(m3==m3)
openmsx::CircularBuffer::removeBack
T & removeBack()
Definition: CircularBuffer.hh:30
openmsx::CircularBuffer::removeFront
T & removeFront()
Definition: CircularBuffer.hh:24
openmsx::CircularBuffer::size
size_t size() const
Definition: CircularBuffer.hh:52
openmsx::CircularBuffer::isFull
bool isFull() const
Definition: CircularBuffer.hh:49
CircularBuffer.hh
openmsx::CircularBuffer::isEmpty
bool isEmpty() const
Definition: CircularBuffer.hh:46
TEST_CASE
TEST_CASE("CircularBuffer")
Definition: CircularBuffer_test.cc:6
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5