added tests
parent
54fb923675
commit
4ec2eb4646
@ -0,0 +1,4 @@
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
# Export compile command -> better tool integration.
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
@ -1,21 +1,30 @@
|
||||
#ifndef GODOT_HUB_MAP_TIME_H
|
||||
#define GODOT_HUB_MAP_TIME_H
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace cb::time {
|
||||
using internal_clock = std::chrono::high_resolution_clock;
|
||||
using time_point = std::chrono::time_point<internal_clock>;
|
||||
using time_point_map = std::map<const std::string_view, time_point>;
|
||||
|
||||
static std::map<const std::string_view, time_point> _name_to_measurement;
|
||||
inline static time_point_map _name_to_measurement;
|
||||
inline static constexpr long long NO_MEASUREMENT = -1;
|
||||
|
||||
time_point chrono_now();
|
||||
|
||||
void start_measure(const std::string_view& id);
|
||||
|
||||
long long get_duration(const std::string_view &id);
|
||||
|
||||
void measure(const std::string_view& id);
|
||||
|
||||
bool has_measurement(const std::string_view &id);
|
||||
|
||||
const time_point_map& get_measurements();
|
||||
}
|
||||
|
||||
#endif //GODOT_HUB_MAP_TIME_H
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
set(TEST_PROJECT_NAME ${CMAKE_PROJECT_NAME}_test)
|
||||
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG v1.13.0
|
||||
)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
|
||||
add_executable(${TEST_PROJECT_NAME}
|
||||
test_tests.cpp
|
||||
)
|
||||
|
||||
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
||||
|
||||
target_include_directories(${TEST_PROJECT_NAME}
|
||||
SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/tests"
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
target_link_libraries(${TEST_PROJECT_NAME} gtest_main cblib)
|
||||
|
||||
|
||||
add_test(NAME Test.tests COMMAND ${TEST_PROJECT_NAME})
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
#include <cb.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST (Time, TestStart) {
|
||||
using namespace cb;
|
||||
|
||||
const auto mehligs = "mehligs";
|
||||
const auto mehl = "mehl";
|
||||
|
||||
time::start_measure(mehl);
|
||||
|
||||
EXPECT_TRUE(time::has_measurement(mehl));
|
||||
EXPECT_FALSE(time::has_measurement(mehligs));
|
||||
|
||||
const auto measured_time_mehl = time::get_duration(mehl);
|
||||
const auto measured_time_mehligs = time::get_duration(mehligs);
|
||||
|
||||
EXPECT_TRUE(time::has_measurement(mehl));
|
||||
EXPECT_FALSE(time::has_measurement(mehligs));
|
||||
|
||||
EXPECT_GT(measured_time_mehl, 0);
|
||||
EXPECT_EQ(measured_time_mehligs, time::NO_MEASUREMENT);
|
||||
}
|
||||
|
||||
TEST (Time, NoTimer) {
|
||||
using namespace cb;
|
||||
|
||||
const auto mehligs = "mehligs";
|
||||
const auto measured_time_mehligs = time::get_duration(mehligs);
|
||||
|
||||
EXPECT_FALSE(time::has_measurement(mehligs));
|
||||
EXPECT_EQ(measured_time_mehligs, time::NO_MEASUREMENT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue