Skip to content

Commit

Permalink
Test uniqueness of all IDS instead of just one
Browse files Browse the repository at this point in the history
Co-Authorod-By: Lars Müller <appgurulars@gmx.de>
  • Loading branch information
JosiahWI committed May 14, 2024
1 parent b02ed55 commit 45860f7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/unittest/test_clientactiveobjectmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include <catch.hpp>

#include <unordered_set>
#include <utility>

class TestClientActiveObject : public ClientActiveObject
Expand Down Expand Up @@ -85,13 +86,20 @@ TEST_CASE("test client active object manager")
client::ActiveObjectMgr caomgr;
auto tcao1 = register_default_test_object(caomgr);

SECTION("When we register a client object, "
"then it should be assigned a unique ID.")
SECTION("When we register many client objects, "
"then all the assigned IDs should be unique.")
{
for (int i = 0; i < UINT8_MAX; ++i) {
// This should be enough rounds to be pretty confident
// there are no duplicates.
u16 n = 255;
std::unordered_set<u16> ids;
ids.insert(tcao1->getId());
for (u16 i = 0; i < n; ++i) {
auto other_tcao = register_default_test_object(caomgr);
CHECK(other_tcao->getId() != tcao1->getId());
ids.insert(other_tcao->getId());
}
// n added objects & tcao1
CHECK(n + 1 == static_cast<u16>(ids.size()));
}

SECTION("two registered objects")
Expand Down

0 comments on commit 45860f7

Please sign in to comment.