Skip to content

Commit

Permalink
reserve: Update tests to use into_raw_vec_and_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Apr 6, 2024
1 parent 25d2d04 commit 7cc7141
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/reserve.rs
@@ -1,12 +1,17 @@
use ndarray::prelude::*;

fn into_raw_vec_capacity<T, D: Dimension>(a: Array<T, D>) -> usize
{
a.into_raw_vec_and_offset().0.capacity()
}

#[test]
fn reserve_1d()
{
let mut a = Array1::<i32>::zeros((4,));
a.reserve(Axis(0), 1000).unwrap();
assert_eq!(a.shape(), &[4]);
assert!(a.into_raw_vec().capacity() >= 1004);
assert!(into_raw_vec_capacity(a) >= 1004);
}

#[test]
Expand All @@ -15,7 +20,7 @@ fn reserve_3d()
let mut a = Array3::<i32>::zeros((0, 4, 8));
a.reserve(Axis(0), 10).unwrap();
assert_eq!(a.shape(), &[0, 4, 8]);
assert!(a.into_raw_vec().capacity() >= 4 * 8 * 10);
assert!(into_raw_vec_capacity(a) >= 4 * 8 * 10);
}

#[test]
Expand All @@ -30,7 +35,7 @@ fn reserve_3d_axis1()
{
let mut a = Array3::<i32>::zeros((2, 4, 8));
a.reserve(Axis(1), 10).unwrap();
assert!(a.into_raw_vec().capacity() >= 2 * 8 * 10);
assert!(into_raw_vec_capacity(a) >= 2 * 8 * 10);
}

#[test]
Expand All @@ -39,7 +44,7 @@ fn reserve_3d_repeat()
let mut a = Array3::<i32>::zeros((2, 4, 8));
a.reserve(Axis(1), 10).unwrap();
a.reserve(Axis(2), 30).unwrap();
assert!(a.into_raw_vec().capacity() >= 2 * 4 * 30);
assert!(into_raw_vec_capacity(a) >= 2 * 4 * 30);
}

#[test]
Expand All @@ -48,7 +53,7 @@ fn reserve_2d_with_data()
let mut a = array![[1, 2], [3, 4], [5, 6]];
a.reserve(Axis(1), 100).unwrap();
assert_eq!(a, array![[1, 2], [3, 4], [5, 6]]);
assert!(a.into_raw_vec().capacity() >= 3 * 100);
assert!(into_raw_vec_capacity(a) >= 3 * 100);
}

#[test]
Expand Down

0 comments on commit 7cc7141

Please sign in to comment.