mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Add negative index to Array.remove_at and Array.insert
This commit is contained in:
@@ -126,6 +126,12 @@ TEST_CASE("[Array] resize(), insert(), and erase()") {
|
||||
CHECK(int(arr[0]) == 2);
|
||||
arr.erase(2);
|
||||
CHECK(int(arr[0]) == 1);
|
||||
|
||||
// Negative index on insert.
|
||||
CHECK(arr.size() == 3);
|
||||
arr.insert(-1, 3);
|
||||
CHECK(int(arr[2]) == 3);
|
||||
CHECK(arr.size() == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("[Array] front() and back()") {
|
||||
@@ -154,6 +160,15 @@ TEST_CASE("[Array] remove_at()") {
|
||||
arr.remove_at(0);
|
||||
CHECK(arr.size() == 0);
|
||||
|
||||
// Negative index.
|
||||
arr.push_back(3);
|
||||
arr.push_back(4);
|
||||
arr.remove_at(-1);
|
||||
CHECK(arr.size() == 1);
|
||||
CHECK(int(arr[0]) == 3);
|
||||
arr.remove_at(-1);
|
||||
CHECK(arr.size() == 0);
|
||||
|
||||
// The array is now empty; try to use `remove_at()` again.
|
||||
// Normally, this prints an error message so we silence it.
|
||||
ERR_PRINT_OFF;
|
||||
|
||||
Reference in New Issue
Block a user