aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-09-09 06:18:53 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-09-09 06:21:36 +0100
commit660996bd750dbb5fcdce85845ee6b260f3ed23eb (patch)
treedc4f9931adf728379e571748eb954db1cf2eb65b /tests
parenta9893965737269512e9c75e87938312d707cb351 (diff)
downloadYAGE-660996bd750dbb5fcdce85845ee6b260f3ed23eb.tar.gz
YAGE-660996bd750dbb5fcdce85845ee6b260f3ed23eb.zip
Renaming test to tests
Diffstat (limited to 'tests')
-rw-r--r--tests/matrixtest.cpp80
-rw-r--r--tests/particlebodytest.cpp41
-rw-r--r--tests/windowtest.cpp21
-rw-r--r--tests/yagetest.cpp23
4 files changed, 165 insertions, 0 deletions
diff --git a/tests/matrixtest.cpp b/tests/matrixtest.cpp
new file mode 100644
index 00000000..b570f6d4
--- /dev/null
+++ b/tests/matrixtest.cpp
@@ -0,0 +1,80 @@
+/* ----------------------------------------------------------------------------
+ * matrixtest.cpp
+ *
+ * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
+ * See file LICENSE for more details
+ * ----------------------------------------------------------------------------
+ */
+
+#include <YAGE/Math/math.h>
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <cstdlib>
+#include <ctime>
+#include <vector>
+
+template <int Size>
+int matrixAddition(int num1, int num2)
+{
+ yage::Matrix<Size, Size, int> m1, m2;
+ m1[1][1] = num1;
+ m2[1][1] = num2;
+
+ yage::Matrix<Size, Size, int> m3 = m1 + m2;
+
+ return m3[1][1];
+}
+
+int vectorDotProduct(const std::vector<int> &vec_contents_f,
+ const std::vector<int> &vec_contents_s)
+{
+ yage::Vector<3, int> v1(vec_contents_f);
+ yage::Vector<3, int> v2(vec_contents_s);
+
+ int x = yage::matrix::dot(v1, v2);
+
+ return x;
+}
+
+bool matrixMultiplication()
+{
+ return false;
+}
+
+// TESTS
+
+TEST(Matrix, Assign)
+{
+ double rand_num = rand();
+ yage::Matrix<5, 5, double> mat1;
+ mat1[3][2] = rand_num;
+ ASSERT_EQ(rand_num, mat1[3][2]);
+ yage::Matrix<2, 2, double> mat2 {{rand_num, rand_num, rand_num, rand_num}};
+ ASSERT_EQ(rand_num, mat2[1][0]);
+}
+
+TEST(Matrix, Addition)
+{
+ int rand_x = rand();
+ int rand_y = rand();
+ ASSERT_EQ(rand_x + rand_y, matrixAddition<10>(rand_x, rand_y));
+}
+
+TEST(Vector, DotProduct)
+{
+ std::vector<int> contents_i = {rand() % 100, rand() % 100, rand() % 100};
+ std::vector<int> contents_j = {rand() % 100, rand() % 100, rand() % 100};
+ int sum = 0;
+ for (std::size_t i = 0; i < contents_i.size(); ++i) {
+ sum += contents_i[i] * contents_j[i];
+ }
+ ASSERT_EQ(sum, vectorDotProduct(contents_i, contents_j));
+}
+
+int main(int argc, char **argv)
+{
+ srand(static_cast<unsigned>(time(nullptr)));
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/particlebodytest.cpp b/tests/particlebodytest.cpp
new file mode 100644
index 00000000..b359cb73
--- /dev/null
+++ b/tests/particlebodytest.cpp
@@ -0,0 +1,41 @@
+/* ----------------------------------------------------------------------------
+ * rigidbodytest.cpp
+ *
+ * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
+ * See file LICENSE for more details
+ * ----------------------------------------------------------------------------
+ */
+
+#include <YAGE/Physics/particlebody.h>
+#include <gtest/gtest.h>
+
+#include <cmath>
+#include <cstdlib>
+
+double gravityAcceleration(int iterations)
+{
+ yage::ParticleBody body;
+ for (int i = 0; i < 60 * iterations; ++i) {
+ body.update();
+ }
+
+ return body.yPosition();
+}
+
+// Tests
+
+TEST(ParticleBody, Gravity)
+{
+ int randomItr = rand() % 10;
+ double idealPosition = 0.5 * -9.81 * std::pow(randomItr, 2);
+
+ ASSERT_GE(idealPosition * 0.95, gravityAcceleration(randomItr));
+ ASSERT_LE(idealPosition * 1.05, gravityAcceleration(randomItr));
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+ srand(static_cast<unsigned>(time(nullptr)));
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/windowtest.cpp b/tests/windowtest.cpp
new file mode 100644
index 00000000..e6739720
--- /dev/null
+++ b/tests/windowtest.cpp
@@ -0,0 +1,21 @@
+/* ----------------------------------------------------------------------------
+ * windowtest.cpp
+ *
+ * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
+ * MIT License, see LICENSE file for more details.
+ * ----------------------------------------------------------------------------
+ */
+
+#include <YAGE/yage.h>
+#include <gtest/gtest.h>
+
+TEST(Window, Open)
+{
+ ASSERT_TRUE(true);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/yagetest.cpp b/tests/yagetest.cpp
new file mode 100644
index 00000000..8d590b4a
--- /dev/null
+++ b/tests/yagetest.cpp
@@ -0,0 +1,23 @@
+/* ----------------------------------------------------------------------------
+ * yagetest.cpp
+ *
+ * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
+ * See file LICENSE for more details
+ * ----------------------------------------------------------------------------
+ */
+
+#include <gtest/gtest.h>
+
+#include <YAGE/yage.h>
+
+TEST(YAGE, InitQuit)
+{
+ ASSERT_TRUE(yage::init());
+ yage::quit();
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}