Skip to content

Commit 53a7dc5

Browse files
committed
add more split_at tests
1 parent a188497 commit 53a7dc5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/array.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern crate ndarray;
77
use ndarray::{RcArray, S, Si,
88
OwnedArray,
99
};
10-
use ndarray::{arr0, arr1, arr2,
10+
use ndarray::{arr0, arr1, arr2, arr3,
1111
aview0,
1212
aview1,
1313
aview2,
@@ -683,4 +683,25 @@ fn split_at() {
683683
let (left, right) = b.view().axis_split_at(2, 2);
684684
assert_eq!(left.shape(), [3, 4, 2]);
685685
assert_eq!(right.shape(), [3, 4, 3]);
686+
assert_eq!(left, arr3(&[[[0., 1.], [5., 6.], [10., 11.], [15., 16.]],
687+
[[20., 21.], [25., 26.], [30., 31.], [35., 36.]],
688+
[[40., 41.], [45., 46.], [50., 51.], [55., 56.]]]));
689+
690+
// we allow for an empty right view when index == dim[axis]
691+
let (_, right) = b.view().axis_split_at(1, 4);
692+
assert_eq!(right.shape(), [3, 0, 5]);
693+
}
694+
695+
#[test]
696+
#[should_panic]
697+
fn deny_split_at_axis_out_of_bounds() {
698+
let a = arr2(&[[1., 2.], [3., 4.]]);
699+
a.view().axis_split_at(2, 0);
700+
}
701+
702+
#[test]
703+
#[should_panic]
704+
fn deny_split_at_index_out_of_bounds() {
705+
let a = arr2(&[[1., 2.], [3., 4.]]);
706+
a.view().axis_split_at(1, 3);
686707
}

0 commit comments

Comments
 (0)