Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WaughB committed Jan 7, 2024
1 parent ea59205 commit 308ec8b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
)
from speed_tests import measure_execution_time

CONST_SIZE = 10
CONST_MAX_LIST_LENGTH = 10
CONST_SIZE = 100
CONST_MAX_LIST_LENGTH = 100

if __name__ == "__main__":
# Initialize the logger. If no log file is specified, logs will just save to .
Expand Down
32 changes: 32 additions & 0 deletions test_convert_to_pandas_df.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
import pandas as pd
from dictionaries import convert_to_pandas_df # Replace with your actual module name


def test_normal_input():
sample_data = [(1, 2), (3, 4)]
expected_output = pd.DataFrame({"Key": [1, 3], "Value": [2, 4]})
pd.testing.assert_frame_equal(convert_to_pandas_df(sample_data), expected_output)


def test_empty_input():
sample_data = []
expected_output = pd.DataFrame(columns=["Key", "Value"])
pd.testing.assert_frame_equal(convert_to_pandas_df(sample_data), expected_output)


def test_multiple_entries():
sample_data = [("a", 1), ("a", 2), ("a", 3)]
expected_output = pd.DataFrame({"Key": ["a", "a", "a"], "Value": [1, 2, 3]})
pd.testing.assert_frame_equal(convert_to_pandas_df(sample_data), expected_output)


def test_invalid_input_data():
with pytest.raises(TypeError):
convert_to_pandas_df("invalid data")


def test_incorrect_tuple_length():
sample_data = [("a", 1, "extra"), ("b", 2)]
with pytest.raises(ValueError):
convert_to_pandas_df(sample_data)
35 changes: 35 additions & 0 deletions test_convert_to_polars_df.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
import polars as pl
from polars.testing import assert_frame_equal, assert_series_equal
from dictionaries import convert_to_polars_df


def test_normal_input():
sample_data = [(1, 2), (3, 4)]
expected_output = pl.DataFrame(
{"column_0": [1, 2], "column_1": [3, 4]}
) # Corrected expected values
pl.testing.assert_frame_equal(convert_to_polars_df(sample_data), expected_output)


def test_empty_input():
sample_data = []
expected_output = pl.DataFrame()
pl.testing.assert_frame_equal(convert_to_polars_df(sample_data), expected_output)


def test_multiple_entries():
sample_data = [("a", 1), ("a", 2), ("a", 3)]
expected_output = pl.DataFrame({"column_0": ["a", "a", "a"], "column_1": [1, 2, 3]})
pl.testing.assert_frame_equal(convert_to_polars_df(sample_data), expected_output)


def test_invalid_input_data():
with pytest.raises(TypeError):
convert_to_polars_df("invalid data")


def test_incorrect_tuple_length():
sample_data = [("a", 1, "extra"), ("b", 2)]
with pytest.raises(ValueError):
convert_to_polars_df(sample_data)

0 comments on commit 308ec8b

Please sign in to comment.