]> Johnzone git - splittermond-assistant.git/commitdiff
trying to test
authorJohn Janus <mail@johnzone.org>
Tue, 13 Aug 2019 22:27:28 +0000 (00:27 +0200)
committerJohn Janus <mail@johnzone.org>
Tue, 13 Aug 2019 22:27:28 +0000 (00:27 +0200)
splittermond-assistant-tests/splittermond-assistant-tests.pro
splittermond-assistant-tests/tst_test.cpp
splittermond-assistant/src/character.cpp
splittermond-assistant/src/character.h

index d2d7b7f0be8045c1745fb719664b24bb20255ee1..6a8fde533d37b96d46fdf39de74e80c1555d80c9 100644 (file)
@@ -5,5 +5,15 @@ 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
+
+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
index 91bf4edd17835b5c428e34ba2f2b1f519cb488b1..7a0132b50b244235ef6e1a2dc28120c2da4c84a7 100644 (file)
@@ -1,4 +1,6 @@
 #include <QtTest>
+#include <exception>
+#include "character.h"
 
 // add necessary includes here
 
@@ -39,9 +41,9 @@ void Test::cleanupTestCase()
 
 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"
index 3e63414631ec2c7746f458ed8a3e4c6271d80801..6fbe87d8870a21b28db182f976e61d2af4b12075 100644 (file)
@@ -2,6 +2,8 @@
 #include <random>
 #include <QSharedData>
 #include <vector>
+#include <utility>
+#include <exception>
 
 namespace sm::data
 {
@@ -14,14 +16,43 @@ public:
 
   ~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()
index 2b013a680e55c66b3eef35c231a437f5f4220ab2..d2fb51d431ba31ab4c511bd349698d95b2700b07 100644 (file)
@@ -3,10 +3,12 @@
 
 #include <QObject>
 #include <QSharedDataPointer>
+#include <QFile>
+#include <unordered_map>
 
 namespace sm::data
 {
-enum Skill {
+enum Skill : unsigned int {
   acrobatics,
   alchemy,
   leadership,
@@ -55,7 +57,7 @@ enum Skill {
   windmagic
 };
 
-enum Attribute {
+enum Attribute : unsigned int {
   charisma,
   agility,
   intuition,
@@ -66,7 +68,7 @@ enum Attribute {
   willpower
 };
 
-enum Damage {
+enum Damage : unsigned int {
   canalised,
   exhausted,
   used
@@ -124,7 +126,14 @@ static const std::unordered_map<Skill, std::pair<Attribute, Attribute>> skillAtt
 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;