Skip to content

Commit

Permalink
add plusAssign/minusAssign of EntityBag to MutableEntityBag
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Dec 11, 2024
1 parent 7be6413 commit 9150e5a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,20 @@ class MutableEntityBag(
}
}

/**
* Adds all [entities] to the bag. If the [capacity] is not sufficient then a resize is happening.
*/
operator fun plusAssign(entities: EntityBag) {
entities.forEach { plusAssign(it) }
}

/**
* Removes all [entities] of the bag.
*/
operator fun minusAssign(entities: EntityBag) {
entities.forEach { minusAssign(it) }
}

/**
* Resets [size] to zero and clears any [entity][Entity] of the bag.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,34 @@ class EntityBagTest {
bag = mutableEntityBagOf()
assertEquals(0, bag.size)
}

@Test
fun `test plusAssign of an EntityBag`() {
val bag = mutableEntityBagOf()
val toAdd = entityBagOf(testEntity1, testEntity2)

bag += toAdd

assertEquals(2, bag.size)
assertTrue { testEntity1 in bag }
assertTrue { testEntity2 in bag }
}

@Test
fun `test minusAssign of an EntityBag`() {
val bag = mutableEntityBagOf()
val toRemove = entityBagOf(testEntity1, testEntity2)

// remove of empty bag does nothing
bag -= toRemove
assertEquals(0, bag.size)

bag += testEntity2
bag += testEntity1
assertEquals(2, bag.size)
bag -= toRemove
assertEquals(0, bag.size)
assertFalse { testEntity1 in bag }
assertFalse { testEntity2 in bag }
}
}

0 comments on commit 9150e5a

Please sign in to comment.