Added test for valid_index for different cases