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
+
+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
#include <QtTest>
+#include <exception>
+#include "character.h"
// add necessary includes here
void Test::test_case1()
{
-
+ QVERIFY_EXCEPTION_THROWN (sm::data::Character c{12, 12}, std::invalid_argument);
}
-QTEST_APPLESS_MAIN(Test)
+QTEST_APPLESS_MAIN (Test)
#include "tst_test.moc"
#include <random>
#include <QSharedData>
#include <vector>
+#include <utility>
+#include <exception>
namespace sm::data
{
~CharacterData() {}
unsigned int life = 0;
- const std::vector<Damage> damage;
- const std::unordered_map<Skill, unsigned int> skills;
- const std::unordered_map<Attribute, unsigned int> attributes;
+ std::vector<Damage> damage;
+ std::unordered_map<Skill, unsigned int> skills;
+ std::unordered_map<Attribute, unsigned int> attributes;
};
-Character::Character () : d{new Character::CharacterData}
+Character::Character (std::initializer_list<unsigned int> list) : d{new Character::CharacterData}
{
+ 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});
+ else if (ctr == 53) d->life = val;
+ else throw std::invalid_argument ("Found an argument that should not have been there!");
+ ctr++;
+ }
+}
+
+Character::Character (QFile* file) : d{new Character::CharacterData}
+{
+
+}
+
+Character::Character (const Character& other) : d (other.d) {}
+Character::Character (Character&& other) : d (other.d) {}
+
+Character& Character::operator= (const Character& other)
+{
+ d = other.d;
+ return *this;
+}
+
+Character& Character::operator= (Character&& other)
+{
+ d.swap (other.d);
+ return *this;
}
Character::~Character()
#include <QObject>
#include <QSharedDataPointer>
+#include <QFile>
+#include <unordered_map>
namespace sm::data
{
-enum Skill {
+enum Skill : unsigned int {
acrobatics,
alchemy,
leadership,
windmagic
};
-enum Attribute {
+enum Attribute : unsigned int {
charisma,
agility,
intuition,
willpower
};
-enum Damage {
+enum Damage : unsigned int {
canalised,
exhausted,
used
class Character
{
public:
- explicit Character ();
+ explicit Character (std::initializer_list<unsigned int>);
+ explicit Character (QFile* file);
+ Character (const Character&); //Copy Constructor
+ Character (Character&&); //Move Constructor
+
+ Character& operator= (const Character&); //Copy Assignment
+ Character& operator= (Character&&); //Move Assignment
+
virtual ~Character();
unsigned int skill (Skill skill) const;
unsigned int attribute (Attribute attribute) const;