def test_random_fill_sparse_exception_1(): H = 12 L = 10 K = 1000 matrix = np.zeros((H, L)) with pytest.raises(ValueError): S1.random_fill_sparse(matrix, K)
def test_random_fill_sparse(): size_rows = 2 size_cols = 5 myTab = numpy.zeros([size_rows, size_cols], dtype=str) v = size_rows * size_cols vfill = algo.alea(v) result = numpy.sum(algo.random_fill_sparse(myTab, vfill) == 'X') assert result == vfill
def test_random_fill_sparse(): ## # Basic function able to test random_fill_sparse function input_array = np.chararray((10, 10)) input_array[:] = '' vfill = input_array.size alea = algo.random(vfill) result = algo.random_fill_sparse(input_array, alea)
def test_random_fill_sparse(): ## #@details Testing random fill #First basic test n=5; tab=numpy.chararray((n, n)); tab[:] = ''; v= tab.size; random = algo.alea(v); result = algo.random_fill_sparse(tab,random);
def test_shuffle(): #@details Testing shuffle #First basic test mylist = [1,2]; assert algo.shuffle(mylist)==[1,2] or [2,1]; #Test with a empty list mylist = []; with pytest.raises(ValueError, match='provided list is empty'): algo.shuffle(mylist)==[];
def test_shuffle(): ## # Basic function able to test shuffle function # Testing with an empty list test_list = [] with pytest.raises(ValueError): algo.shuffle(test_list) # Initialise test list test_list = [1, 2, 3] # Test all the possibilities with a shuffle assert algo.shuffle(test_list) == [1, 2, 3] or [2, 1, 3] or [2, 3, 1] or [ 1, 3, 2 ] or [3, 1, 2] or [3, 2, 1]
def test_reverse_table(): ## # Basic function able to test reverse_table function # Testing with an empty list test_list = [] with pytest.raises(ValueError): algo.reverse_table(test_list) # Initialise test list test_list = [1, 2, 3, 4, -7] test_reversed_list = [-7, 4, 3, 2, 1] # Testing with a basic list assert algo.reverse_table(test_list) == test_reversed_list
def test_roi_bbox(): ## #@details Testing roi bbox #First basic test myMat=numpy.zeros([10,10],dtype=int) myMat[2:4,5:9]=numpy.ones([2,4]) result=numpy.array([[5,2],[5,3],[8,2],[8,3]]) assert_array_equal(algo.roi_bbox(myMat),result) #testing with 0 value myMat=numpy.zeros([10,10],dtype=int) myMat[0:0,0:0]=numpy.ones([0,0]) with pytest.raises(ValueError, match='provided matrix is empty'): assert_array_equal(algo.roi_bbox(myMat),result)
def test_random_fill_sparse_Right(): count = 2 W = 5 H = 5 Xin = np.zeros((H,W),dtype=str) filled_mat = sa.random_fill_sparse(Xin,count) assert np.where(filled_mat == "X")[0].shape[0] == count
def test_random_fill_sparse_working(): """Function that test if random_fill_sparse return an array with 'X'""" charar = np.chararray((5, 5)) charar[:] = '0' arr = s1.random_fill_sparse(charar, 2) condition = arr == b'X' assert np.count_nonzero(condition) == 2
def test_roi_bbox_functionnal(): ##function testing the finding of a bounding box size_rows = 7 size_cols = 7 my_mat = numpy.zeros([size_rows, size_cols]) my_mat[1:5,2:4] = numpy.ones([4,2]) assert numpy.alltrue(algotools.roi_bbox(my_mat) == [[1, 2],[1, 3], [4, 2], [4, 3]])
def test_random_fill_sparse_functionnal(): ##function testing random filling of a numpy array #it's testing if the result_array is not empty size = 5 my_rand_mat = numpy.zeros([size, size], dtype=str) vfill = 10 assert numpy.any(algotools.random_fill_sparse(my_rand_mat, vfill) != [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']])
def test_maxValue_returnMax(): ## #Function to test the return of the maaximum value of a list tab_list = [1, 2, 4, 6, -9] test, i = S1tested.max_value(tab_list) assert test == 6 assert i == 3
def test_reverse_table_with_event_length(): """ Function that tests the function reverse_table with a list of event length """ list = [1,2,3,4,5,6] assert list[::-1] == algo.reverse_table(list)
def test_roi_bbox_normal_values(): ## # test roi bbox with normal values my_matrix = numpy.zeros([10, 10], bool) my_matrix[3:4, 6:9] = numpy.ones([1, 3]) my_matrix[2:4, 6:8] = numpy.ones([2, 2]) assert s1.roi_bbox(my_matrix).all() == numpy.array([[2, 6], [2, 8], [3, 6], [3, 8]]).all()
def test_reverse_table_with_empty_list(): """ Function that tests the function reverse_table with an empty list """ list = [] assert algo.reverse_table(list) == []
def test_min_value_with_positive_values(): """ Function that tests the function min_value with a list of positive values """ list = [1,2,3,4,7] assert algo.min_value(list) == (1,0)
def test_max_value_with_negative_and_positive_values(): """ Function that tests the function max_value with a list of both negative and positive values """ list = [1,-2,-3,-4,-7] assert algo.max_value(list) == (1,0)
def test_average_above_zero_with_positive_values(): """ Function that tests the function average_above_zero with positive values """ list = [1,2,3,4] assert algo.average_above_zero(list) == 2.5
def test_average_above_zero_with_negative_values(): """ Function that tests the function average_above_zero with negative values """ list = [-1,-2,-3,-4,-7] assert algo.average_above_zero(list) == 0
def test_roi_bbox_1(): size_rows = 10 size_cols = 10 mtx = numpy.zeros([size_rows, size_cols]) mtx[4:7, 7:9] = numpy.ones([3, 2]) mtx[2:4, 5:8] = numpy.ones([2, 3]) assert s.roi_bbox(mtx) == ((2, 6), (5, 8))
def test_random_fill_sparse_4(): table = ['0', '1', '2', '3', '4', '5', '6'] table = np.chararray((4, 4)) table[:] = '' k = 2 res = tobetested.random_fill_sparse(table, k) assert res.all == table.all
def test_random_fill_sparse_too_much_vfill(): ## # test random fill sparse with normal value my_table = numpy.full([5, 5], '', dtype=str) fill = 50 with pytest.raises(ValueError): filled_table = s1.random_fill_sparse(my_table, fill)
def test_min_value_with_negative_values(): """ Function that tests the function min_value with a list of negative values """ list = [-1,-2,-3,-4,-7] assert algo.min_value(list) == (-7,4)
def test_reverse_table_with_odd_length(): """ Function that tests the function reverse_table with a list of odd length """ list = [1,2,3,4,-7] assert list[::-1] == algo.reverse_table(list)
def test_random_fill_sparse_not_square_matrix(): ## # test random fill sparse with no square matrix my_table = numpy.full([5, 8], '', dtype=str) fill = 5 with pytest.raises(ValueError): res = s1.random_fill_sparse(my_table, fill)
def test_roi_bbox(): matrix_bounding_box = np.array([[False, False, True, True, False, False, False, False, False, False], [False, False, True, True, False, False, False, False, False, False], [False, False, False, False, False, True, True, False, False, False], [False, False, False, False, False, True, True, False, False, False], [False, False, False, False, False, False, False, False, False, False]]) assert np.array_equal(algotools.roi_bbox(matrix_bounding_box), np.array([0, 2, 3, 6]))
def test_roi_bbox_2(): size_rows = 10 size_cols = 10 myMat = numpy.zeros([size_rows, size_cols], dtype=int) for row in range(5, 8): for col in range(7, 9): myMat[row, col] = 1 assert numpy.all(algo.roi_bbox(myMat) == [[5, 7], [5, 8], [7, 7], [7, 8]])
def test_remove_whitespace(): #@details Testing remove whitespace #First basic test whitespace = "I am a whitespace"; result = "Iamawhitespace" ; assert algo.remove_whitespace(whitespace)==result; #Test without space whitespace = "iamnotawhitespace"; result = "iamnotawhitespace" ; assert algo.remove_whitespace(whitespace)==result; #Test with just whitespace whitespace = ""; result = "" ; assert algo.remove_whitespace(whitespace)==result;
def test_sort_selective(): #@details Testing sort selective #First basic test vector = [10, 15, 7, 1,3, 3, 9]; rvector = [15,10,9,7,3,3,1]; assert algo.sort_selective(vector)==rvector; #Test with a empty list vector = []; rvector = []; assert algo.sort_selective(vector)==rvector; #Test with one value vector = [1]; rvector = [1]; assert algo.sort_selective(vector)==rvector;