-
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.
Merge pull request #6 from Isembart/Tests
Tests
- Loading branch information
Showing
5 changed files
with
88 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(QuadTreeTest LANGUAGES CXX) | ||
project(BoidsSimulation LANGUAGES CXX) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) | ||
|
||
|
||
# SET(CMAKE_CXX_FLAGS "-pg -no-pie -O2") | ||
# SET(CMAKE_CXX_FLAGS "-O3") | ||
|
||
execute_process(COMMAND git submodule update --init --recursive) | ||
|
||
add_subdirectory(libs/SFML) | ||
add_subdirectory(libs/googletest) | ||
|
||
set(SOURCE src/main.cpp src/quadTree.cpp src/gameObject.cpp src/particle.cpp src/vectorFunctions.cpp) | ||
|
||
add_executable(QuadTreeTest ${SOURCE}) | ||
target_link_libraries(QuadTreeTest PRIVATE sfml-graphics) | ||
target_compile_features(QuadTreeTest PRIVATE cxx_std_17) | ||
add_executable(BoidsSimulation ${SOURCE}) | ||
target_link_libraries(BoidsSimulation PRIVATE sfml-graphics) | ||
target_compile_features(BoidsSimulation PRIVATE cxx_std_17) | ||
|
||
#my | ||
target_include_directories(QuadTreeTest PUBLIC include) | ||
target_include_directories(BoidsSimulation PUBLIC include) | ||
|
||
install(TARGETS QuadTreeTest) | ||
# add tests | ||
enable_testing() | ||
add_subdirectory(tests) |
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,4 +1,4 @@ | ||
#include "SFML/Graphics.hpp" | ||
#include <SFML/Graphics.hpp> | ||
#include "math.h" | ||
#include "vectorFunctions.hpp" | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Write a cmakelists to build tests | ||
cmake_minimum_required(VERSION 3.16) | ||
project(Tests) | ||
|
||
#because I don't want to create a library from my source files, I just add them to the test executable | ||
#This may change | ||
|
||
set(SOURCES | ||
../src/gameObject.cpp | ||
../src/particle.cpp | ||
../src/quadTree.cpp | ||
../src/vectorFunctions.cpp | ||
gameObjectTest.cpp | ||
vectorFunctionsTest.cpp | ||
) | ||
|
||
add_executable(${PROJECT_NAME} ${SOURCES}) | ||
|
||
#include the headers | ||
target_include_directories(${PROJECT_NAME} PUBLIC | ||
../include | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
sfml-graphics | ||
gtest_main | ||
) | ||
|
||
add_test(NAME BoidsTests | ||
COMMAND ${PROJECT_NAME} | ||
) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//test for gameObject.cpp | ||
#include <SFML/Graphics.hpp> | ||
#include <gtest/gtest.h> | ||
|
||
#include "typedefs.hpp" | ||
#include "gameObject.hpp" | ||
|
||
TEST(gameObjectTest, gettersAndSetters) { | ||
gameObject obj; | ||
obj.setPosition(sf::Vector2f(10,10)); | ||
EXPECT_EQ(obj.getPosition(), sf::Vector2f(10,10)); | ||
obj.setHitboxRadius(10); | ||
EXPECT_EQ(obj.getHitboxRadius(), 10); | ||
} | ||
|
||
TEST(gameObjectTest, collision) { | ||
gameObjectPtr obj1 = std::make_shared<gameObject>(); | ||
gameObjectPtr obj2 = std::make_shared<gameObject>(); | ||
obj1->setPosition(sf::Vector2f(10,10)); | ||
obj2->setPosition(sf::Vector2f(10,10)); | ||
obj1->setHitboxRadius(10); | ||
obj2->setHitboxRadius(10); | ||
EXPECT_EQ(obj1->intersects(obj2), true); | ||
obj2->setPosition(sf::Vector2f(100,100)); | ||
EXPECT_EQ(obj1->intersects(obj2), false); | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <gtest/gtest.h> | ||
#include "vectorFunctions.hpp" | ||
|
||
TEST(vectorFunctionsTest, magnitude) { | ||
sf::Vector2f vec(3,4); | ||
EXPECT_EQ(magnitude(vec), 5); | ||
} | ||
|
||
TEST(vectorFunctionsTest, normalize) { | ||
sf::Vector2f vec(3,4); | ||
EXPECT_EQ(normalize(vec), sf::Vector2f(0.6,0.8)); | ||
} | ||
|
||
TEST(vectorFunctionsTest, distance) { | ||
sf::Vector2f a(0,0); | ||
sf::Vector2f b(3,4); | ||
EXPECT_EQ(distance(a,b), 5); | ||
} |