Skip to content
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

[stdlib] Add test for InlineArray (sizeof[T] by capacity). #4125

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
16 changes: 16 additions & 0 deletions mojo/stdlib/test/collections/test_inline_array.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from memory import UnsafePointer
from memory.maybe_uninitialized import UnsafeMaybeUninitialized
from test_utils import DelRecorder
from testing import assert_equal, assert_false, assert_true
from sys.info import sizeof


def test_array_unsafe_get():
Expand Down Expand Up @@ -225,6 +226,20 @@ fn test_unsafe_ptr() raises:
assert_equal(arr[i], ptr[i])


def test_sizeof_array[current_type: CollectionElement, capacity: Int]():
"""Testing if `sizeof` the array equals capacity * `sizeof` current_type.

Parameters:
current_type: The type of the elements of the `InlineList`.
capacity: The capacity of the `InlineList`.
"""
alias size_of_current_type = sizeof[current_type]()
assert_equal(
sizeof[InlineArray[current_type, capacity]](),
capacity * size_of_current_type,
)


def main():
test_array_unsafe_get()
test_array_int()
Expand All @@ -234,3 +249,4 @@ def main():
test_array_contains()
test_inline_array_runs_destructors()
test_unsafe_ptr()
test_sizeof_array[Int, capacity=32]()