From ec7c497925f3b0c9e96d15feea6308cff77c49fe Mon Sep 17 00:00:00 2001 From: John Janus Date: Wed, 21 Aug 2019 14:35:09 +0200 Subject: [PATCH] fix test setup and small correction --- .../splittermond-assistant-tests.pro | 9 +++++--- splittermond-assistant-tests/tst_test.cpp | 21 ++++++++++++++++--- splittermond-assistant/src/character.cpp | 4 ++-- splittermond-assistant/src/character.h | 6 ++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/splittermond-assistant-tests/splittermond-assistant-tests.pro b/splittermond-assistant-tests/splittermond-assistant-tests.pro index 6a8fde5..4a9965e 100644 --- a/splittermond-assistant-tests/splittermond-assistant-tests.pro +++ b/splittermond-assistant-tests/splittermond-assistant-tests.pro @@ -1,3 +1,5 @@ +include(../qmake-target-platform.pri) +include(../qmake-destination-path.pri) QT += testlib QT -= gui @@ -5,15 +7,16 @@ CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle TEMPLATE = app -include(../qmake-destination-path.pri) -include(../qmake-target-platform.pri) INCLUDEPATH += ../splittermond-assistant/src DEPENDPATH += ../splittermond-assistant/src -SOURCES += tst_test.cpp +SOURCES += tst_test.cpp \ + ../splittermond-assistant/src/character.cpp DESTDIR = $$PWD/../binaries/$$DESTINATION_PATH OBJECTS_DIR = $$PWD/build/$$DESTINATION_PATH/.obj MOC_DIR = $$PWD/build/$$DESTINATION_PATH/.moc RCC_DIR = $$PWD/build/$$DESTINATION_PATH/.qrc UI_DIR = $$PWD/build/$$DESTINATION_PATH/.ui +message(splittermond-assistant-test output dir: $${DESTDIR}) +message(splittermond-assistant-test project dir: $${PWD}) diff --git a/splittermond-assistant-tests/tst_test.cpp b/splittermond-assistant-tests/tst_test.cpp index 7a0132b..2ea0de2 100644 --- a/splittermond-assistant-tests/tst_test.cpp +++ b/splittermond-assistant-tests/tst_test.cpp @@ -15,7 +15,7 @@ public: private slots: void initTestCase(); void cleanupTestCase(); - void test_case1(); + void init_Character(); }; @@ -39,9 +39,24 @@ void Test::cleanupTestCase() } -void Test::test_case1() +void Test::init_Character() { - QVERIFY_EXCEPTION_THROWN (sm::data::Character c{12, 12}, std::invalid_argument); + QVERIFY_EXCEPTION_THROWN (sm::data::Character c ({12, 12}), std::invalid_argument); + sm::data::Character c ({9, 9, 9, 9, 9, 9, 9, 9, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 10}); + QVERIFY ( c.skill (sm::data::Skill::heal) == 8); + QVERIFY ( c.attribute (sm::data::Attribute::mind) == 9); + QVERIFY ( c.life() == 10); + QVERIFY_EXCEPTION_THROWN (sm::data::Character c ({9, 9, 9, 9, 9, 9, 9, 9, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 10, 11}), std::invalid_argument); } QTEST_APPLESS_MAIN (Test) diff --git a/splittermond-assistant/src/character.cpp b/splittermond-assistant/src/character.cpp index 6fbe87d..a3488d1 100644 --- a/splittermond-assistant/src/character.cpp +++ b/splittermond-assistant/src/character.cpp @@ -26,8 +26,8 @@ Character::Character (std::initializer_list list) : d{new Characte if (list.size() != 54) throw std::invalid_argument (std::string ("Not exactly 54 arguments!") ); unsigned int ctr = 0; for (auto val : list) { - if (ctr < 8) d->attributes.insert ({Attribute{ctr}, val}); - else if (ctr >= 8 && ctr < 53) d->skills.insert ({Skill{ctr - 8}, val}); + if (ctr < 8) d->attributes.insert ({static_cast (ctr), val}); + else if (ctr >= 8 && ctr < 53) d->skills.insert ({static_cast (ctr - 8), val}); else if (ctr == 53) d->life = val; else throw std::invalid_argument ("Found an argument that should not have been there!"); ctr++; diff --git a/splittermond-assistant/src/character.h b/splittermond-assistant/src/character.h index d2fb51d..f00dae1 100644 --- a/splittermond-assistant/src/character.h +++ b/splittermond-assistant/src/character.h @@ -74,6 +74,12 @@ enum Damage : unsigned int { used }; +enum TestKind : unsigned int { + safe, + normal, + risk +}; + static const std::unordered_map> skillAttributes{ {acrobatics, {agility, strength}}, {alchemy, {mystic, mind}}, -- 2.47.0