Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoIover committed Jan 7, 2025
1 parent 18c48a7 commit 8d7b8fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions corelib/src/array.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ impl SpanIntoIterator<T> of crate::iter::IntoIterator<Span<T>> {
}
}

impl SnapshotSpanIntoIterator<T> of core::iter::IntoIterator<@Span<T>> {
type IntoIter = core::array::SpanIter<T>;
impl SnapshotSpanIntoIterator<T> of crate::iter::IntoIterator<@Span<T>> {
type IntoIter = crate::array::SpanIter<T>;
fn into_iter(self: @Span<T>) -> Self::IntoIter {
(*self).into_iter()
}
Expand Down
2 changes: 1 addition & 1 deletion corelib/src/iter/traits/collect.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl IteratorIntoIterator<T, +Iterator<T>> of IntoIterator<T> {
}
}

impl SnapshotIteratorSpanBased<C, T, +Into<@C, Span<T>>> of core::iter::IntoIterator<@C> {
impl SnapshotIteratorSpanBased<C, T, +Into<@C, Span<T>>> of IntoIterator<@C> {
type IntoIter = core::array::SpanIter<T>;
fn into_iter(self: @C) -> Self::IntoIter {
let span: Span<T> = self.into();
Expand Down
29 changes: 13 additions & 16 deletions corelib/src/test/array_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,19 @@ fn test_array_iterator() {

#[test]
fn test_snapshot_fixed_size_array_iterator() {
let fixed_arr = [10_usize, 11, 12, 13];
let mut iter = (@fixed_arr).into_iter();
let mut iter = (@[10_usize, 11, 12, 13]).into_iter();
assert_eq!(iter.next(), Option::Some(@10));
assert_eq!(iter.next(), Option::Some(@11));
assert_eq!(iter.next(), Option::Some(@12));
assert_eq!(iter.next(), Option::Some(@13));
assert!(iter.next().is_none());

assert_eq!(fixed_arr.span()[1], @11);
}

#[test]
fn test_empty_snapshot_fixed_size_array_iterator() {
let mut fixed_arr: [usize; 0] = [];
let mut iter = (@fixed_arr).into_iter();
let mut input: [usize; 0] = [];
let mut iter = (@input).into_iter();
assert!(iter.next().is_none());

assert_eq!(fixed_arr.span().len(), 0);
}


Expand All @@ -225,20 +220,22 @@ fn test_snapshot_array_into_iter() {
let mut arr = array![1, 2, 3, 4, 5];
let mut arr_iter = (@arr).into_iter();

let next = arr_iter.next();
assert!(next == Option::Some(@1));

assert!(arr[1] == @2);
let mut i = 1;
while let Option::Some(value) = arr_iter.next() {
assert_eq!(value, @i);
i += 1;
}
}

#[test]
fn test_snapshot_span_into_iter() {
let span = array![1, 2, 3, 4, 5].span();
let mut span_iter = (@span).into_iter();
let next = span_iter.next();
assert!(next == Option::Some(@1));

assert!(span[1] == @2);
let mut i = 1;
while let Option::Some(value) = span_iter.next() {
assert_eq!(value, @i);
i += 1;
}
}

#[test]
Expand Down

0 comments on commit 8d7b8fe

Please sign in to comment.