Skip to content

Commit 7cc7141

Browse files
committed
reserve: Update tests to use into_raw_vec_and_offset
1 parent 25d2d04 commit 7cc7141

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/reserve.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
use ndarray::prelude::*;
22

3+
fn into_raw_vec_capacity<T, D: Dimension>(a: Array<T, D>) -> usize
4+
{
5+
a.into_raw_vec_and_offset().0.capacity()
6+
}
7+
38
#[test]
49
fn reserve_1d()
510
{
611
let mut a = Array1::<i32>::zeros((4,));
712
a.reserve(Axis(0), 1000).unwrap();
813
assert_eq!(a.shape(), &[4]);
9-
assert!(a.into_raw_vec().capacity() >= 1004);
14+
assert!(into_raw_vec_capacity(a) >= 1004);
1015
}
1116

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

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

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

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

5459
#[test]

0 commit comments

Comments
 (0)