core/stacklist: add tests
This commit is contained in:
parent
6024c37492
commit
c2ed5bf559
4 changed files with 123 additions and 1 deletions
|
|
@ -7,3 +7,4 @@ endfunction()
|
|||
qs_test(transformwatcher transformwatcher.cpp)
|
||||
qs_test(ringbuffer ringbuf.cpp)
|
||||
qs_test(scriptmodel scriptmodel.cpp)
|
||||
qs_test(stacklist stacklist.cpp)
|
||||
|
|
|
|||
92
src/core/test/stacklist.cpp
Normal file
92
src/core/test/stacklist.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include "stacklist.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qtest.h>
|
||||
#include <qtestcase.h>
|
||||
|
||||
#include "../stacklist.hpp"
|
||||
|
||||
void TestStackList::push() {
|
||||
StackList<int, 2> list;
|
||||
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
|
||||
QCOMPARE_EQ(list.toList(), QList({1, 2}));
|
||||
QCOMPARE_EQ(list.length(), 2);
|
||||
}
|
||||
|
||||
void TestStackList::pushAndGrow() {
|
||||
StackList<int, 2> list;
|
||||
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
|
||||
QCOMPARE_EQ(list.toList(), QList({1, 2, 3, 4}));
|
||||
QCOMPARE_EQ(list.length(), 4);
|
||||
}
|
||||
|
||||
void TestStackList::copy() {
|
||||
StackList<int, 2> list;
|
||||
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
|
||||
QCOMPARE_EQ(list.toList(), QList({1, 2, 3, 4}));
|
||||
QCOMPARE_EQ(list.length(), 4);
|
||||
|
||||
auto list2 = list;
|
||||
|
||||
QCOMPARE_EQ(list2.toList(), QList({1, 2, 3, 4}));
|
||||
QCOMPARE_EQ(list2.length(), 4);
|
||||
QCOMPARE_EQ(list2, list);
|
||||
}
|
||||
|
||||
void TestStackList::viewVla() {
|
||||
StackList<int, 2> list;
|
||||
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
|
||||
QCOMPARE_EQ(list.toList(), QList({1, 2}));
|
||||
QCOMPARE_EQ(list.length(), 2);
|
||||
|
||||
STACKLIST_VLA_VIEW(int, list, listView);
|
||||
|
||||
QList<int> ql;
|
||||
|
||||
for (size_t i = 0; i != list.length(); ++i) {
|
||||
ql.push_back(listView[i]); // NOLINT
|
||||
}
|
||||
|
||||
QCOMPARE_EQ(ql, list.toList());
|
||||
}
|
||||
|
||||
void TestStackList::viewVlaGrown() {
|
||||
StackList<int, 2> list;
|
||||
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
list.push(4);
|
||||
|
||||
QCOMPARE_EQ(list.toList(), QList({1, 2, 3, 4}));
|
||||
QCOMPARE_EQ(list.length(), 4);
|
||||
|
||||
STACKLIST_VLA_VIEW(int, list, listView);
|
||||
|
||||
QList<int> ql;
|
||||
|
||||
for (size_t i = 0; i != list.length(); ++i) {
|
||||
ql.push_back(listView[i]); // NOLINT
|
||||
}
|
||||
|
||||
QCOMPARE_EQ(ql, list.toList());
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestStackList);
|
||||
15
src/core/test/stacklist.hpp
Normal file
15
src/core/test/stacklist.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class TestStackList: public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
private slots:
|
||||
static void push();
|
||||
static void pushAndGrow();
|
||||
static void copy();
|
||||
static void viewVla();
|
||||
static void viewVlaGrown();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue