use ndarray::Array1;
use tensorism::Reindexing1;
use tensorism::Reindexing2;
use tensorism::new_ndarray;

#[test]
fn indexing_alias_generation() {
    let tensor1 = Array1::<i32>::from_shape_fn((7,), |i| (i as i32) * 3 - 7);
    // let sort = Reindexing1::new(5, 7, |i| i * i + 3);
    // let sort = reindexing!(for i :< 5 => i * i + 3 :< 7);
    let indexer = Reindexing1::new(5, 7, |i| i * i + 3);

    let expected = Array1::<i32>::from_vec(vec![2, 5, -7, 8, 8]);

    let result: Array1<i32> = new_ndarray!(for i let j = indexer[i] => tensor1[j]);
    assert_eq!(result, expected);

    let result: Array1<i32> = new_ndarray!(for i => tensor1[indexer[i]]);
    assert_eq!(result, expected);

    // let shuffle = Reindexing1::new(3, 4, 12, |i, j| i * 5 + j * 7 + 1);
    // let shuffle = reindexing!(for i :< 3 for j :< 4 => i * 5 + j * 7 + 1 :< 12);
    let shuffle = Reindexing2::new(3, 4, 12, |i, j| i * 4 + j * 3 + 7);
    let expected = [7, 10, 1, 4, 11, 2, 5, 8, 3, 6, 9, 0];
    assert_eq!(shuffle.as_ref(), expected);
}
