Skip to content

Commit

Permalink
Merge pull request #6 from Isembart/Tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
Isembart authored Nov 21, 2023
2 parents 10907e3 + b1c5262 commit b482d3c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
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)
2 changes: 1 addition & 1 deletion src/vectorFunctions.cpp
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"

Expand Down
33 changes: 33 additions & 0 deletions tests/CMakeLists.txt
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}
)


27 changes: 27 additions & 0 deletions tests/gameObjectTest.cpp
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);
}

18 changes: 18 additions & 0 deletions tests/vectorFunctionsTest.cpp
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);
}

0 comments on commit b482d3c

Please sign in to comment.