summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-12-29 15:59:54 -0500
committerBen Boeckel <MathStuf@gmail.com>2008-12-29 15:59:54 -0500
commit26e82996b0be76da6efb00eeb67f806fca60a17f (patch)
treefae364076908360cb2bddfee6a8770c7bea99016
parent0e2b7db5661c4c6c8faaf89eede509a18c52949a (diff)
Added test for SpeciesMove
-rw-r--r--sigmod/test/CMakeLists.txt2
-rw-r--r--sigmod/test/TestSpeciesMove.cpp206
-rw-r--r--sigmod/test/TestSpeciesMove.h53
3 files changed, 260 insertions, 1 deletions
diff --git a/sigmod/test/CMakeLists.txt b/sigmod/test/CMakeLists.txt
index ecf7f110..0034061e 100644
--- a/sigmod/test/CMakeLists.txt
+++ b/sigmod/test/CMakeLists.txt
@@ -51,7 +51,7 @@ MAKE_TEST(sigmod-tests libraries ItemType)
# MAKE_TEST(sigmod-tests libraries Species)
MAKE_TEST(sigmod-tests libraries SpeciesAbility)
MAKE_TEST(sigmod-tests libraries SpeciesItem)
-# MAKE_TEST(sigmod-tests libraries SpeciesMove)
+MAKE_TEST(sigmod-tests libraries SpeciesMove)
# MAKE_TEST(sigmod-tests libraries Sprite)
# MAKE_TEST(sigmod-tests libraries Status)
# MAKE_TEST(sigmod-tests libraries Store)
diff --git a/sigmod/test/TestSpeciesMove.cpp b/sigmod/test/TestSpeciesMove.cpp
new file mode 100644
index 00000000..660896c4
--- /dev/null
+++ b/sigmod/test/TestSpeciesMove.cpp
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Header include
+#include "TestSpeciesMove.h"
+
+// Sigmod includes
+#include "../Rules.h"
+#include "../Sigmod.h"
+#include "../Species.h"
+#include "../SpeciesMove.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtTest/QTest>
+
+void TestSpeciesMove::initTestCase()
+{
+ TestSigmodObject::initTestCase();
+
+ Sigmod::Species* species = m_sigmod->newSpecies();
+
+ m_speciesMove1 = species->newMove();
+ m_speciesMove2 = species->newMove();
+ m_speciesMove3 = species->newMove();
+}
+
+void TestSpeciesMove::cleanupTestCase()
+{
+ TestSigmodObject::cleanupTestCase();
+}
+
+void TestSpeciesMove::init()
+{
+ TestSigmodObject::init();
+
+ makeConnections(m_speciesMove1);
+ makeConnections(m_speciesMove2);
+ makeConnections(m_speciesMove3);
+}
+
+void TestSpeciesMove::cleanup()
+{
+ closeConnections(m_speciesMove1);
+ closeConnections(m_speciesMove2);
+ closeConnections(m_speciesMove3);
+
+ TestSigmodObject::cleanup();
+}
+
+void TestSpeciesMove::validation()
+{
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 3);
+
+ m_sigmod->newMove();
+
+ m_speciesMove1->setMove(0);
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 5);
+
+ m_sigmod->rules()->setMaxLevel(25);
+
+ m_speciesMove1->setLevel(15);
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 6);
+
+ m_sigmod->rules()->setMaxLevel(10);
+
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 8);
+
+ m_sigmod->rules()->setMaxLevel(50);
+
+ m_speciesMove1->setWild(40);
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 8);
+
+ m_sigmod->rules()->setMaxLevel(30);
+
+ m_speciesMove1->validate();
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 9);
+}
+
+void TestSpeciesMove::saving()
+{
+ QDomDocument xml = Sigmod::Object::xml(m_speciesMove1);
+ QFile file("speciesMove.xml");
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.write(xml.toByteArray());
+ file.close();
+}
+
+void TestSpeciesMove::loading()
+{
+ QDomDocument xml;
+ QFile file("speciesMove.xml");
+
+ m_sigmod->newMove();
+
+ m_speciesMove1->setMove(1);
+ m_speciesMove1->setLevel(5);
+ m_speciesMove1->setWild(5);
+
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(xml.setContent(&file));
+ m_speciesMove1->load(xml.firstChildElement("SpeciesMove"));
+
+ QCOMPARE(m_speciesMove1->move(), 0);
+ QCOMPARE(m_speciesMove1->level(), 15);
+ QCOMPARE(m_speciesMove1->wild(), 40);
+}
+
+void TestSpeciesMove::setMove()
+{
+ m_speciesMove2->setMove(2);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_sigmod->newMove();
+
+ m_speciesMove2->setMove(2);
+ m_speciesMove2->setMove(2);
+
+ QCOMPARE(m_speciesMove2->move(), 2);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestSpeciesMove::setLevel()
+{
+ m_speciesMove2->setLevel(50);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_speciesMove2->setLevel(15);
+ m_speciesMove2->setLevel(15);
+
+ QCOMPARE(m_speciesMove2->level(), 15);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestSpeciesMove::setWild()
+{
+ m_speciesMove2->setWild(50);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+
+ m_speciesMove2->setWild(15);
+ m_speciesMove2->setWild(15);
+
+ QCOMPARE(m_speciesMove2->wild(), 15);
+
+ QCOMPARE(m_changedCount, 1);
+
+ QCOMPARE(m_warnings.size(), 0);
+ QCOMPARE(m_errors.size(), 1);
+}
+
+void TestSpeciesMove::assignment()
+{
+ *m_speciesMove3 = *m_speciesMove2;
+
+ QCOMPARE(m_speciesMove3->move(), 2);
+ QCOMPARE(m_speciesMove3->level(), 15);
+ QCOMPARE(m_speciesMove3->wild(), 15);
+}
+
+QTEST_APPLESS_MAIN(TestSpeciesMove)
diff --git a/sigmod/test/TestSpeciesMove.h b/sigmod/test/TestSpeciesMove.h
new file mode 100644
index 00000000..9660f0dc
--- /dev/null
+++ b/sigmod/test/TestSpeciesMove.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SIGMOD_TESTSPECIESMOVE
+#define SIGMOD_TESTSPECIESMOVE
+
+// Test includes
+#include "TestSigmodObject.h"
+
+// Sigmod includes
+#include "../SpeciesMove.h"
+
+class TestSpeciesMove : public TestSigmodObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void validation();
+ void saving();
+ void loading();
+
+ void setMove();
+ void setLevel();
+ void setWild();
+
+ void assignment();
+ private:
+ Sigmod::SpeciesMove* m_speciesMove1;
+ Sigmod::SpeciesMove* m_speciesMove2;
+ Sigmod::SpeciesMove* m_speciesMove3;
+};
+
+#endif