-
-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: some things related to containers and add container test
- Loading branch information
Showing
9 changed files
with
125 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target_sources(canary_ut PRIVATE | ||
containers/container_test.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "pch.hpp" | ||
|
||
#include <boost/ut.hpp> | ||
|
||
#include "lib/logging/in_memory_logger.hpp" | ||
|
||
#include "items/containers/container.hpp" | ||
|
||
using namespace boost::ut; | ||
|
||
suite<"ContainerIteratorTest"> containerIteratorTest = [] { | ||
di::extension::injector<> injector{}; | ||
DI::setTestContainer(&InMemoryLogger::install(injector)); | ||
auto& logger = dynamic_cast<InMemoryLogger&>(injector.create<Logger&>()); | ||
|
||
auto createNestedContainers = [](size_t depth, size_t itemsPerContainer) -> std::shared_ptr<Container> { | ||
if (depth == 0) { | ||
return std::make_shared<Container>(ITEM_SHOPPING_BAG); | ||
} | ||
|
||
auto container = std::make_shared<Container>(ITEM_SHOPPING_BAG); | ||
for (size_t i = 0; i < itemsPerContainer; ++i) { | ||
auto item = Item::CreateItem(ITEM_GOLD_COIN, 1); | ||
container->addItem(item); | ||
} | ||
|
||
auto nestedContainer = createNestedContainers(depth - 1, itemsPerContainer); | ||
Check failure on line 27 in tests/unit/items/containers/container_test.cpp GitHub Actions / ubuntu-22.04-linux-release
|
||
container->addItem(nestedContainer); | ||
|
||
return container; | ||
}; | ||
|
||
test("ContainerIterator performance com contêineres profundamente aninhados") = [&]() { | ||
size_t depth = 100; | ||
size_t itemsPerContainer = 10; | ||
|
||
auto rootContainer = createNestedContainers(depth, itemsPerContainer); | ||
|
||
auto startTime = std::chrono::high_resolution_clock::now(); | ||
|
||
size_t itemCount = 0; | ||
ContainerIterator iterator = rootContainer->iterator(); | ||
while (iterator.hasNext()) { | ||
auto item = *iterator; | ||
++itemCount; | ||
|
||
iterator.advance(); | ||
} | ||
|
||
auto endTime = std::chrono::high_resolution_clock::now(); | ||
|
||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count(); | ||
|
||
logger.info("Percorridos {} itens em {} milissegundos.", itemCount, duration); | ||
|
||
size_t expectedItemCount = (itemsPerContainer + 1) * depth; | ||
|
||
expect(itemCount == expectedItemCount) << "Contagem de itens esperada: " << expectedItemCount << ", Obtida: " << itemCount; | ||
}; | ||
}; |