-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 establishing the GoogleTest framework
- Loading branch information
1 parent
b0d7317
commit ebb3847
Showing
3 changed files
with
59 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
# see https://cmake.org/cmake/help/latest/module/FindBoost.html | ||
set(Boost_USE_STATIC_LIBS OFF) #enable dynamic linking | ||
# Assuming GoogleTest has already been made available in the main CMakeLists.txt | ||
|
||
# search for unit_test_framework | ||
find_package(Boost REQUIRED COMPONENTS unit_test_framework) | ||
# Create a test executable target from tests.cpp | ||
add_executable(SimpleCloth_test tests.cpp) | ||
|
||
include_directories(${Boost_INCLUDE_DIR}) | ||
# Link GoogleTest libraries to the new target | ||
target_link_libraries(SimpleCloth_test gtest_main) | ||
|
||
# create a cmake_testapp_boost target from tests.cpp | ||
add_executable(SimpleCloth_boost tests.cpp) | ||
# Optionally, if you have additional libraries your tests need to link against, include them here | ||
# target_link_libraries(SimpleCloth_test gtest_main your_additional_libraries) | ||
|
||
# link Boost libraries to the new target | ||
target_link_libraries(SimpleCloth_boost ${Boost_LIBRARIES}) | ||
|
||
# link Boost with code library | ||
target_link_libraries(SimpleCloth_boost) | ||
# Register the executable with CTest | ||
add_test(NAME SimpleCloth_test COMMAND SimpleCloth_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,36 @@ | ||
// | ||
// Created by saman on 10/29/20. | ||
// | ||
|
||
#define BOOST_TEST_MAIN | ||
#define BOOST_TEST_MODULE my_unit_tests | ||
#define BOOST_TEST_DYN_LINK | ||
#include <boost/test/unit_test.hpp> | ||
|
||
// Assuming you have GoogleTest included in your project setup | ||
|
||
#include <gtest/gtest.h> | ||
#include "../includes/Vec3.h" | ||
#include "../includes/ArrayT.h" | ||
|
||
// Define the test suite name with TEST() | ||
TEST(MyTestSuite, DotProduct) { | ||
Vec3 v1(1.0, 2.0, 0.0); | ||
Vec3 v2(-1.0, -3.0, 1.0); | ||
EXPECT_DOUBLE_EQ(v1.Dot(v2), -7.0); // Use EXPECT_DOUBLE_EQ for comparing floating-point numbers | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE(my_testsuite) | ||
TEST(MyTestSuite, AssignToScalar) { | ||
Vec3 v1(3, 5, 0); | ||
double val = 3; | ||
v1 = val; | ||
EXPECT_EQ(v1.x, 3); | ||
EXPECT_EQ(v1.y, 3); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(dot_product) | ||
{ | ||
Vec3 v1(1.0, 2.0, 0.0); | ||
Vec3 v2(-1.0, -3.0, 1.0); | ||
BOOST_TEST ( v1.Dot(v2) == -7.0); | ||
} | ||
TEST(MyTestSuite, MultiplyingByScalar) { | ||
Vec3 v1(5, 4, 0); | ||
double val = 3; | ||
v1 *= val; | ||
EXPECT_EQ(v1.x, 15); | ||
EXPECT_EQ(v1.y, 12); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(assign_to_scalar) | ||
{ | ||
Vec3 v1(3, 5, 0); | ||
double val = 3; | ||
v1 = val; | ||
BOOST_TEST (v1.x == 3); | ||
BOOST_TEST (v1.y == 3); | ||
} | ||
BOOST_AUTO_TEST_CASE(multiplying_by_scalar) | ||
{ | ||
Vec3 v1(5, 4, 0); | ||
double val = 3; | ||
v1 *= val; | ||
BOOST_TEST (v1.x == 15); | ||
BOOST_TEST (v1.y == 12); | ||
} | ||
BOOST_AUTO_TEST_CASE(multiplying_by_scalar_on_the_line) | ||
{ | ||
Vec3 v1(2.0, 3.0, 0.0); | ||
double val = 2.0; | ||
Vec3 v2 = v1 * val; | ||
BOOST_TEST (v2.x == 4.0); | ||
BOOST_TEST (v2.y == 6.0); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
TEST(MyTestSuite, MultiplyingByScalarOnTheLine) { | ||
Vec3 v1(2.0, 3.0, 0.0); | ||
double val = 2.0; | ||
Vec3 v2 = v1 * val; | ||
EXPECT_EQ(v2.x, 4.0); | ||
EXPECT_EQ(v2.y, 6.0); | ||
} |