def test_input_int_in_np_sum(): obj = np.array([30, 53, 31, 47, 32]) df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"]) expected_output = [193] actual_output = df.sum() assert actual_output == expected_output
def test_input_mixed_in_np_sum(): obj = np.array([30, 53.0, "31", True, 32]) df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"]) expected_output = [] actual_output = df.sum() assert actual_output == expected_output
def test_input_int_in_dict_of_lists_sum(): obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]} df = DataFrame(obj, colindex=["AGE", "ALBUMS"], rowindex=["A", "B", "C", "D", "E"]) expected_output = [193, 25] actual_output = df.sum() assert actual_output == expected_output
def test_sum_df(): data = { "value1": [1, 2, 3, 4, 5, 6], "value2": [2, 2, 2, 2, 2, 2], "value3": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6], "value4": ["a", "b", "c", "d", "e", "f"], } expected_output = np.array([21, 12, 23.1, None]) df = DataFrame(data) sum_output = df.sum() print(sum_output) print(expected_output) assert sum_output.all() == expected_output.all()
def test_input_mixed_in_dict_of_np_sum(): obj = { "age": np.array([30.1, 53.1, 31.1, 47.1, 32.1]), "albums": np.array([4, 10, 2, 5, 4]), "C": np.array(["a", "b", "c", "d", "e"]), "D": np.array([True, False, True, True, False]), } df = DataFrame( obj, colindex=["AGE", "ALBUMS", "C", "D"], rowindex=["A", "B", "C", "D", "E"], ) expected_output = [193.5, 25, 3] actual_output = df.sum() assert actual_output == expected_output
def test_input_mixed_in_list_of_lists_sum(): obj = [ [30.1, 53.1, 31.1, 47.1, 32.1], [4, 10, 2, 5, 4], ["a", "b", "c", "d", "e"], [True, False, True, True, False], ] df = DataFrame( obj, colindex=["AGE", "ALBUMS", "C", "D"], rowindex=["A", "B", "C", "D", "E"], ) expected_output = [193.5, 25, 3] actual_output = df.sum() assert actual_output == expected_output
def test_sum2(): dictionary = { "pet": np.array(["cat", "dog", "mouse"]), "age": np.array([1, 2, 3]), "weight": np.array([1.0, 2.0, 3.0]), "sick": np.array([True, True, False]), } df = DataFrame(dictionary) sum_collector = [] columns = [] for key in dictionary: if dictionary[key].dtype == "float64" or \ dictionary[key].dtype == "int32": columns.append(key) sum_collector.append(sum(dictionary[key])) expected_output = sum_collector output = df.sum() assert output == expected_output
def test_for_sum_method(data, expected_result): input_DF = DataFrame(data) result = input_DF.sum() assert expected_result == result
def test_sum(dictionary, expected): myDF = DataFrame(dictionary) assert myDF.sum() == expected