diff options
author | Ninni Pipping <over999ships@gmail.com> | 2023-03-14 14:11:05 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 17:31:05 +0200 |
commit | b43f84780882358d451bece176de2c854f666f30 (patch) | |
tree | 081a216b96b3574a37956cb95cebe70d859baba3 /tests | |
parent | ac1b26c7c51e71e5d98a18fb4ad779de1b572a5f (diff) |
Fix `Array.slice()` rounding for `abs(step) != 1`
(cherry picked from commit 10f385fb792dc74ffb8be221fec88ba9ef7aaa25)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/variant/test_array.h | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h index 04d5bb5107..ccb02ed5fa 100644 --- a/tests/core/variant/test_array.h +++ b/tests/core/variant/test_array.h @@ -253,6 +253,7 @@ TEST_CASE("[Array] slice()") { array.push_back(2); array.push_back(3); array.push_back(4); + array.push_back(5); Array slice0 = array.slice(0, 0); CHECK(slice0.size() == 0); @@ -263,42 +264,52 @@ TEST_CASE("[Array] slice()") { CHECK(slice1[1] == Variant(2)); Array slice2 = array.slice(1, -1); - CHECK(slice2.size() == 3); + CHECK(slice2.size() == 4); CHECK(slice2[0] == Variant(1)); CHECK(slice2[1] == Variant(2)); CHECK(slice2[2] == Variant(3)); + CHECK(slice2[3] == Variant(4)); Array slice3 = array.slice(3); - CHECK(slice3.size() == 2); + CHECK(slice3.size() == 3); CHECK(slice3[0] == Variant(3)); CHECK(slice3[1] == Variant(4)); + CHECK(slice3[2] == Variant(5)); Array slice4 = array.slice(2, -2); - CHECK(slice4.size() == 1); + CHECK(slice4.size() == 2); CHECK(slice4[0] == Variant(2)); + CHECK(slice4[1] == Variant(3)); Array slice5 = array.slice(-2); CHECK(slice5.size() == 2); - CHECK(slice5[0] == Variant(3)); - CHECK(slice5[1] == Variant(4)); + CHECK(slice5[0] == Variant(4)); + CHECK(slice5[1] == Variant(5)); Array slice6 = array.slice(2, 42); - CHECK(slice6.size() == 3); + CHECK(slice6.size() == 4); CHECK(slice6[0] == Variant(2)); CHECK(slice6[1] == Variant(3)); CHECK(slice6[2] == Variant(4)); + CHECK(slice6[3] == Variant(5)); Array slice7 = array.slice(4, 0, -2); CHECK(slice7.size() == 2); CHECK(slice7[0] == Variant(4)); CHECK(slice7[1] == Variant(2)); - ERR_PRINT_OFF; - Array slice8 = array.slice(4, 1); - CHECK(slice8.size() == 0); + Array slice8 = array.slice(5, 0, -2); + CHECK(slice8.size() == 3); + CHECK(slice8[0] == Variant(5)); + CHECK(slice8[1] == Variant(3)); + CHECK(slice8[2] == Variant(1)); - Array slice9 = array.slice(3, -4); + ERR_PRINT_OFF; + Array slice9 = array.slice(4, 1); CHECK(slice9.size() == 0); + + Array slice10 = array.slice(3, -4); + CHECK(slice10.size() == 0); ERR_PRINT_ON; } |