summaryrefslogtreecommitdiffstats
path: root/test/unit/math
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/math')
-rw-r--r--test/unit/math/func_test.cpp39
-rw-r--r--test/unit/math/geometry_test.cpp18
-rw-r--r--test/unit/math/matrix_test.cpp18
-rw-r--r--test/unit/math/vector_test.cpp18
4 files changed, 42 insertions, 51 deletions
diff --git a/test/unit/math/func_test.cpp b/test/unit/math/func_test.cpp
new file mode 100644
index 0000000..57f1347
--- /dev/null
+++ b/test/unit/math/func_test.cpp
@@ -0,0 +1,39 @@
+/*
+ Unit tests for math functions.
+ */
+
+#include "math/func.h"
+
+#include <gtest/gtest.h>
+
+
+TEST(IsPowerOfTwo, TestDifferentValues)
+{
+ EXPECT_FALSE(Math::IsPowerOfTwo(0));
+ EXPECT_TRUE(Math::IsPowerOfTwo(1));
+ EXPECT_TRUE(Math::IsPowerOfTwo(2));
+ EXPECT_FALSE(Math::IsPowerOfTwo(3));
+ EXPECT_TRUE(Math::IsPowerOfTwo(4));
+
+ EXPECT_FALSE(Math::IsPowerOfTwo(31));
+ EXPECT_TRUE(Math::IsPowerOfTwo(32));
+ EXPECT_FALSE(Math::IsPowerOfTwo(33));
+
+ EXPECT_FALSE(Math::IsPowerOfTwo(1234));
+}
+
+TEST(NextPowerOfTwo, TestDifferentValues)
+{
+ EXPECT_EQ(2, Math::NextPowerOfTwo(2));
+ EXPECT_EQ(4, Math::NextPowerOfTwo(3));
+ EXPECT_EQ(4, Math::NextPowerOfTwo(4));
+ EXPECT_EQ(8, Math::NextPowerOfTwo(5));
+
+ EXPECT_EQ(8, Math::NextPowerOfTwo(7));
+ EXPECT_EQ(8, Math::NextPowerOfTwo(8));
+ EXPECT_EQ(16, Math::NextPowerOfTwo(9));
+
+ EXPECT_EQ(32, Math::NextPowerOfTwo(31));
+ EXPECT_EQ(32, Math::NextPowerOfTwo(32));
+ EXPECT_EQ(64, Math::NextPowerOfTwo(33));
+}
diff --git a/test/unit/math/geometry_test.cpp b/test/unit/math/geometry_test.cpp
index 7c3e26a..581ef89 100644
--- a/test/unit/math/geometry_test.cpp
+++ b/test/unit/math/geometry_test.cpp
@@ -1,25 +1,9 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
-// *
-// * 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/.
-
/* Unit tests for functions in geometry.h */
#include "math/func.h"
#include "math/geometry.h"
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
const float TEST_TOLERANCE = 1e-5;
diff --git a/test/unit/math/matrix_test.cpp b/test/unit/math/matrix_test.cpp
index 5f5c3af..7693a85 100644
--- a/test/unit/math/matrix_test.cpp
+++ b/test/unit/math/matrix_test.cpp
@@ -1,19 +1,3 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
-// *
-// * 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/.
-
/*
Unit tests for Matrix struct
@@ -24,7 +8,7 @@
#include "math/func.h"
#include "math/matrix.h"
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
const float TEST_TOLERANCE = 1e-6;
diff --git a/test/unit/math/vector_test.cpp b/test/unit/math/vector_test.cpp
index 41bac74..6fe30be 100644
--- a/test/unit/math/vector_test.cpp
+++ b/test/unit/math/vector_test.cpp
@@ -1,19 +1,3 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
-// *
-// * 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/.
-
/*
Unit tests for Vector struct
@@ -24,7 +8,7 @@
#include "math/func.h"
#include "math/vector.h"
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
const float TEST_TOLERANCE = 1e-6;