mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 13:53:37 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
57
base/base_tests/control_flow_tests.cpp
Normal file
57
base/base_tests/control_flow_tests.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "base/control_flow.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
using namespace base;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Repeater
|
||||
{
|
||||
explicit Repeater(uint32_t repetitions) : m_repetitions(repetitions) {}
|
||||
|
||||
template <typename Fn>
|
||||
void ForEach(Fn && fn)
|
||||
{
|
||||
ControlFlowWrapper<Fn> wrapper(std::forward<Fn>(fn));
|
||||
for (uint32_t i = 0; i < m_repetitions; ++i)
|
||||
{
|
||||
++m_calls;
|
||||
if (wrapper() == ControlFlow::Break)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t m_repetitions = 0;
|
||||
uint32_t m_calls = 0;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(ControlFlow_Smoke)
|
||||
{
|
||||
{
|
||||
Repeater repeater(10);
|
||||
uint32_t c = 0;
|
||||
repeater.ForEach([&c] { ++c; });
|
||||
|
||||
TEST_EQUAL(c, 10, ());
|
||||
TEST_EQUAL(c, repeater.m_repetitions, ());
|
||||
TEST_EQUAL(c, repeater.m_calls, ());
|
||||
}
|
||||
|
||||
{
|
||||
Repeater repeater(10);
|
||||
uint32_t c = 0;
|
||||
repeater.ForEach([&c] {
|
||||
++c;
|
||||
if (c == 5)
|
||||
return ControlFlow::Break;
|
||||
return ControlFlow::Continue;
|
||||
});
|
||||
|
||||
TEST_EQUAL(c, 5, ());
|
||||
TEST_EQUAL(c, repeater.m_calls, ());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user