Skip to content

Commit 8123f0f

Browse files
rd4commodularbot
authored andcommitted
[External] [stdlib] Add test for InlineArray (sizeof[T] by capacity). (#57404)
[External] [stdlib] Add test for `InlineArray` (`sizeof[T]` by `capacity`). Add a small test for `InlineArray`: ```mojo (sizeof[ElementType]() * capacity) == sizeof[self._array]() ``` Co-authored-by: rd4com <144297616+rd4com@users.noreply.github.com> Closes #4125 MODULAR_ORIG_COMMIT_REV_ID: 8e241e5662e8534e8a02fa430126082018e23b81
1 parent 29c929c commit 8123f0f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mojo/stdlib/test/collections/test_inline_array.mojo

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from memory import UnsafePointer
1818
from memory.maybe_uninitialized import UnsafeMaybeUninitialized
1919
from test_utils import DelRecorder
2020
from testing import assert_equal, assert_false, assert_true
21+
from sys.info import sizeof
2122

2223

2324
def test_array_unsafe_get():
@@ -225,6 +226,20 @@ fn test_unsafe_ptr() raises:
225226
assert_equal(arr[i], ptr[i])
226227

227228

229+
def test_sizeof_array[current_type: CollectionElement, capacity: Int]():
230+
"""Testing if `sizeof` the array equals capacity * `sizeof` current_type.
231+
232+
Parameters:
233+
current_type: The type of the elements of the `InlineList`.
234+
capacity: The capacity of the `InlineList`.
235+
"""
236+
alias size_of_current_type = sizeof[current_type]()
237+
assert_equal(
238+
sizeof[InlineArray[current_type, capacity]](),
239+
capacity * size_of_current_type,
240+
)
241+
242+
228243
def main():
229244
test_array_unsafe_get()
230245
test_array_int()
@@ -234,3 +249,4 @@ def main():
234249
test_array_contains()
235250
test_inline_array_runs_destructors()
236251
test_unsafe_ptr()
252+
test_sizeof_array[Int, capacity=32]()

0 commit comments

Comments
 (0)