From 7a0fe78836d1eb806541c6debbd23c62950b08ef Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 9 May 2021 15:02:14 +0200 Subject: [PATCH] Add more tests, document tests --- tests/unittest_area/tst_unittest_area.cpp | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/unittest_area/tst_unittest_area.cpp b/tests/unittest_area/tst_unittest_area.cpp index 22fea34..d8dca7b 100644 --- a/tests/unittest_area/tst_unittest_area.cpp +++ b/tests/unittest_area/tst_unittest_area.cpp @@ -2,6 +2,8 @@ #include +Q_DECLARE_METATYPE(AreaData::Side); + namespace tests { namespace unittests { @@ -13,17 +15,50 @@ class Area : public QObject Q_OBJECT public: + /** + * @brief An AreaData pointer to test with. + */ AreaData* m_area; private slots: + /** + * @brief Initialises every tests with creating a new area with the title "Test Area", and the index of 0. + */ void init(); + + /** + * @brief Cleans up the area pointer. + */ void cleanup(); + /** + * @test Tests various scenarios of a client joining and leaving, and what it changes on the area. + */ void clientJoinLeave(); + /** + * @brief The data function for areaStatuses(). + */ void areaStatuses_data(); + + /** + * @test Tests various attempts at changing area statuses. + */ void areaStatuses(); + /** + * @brief The data function for changeHP(). + */ + void changeHP_data(); + + /** + * @test Tests changing Confidence bar values for the sides. + */ + void changeHP(); + + /** + * @test Tests changing character in the area. + */ void changeCharacter(); }; @@ -82,6 +117,35 @@ void Area::areaStatuses() QCOMPARE(l_success, isSuccessful); } +void Area::changeHP_data() +{ + QTest::addColumn("side"); + QTest::addColumn("setHP"); + QTest::addColumn("expectedHP"); + + QTest::newRow("Set = Expected (DEF)") << AreaData::Side::DEFENCE << 3 << 3; + QTest::newRow("Set = Expected (PRO)") << AreaData::Side::PROSECUTOR << 5 << 5; + QTest::newRow("Below Zero (DEF)") << AreaData::Side::DEFENCE << -5 << 0; + QTest::newRow("Below Zero (PRO)") << AreaData::Side::PROSECUTOR << -7 << 0; + QTest::newRow("Above Ten (DEF)") << AreaData::Side::DEFENCE << 12 << 10; + QTest::newRow("Above Ten (PRO)") << AreaData::Side::PROSECUTOR << 14 << 10; +} + +void Area::changeHP() +{ + QFETCH(AreaData::Side, side); + QFETCH(int, setHP); + QFETCH(int, expectedHP); + + m_area->changeHP(side, setHP); + + if (AreaData::Side::DEFENCE == side) { + QCOMPARE(expectedHP, m_area->defHP()); + } else { + QCOMPARE(expectedHP, m_area->proHP()); + } +} + void Area::changeCharacter() { {