-
Notifications
You must be signed in to change notification settings - Fork 170
Add list.pop
#1845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add list.pop
#1845
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f0a7607
Add list pop
kabra1110 8cc8d8f
Modify for expr
kabra1110 66aabc2
test files
kabra1110 766dcc6
Merge main
czgdp1807 0072610
Add verify_args in list.pop
czgdp1807 39344db
Add pop with argument
kabra1110 2571642
Merge branch 'main' into list_pop
kabra1110 f695a40
Merge main
czgdp1807 820dfc3
Fix bugs related to deepcopy of struct based data structures in list.pop
czgdp1807 d34aa84
Updated ref tests
czgdp1807 e00c1fa
add error check
kabra1110 5a036d7
Update integration_tests/CMakeLists.txt
czgdp1807 287a175
Merge branch 'main' into list_pop
czgdp1807 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from lpython import i32, f64 | ||
|
||
def test_list_pop(): | ||
l1: list[i32] | ||
l2: list[tuple[i32, f64]] | ||
l3: list[list[str]] | ||
i: i32 | ||
j: i32 | ||
total: i32 | ||
x: tuple[i32, f64] | ||
|
||
l1 = [1, 2, 3] | ||
assert l1.pop() == 3 | ||
assert l1 == [1, 2] | ||
|
||
l1 = [] | ||
total = 10 | ||
for i in range(total): | ||
l1.append(i) | ||
if i % 2 == 1: | ||
assert l1.pop() == i | ||
for i in range(total // 2): | ||
assert l1[i] == 2 * i | ||
|
||
l2 = [(1, 2.0)] | ||
x = l2.pop() | ||
assert x == (1, 2.0) | ||
assert len(l2) == 0 | ||
l2.append((2, 3.0)) | ||
assert x == (1, 2.0) | ||
|
||
l3 = [] | ||
for i in range(total): | ||
l3.insert(0, ["a"]) | ||
for j in range(len(l3)): | ||
l3[j] += ["a"] | ||
while len(l3) > 0: | ||
total = len(l3) | ||
assert len(l3.pop()) == total + 1 | ||
assert len(l3) == 0 | ||
|
||
l1 = [0, 1, 2, 3, 4] | ||
assert l1.pop(3) == 3 | ||
assert l1.pop(0) == 0 | ||
assert l1.pop(len(l1) - 1) == 4 | ||
assert l1 == [1, 2] | ||
|
||
total = 10 | ||
l1 = [] | ||
for i in range(total): | ||
l1.append(i) | ||
j = 0 | ||
for i in range(total): | ||
assert l1.pop(j - i) == i | ||
j += 1 | ||
assert len(l1) == 0 | ||
|
||
total = 10 | ||
l2 = [] | ||
for i in range(total): | ||
l2.append((i, f64(i * i))) | ||
j = 0 | ||
for i in range(total): | ||
assert l2.pop(j - i) == (i, f64(i * i)) | ||
j += 1 | ||
assert len(l2) == 0 | ||
|
||
test_list_pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from lpython import i32, f64, InOut | ||
|
||
def pop_wrapper(l: InOut[list[tuple[i32, f64]]], idx: i32) -> tuple[i32, f64]: | ||
return l.pop(idx) | ||
|
||
def test_list_pop(): | ||
l1: list[tuple[i32, f64]] | ||
x: tuple[i32, f64] | ||
i: i32 | ||
|
||
l1 = [(1, 1.0), (2, 4.0), (3, 6.0)] | ||
|
||
x = pop_wrapper(l1, 0) | ||
assert x == (1, 1.0) | ||
|
||
l1.append((4, 8.0)) | ||
assert x == (1, 1.0) | ||
|
||
for i in range(len(l1)): | ||
assert l1[i] == (i + 2, 2.0 * f64(i + 2)) | ||
|
||
test_list_pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.