Skip to content
Snippets Groups Projects
Commit 6f44d642 authored by Tomas Vybiral's avatar Tomas Vybiral
Browse files

added tests

parent 09e0e578
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ target_link_libraries(catch_main PUBLIC CONAN_PKG::catch2)
target_link_libraries(catch_main PRIVATE project_options)
 
add_executable(tests tests.cpp)
target_link_libraries(tests PRIVATE project_warnings project_options catch_main)
target_link_libraries(tests PRIVATE project_warnings project_options catch_main state game)
 
# automatically discover tests that are defined in catch based test files you can modify the unittests. TEST_PREFIX to
# whatever you want, or use different for different binaries
......
#include <catch2/catch.hpp>
#include <string>
 
unsigned int Factorial(unsigned int number)
#include "state/state.h"
#include "state/shooter.h"
#include "game/game.h"
#include "state/level.h"
TEST_CASE("Testing state history storing", "[state]")
{
return number <= 1 ? number : Factorial(number - 1) * number;
state cs;
REQUIRE(cs.score == 0);
REQUIRE(cs.player.position.get() == 240);
cs.score = 100;
cs.push();
REQUIRE(cs.score == 100);
cs.player.position.set(120);
REQUIRE(cs.player.position.get() == 120);
cs.push();
cs.player.position.set(0);
REQUIRE(cs.player.position.get() == 0);
cs = state::pop();
REQUIRE(cs.player.position.get() == 120);
REQUIRE(cs.score == 100);
cs = state::pop();
REQUIRE(cs.player.position.get() == 240);
REQUIRE(cs.score == 100);
try {
cs = state::pop();
REQUIRE(false);
} catch (const std::exception&) { }
}
 
TEST_CASE("Factorials are computed", "[factorial]")
{
REQUIRE(Factorial(1) == 1);
REQUIRE(Factorial(2) == 2);
REQUIRE(Factorial(3) == 6);
REQUIRE(Factorial(10) == 3628800);
TEST_CASE("Testing ranged_value structure", "[ranged_value]") {
ranged_value<int> val(5, 0, 10);
REQUIRE(val.get() == 5);
val.set(3);
REQUIRE(val.get() == 3);
val.set(-5);
REQUIRE(val.get() == 0);
val.set(15);
REQUIRE(val.get() == 10);
}
TEST_CASE("Testing game initialization", "[game]") {
try {
game g(30);
REQUIRE(true);
} catch (const std::exception& e) {
std::string exception_string = e.what();
REQUIRE(exception_string == "");
}
}
TEST_CASE("Testing level loading", "[level]") {
try {
level::create().from_file("levels/01.txt");
level l1 = level::get("start");
REQUIRE(true);
} catch (const std::exception& e) {
std::string exception_string = e.what();
REQUIRE(exception_string == "");
}
try {
level l2 = level::get("gkfhdfgkdfghj");
REQUIRE(false);
} catch (const std::exception&) {
REQUIRE(true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment