Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Tests: Add test
  • Loading branch information
kmr-srbh committed Apr 9, 2024
commit 169350e6f77022aa20258d931476d50d2bf170ab
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython)
RUN(NAME intrinsics_01 LABELS cpython llvm NOFAST) # any
RUN(NAME intrinsics_02 LABELS cpython llvm c) # floordiv
RUN(NAME test_builtin_type LABELS cpython llvm c) # type
RUN(NAME test_builtin_reversed LABELS llvm) # reversed

# lpython decorator
RUN(NAME lpython_decorator_01 LABELS cpython)
Expand Down
40 changes: 40 additions & 0 deletions integration_tests/test_builtin_reversed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from lpython import i32, f64


def test_builtin_reversed():
# list of strings
alphabets: list[str] = ["a", "b", "c", "d", "e"]

reversed_alphabets: list[str] = reversed(alphabets)
print(reversed_alphabets)
assert reversed_alphabets == ["e", "d", "c", "b", "a"]

# list of numbers
numbers: list[i32] = [1, 2, 3, 4, 5]

reversed_numbers: list[i32] = reversed(numbers)
print(reversed_numbers)
assert reversed_numbers == [5, 4, 3, 2, 1]

# list returned through function call
alphabet_dictionary: dict[str, i32] = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
}
reversed_keys: list[str] = reversed(alphabet_dictionary.keys())
print(reversed_keys)

assert reversed_keys == ["e", "d", "c", "b", "a"]

# list of another object
points: list[tuple[f64, f64]] = [(1.0, 0.0), (2.3, 5.9), (78.1, 23.2)]
reversed_points: list[tuple[f64, f64]] = reversed(points)
print(reversed_points)

assert reversed_points == [(78.1, 23.2), (2.3, 5.9), (1.0, 0.0)]


test_builtin_reversed()