Skip to content

Commit

Permalink
[stdlib] adds tests for negative index insert
Browse files Browse the repository at this point in the history
Signed-off-by: Dhaval Kumar <[email protected]>
  • Loading branch information
whym1here committed Apr 7, 2024
1 parent c5bb4bf commit 528c276
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions stdlib/test/collections/test_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,43 @@ def test_list_insert():

vec.clear()

#
# Test the list [1, 2, 3, 4, 5] created with negative and positive index
#

vec.insert(-1729, 2)
vec.insert(len(vec), 3)
vec.insert(len(vec), 5)
vec.insert(-1, 4)
vec.insert(-len(vec), 1)

assert_equal(len(vec), 5)
assert_equal(vec[0], 1)
assert_equal(vec[1], 2)
assert_equal(vec[2], 3)
assert_equal(vec[3], 4)
assert_equal(vec[4], 5)

vec.clear()


#
# Test the list [1, 2, 3, 4] created with negative index
#

vec.insert(-11, 4)
vec.insert(-13, 3)
vec.insert(-17, 2)
vec.insert(-19, 1)

assert_equal(len(vec), 4)
assert_equal(vec[0], 1)
assert_equal(vec[1], 2)
assert_equal(vec[2], 3)
assert_equal(vec[3], 4)

vec.clear()

#
# Test the list [1, 2, 3, 4, 5, 6, 7, 8] created with insert
#
Expand Down

0 comments on commit 528c276

Please sign in to comment.