Skip to content
Merged
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
43 changes: 43 additions & 0 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ where
if self.is_empty() {
None
} else {
self.ensure_unique();
let mut index = self.raw_dim();
for ax in 0..index.ndim() {
index[ax] -= 1;
Expand Down Expand Up @@ -3081,6 +3082,7 @@ mod tests
{
use super::*;
use crate::arr3;
use defmac::defmac;

#[test]
fn test_flatten()
Expand All @@ -3107,4 +3109,45 @@ mod tests
let flattened = array.into_flat();
assert_eq!(flattened, arr1(&[1, 2, 3, 4, 5, 6, 7, 8]));
}

#[test]
fn test_first_last()
{
let first = 2;
let last = 3;

defmac!(assert_first mut array => {
assert_eq!(array.first().copied(), Some(first));
assert_eq!(array.first_mut().copied(), Some(first));
});
defmac!(assert_last mut array => {
assert_eq!(array.last().copied(), Some(last));
assert_eq!(array.last_mut().copied(), Some(last));
});

let base = Array::from_vec(vec![first, last]);
let a = base.clone();
assert_first!(a);

let a = base.clone();
assert_last!(a);

let a = CowArray::from(base.view());
assert_first!(a);
let a = CowArray::from(base.view());
assert_last!(a);

let a = CowArray::from(base.clone());
assert_first!(a);
let a = CowArray::from(base.clone());
assert_last!(a);

let a = ArcArray::from(base.clone());
let _a2 = a.clone();
assert_last!(a);

let a = ArcArray::from(base.clone());
let _a2 = a.clone();
assert_first!(a);
}
}