Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
test_sparsearray.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
4
5using namespace rtp::ecs;
6
8 int value{0};
9};
10
11TEST(SparseArrayTest, EraseNonExistingIsNoop) {
13 Entity e1{1, 0};
14 EXPECT_NO_THROW(arr.erase(e1));
15 EXPECT_TRUE(arr.empty());
16 EXPECT_EQ(arr.size(), 0u);
17}
18
19TEST(SparseArrayTest, OverwriteKeepsSizeOne) {
21 Entity e{0, 0};
22 arr.emplace(e, DummyComponent{10});
23 arr.emplace(e, DummyComponent{20});
24 EXPECT_EQ(arr.size(), 1u);
25 EXPECT_EQ(arr[e].value, 20);
26}
27
28TEST(SparseArrayTest, EraseSwapBackMaintainsMapping) {
30 Entity e1{0, 0};
31 Entity e2{1, 0};
32 Entity e3{2, 0};
33
34 arr.emplace(e1, DummyComponent{1});
35 arr.emplace(e2, DummyComponent{2});
36 arr.emplace(e3, DummyComponent{3});
37
38 arr.erase(e2);
39
40 EXPECT_EQ(arr.size(), 2u);
41 EXPECT_FALSE(arr.has(e2));
42
43 ASSERT_TRUE(arr.has(e1));
44 ASSERT_TRUE(arr.has(e3));
45
46 EXPECT_EQ(arr[e1].value, 1);
47 EXPECT_EQ(arr[e3].value, 3);
48}
49
50TEST(SparseArrayTest, EntitiesAndDataSizesStayConsistent) {
52 Entity e1{0, 0};
53 Entity e2{1, 0};
54
55 arr.emplace(e1, DummyComponent{5});
56 arr.emplace(e2, DummyComponent{6});
57
58 EXPECT_EQ(arr.entities().size(), arr.kill().size());
59
60 arr.erase(e1);
61
62 EXPECT_EQ(arr.entities().size(), arr.kill().size());
63}
Entity identifier for ECS architecture.
Sparse array container for efficient component storage in ECS.
Represents an entity in the ECS (Entity-Component-System) architecture.
Definition Entity.hpp:63
Sparse array container for component storage.
bool has(Entity entity) const noexcept override final
Check if an entity has this component.
std::span< Entity > entities() noexcept
Get the entity array corresponding to components.
T & emplace(Entity entity, Args &&...args)
Construct a component in-place for an entity.
void erase(Entity entity) noexcept override final
Remove a component from an entity.
std::size_t size(void) const noexcept
Get the number of components stored.
bool empty(void) const noexcept
Check if the array is empty.
File : RenderSystem.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
TEST(SparseArrayTest, EraseNonExistingIsNoop)