Merge remote-tracking branch 'origin/master' into sw7_lap_detection

This commit is contained in:
schaermicha1 committed 2026-04-11 23:10:28 +02:00
commit f03c720435
13 files changed
+314 -2

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import pytest
from src.exercises.pricing import discount_price
def test_discount_price_happy_path():
result = discount_price(100.0, 20.0)
assert result == 80.0
def test_discount_price_edge_case_1():
result = discount_price(100.0, 100.0)
assert result == 0.0
def test_discount_price_edge_case_2():
result = discount_price(100.0, 0.0)
assert result == 100.0
def test_discount_price_negative_price():
with pytest.raises(ValueError, match="price cannot be negative"):
discount_price(-1.0, 20.0)
def test_discount_price_invalid_discount():
with pytest.raises(ValueError, match="discount must be between 0 and 100"):
discount_price(100.0, 120.0)
+1 -1
View File
@@ -1,4 +1,4 @@
from src.moduleA import addition
from src.exercises.moduleA import addition
def test_a():
+25
View File
@@ -0,0 +1,25 @@
import pytest
from testing.catching_exeptions import double_integers
@pytest.mark.parametrize(
"data, expected_error",
[
(123, "data must be a list"),
([1, "2", 3, 4, 5], "data may contain only integers"),
],
)
def test_double_integers_unhappy_path(data, expected_error) -> None:
with pytest.raises(TypeError, match=expected_error):
double_integers(data)
@pytest.mark.parametrize(
"data, expected_result",
[
([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]),
([0, -1, -2, -3, -4, -5], [0, -2, -4, -6, -8, -10]),
],
)
def test_double_integers_happy_path(data, expected_result) -> None:
assert double_integers(data) == expected_result
+18
View File
@@ -0,0 +1,18 @@
import pytest
from testing.kata_list_filtering import filter_list
@pytest.mark.parametrize(
"input_list,expected_result",
[
([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]),
([], []),
([1 / 2, 1, "2", 3, "4", 5], [1, 3, 5]),
(["1", "2", "3", "4", "5"], []),
([True, False], []),
(1, []),
("asd123", []),
],
)
def test_filter_list(input_list, expected_result) -> None:
assert filter_list(input_list) == expected_result
+115
View File
@@ -0,0 +1,115 @@
import pytest
import pandas as pd
from testing.pandas_filter_rows import filter_dataframe
# --- Fixtures ---
@pytest.fixture
def sample_df():
return pd.DataFrame(
{
"age": [10, 25, 35, 45],
"name": ["Alice", "Bob", "Charlie", "Diana"],
"score": [88.5, 92.0, 70.0, 55.5],
}
)
# --- Happy path tests ---
def test_filter_numeric_column(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x > 20)
assert list(result["age"]) == [25, 35, 45]
def test_filter_returns_dataframe(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x > 0)
assert isinstance(result, pd.DataFrame)
def test_filter_string_column(sample_df):
result = filter_dataframe(sample_df, "name", lambda x: x.startswith("A"))
assert list(result["name"]) == ["Alice"]
def test_filter_float_column(sample_df):
result = filter_dataframe(sample_df, "score", lambda x: x >= 88.5)
assert list(result["score"]) == [88.5, 92.0]
def test_filter_preserves_all_columns(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x == 25)
assert list(result.columns) == ["age", "name", "score"]
assert result.iloc[0]["name"] == "Bob"
def test_filter_preserves_original_index(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x > 30)
assert list(result.index) == [2, 3]
def test_filter_does_not_mutate_original(sample_df):
original_len = len(sample_df)
filter_dataframe(sample_df, "age", lambda x: x > 20)
assert len(sample_df) == original_len
# --- Edge cases ---
def test_filter_all_rows_pass(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x > 0)
assert len(result) == len(sample_df)
def test_filter_no_rows_pass(sample_df):
result = filter_dataframe(sample_df, "age", lambda x: x > 1000)
assert len(result) == 0
assert list(result.columns) == ["age", "name", "score"]
def test_filter_on_empty_dataframe():
empty_df = pd.DataFrame({"age": [], "name": []})
result = filter_dataframe(empty_df, "age", lambda x: x > 10)
assert len(result) == 0
def test_filter_with_none_values():
df = pd.DataFrame({"value": [1, None, 3, None]})
result = filter_dataframe(df, "value", lambda x: x is not None and x > 1)
assert list(result["value"]) == [3.0]
def test_filter_single_row_match():
df = pd.DataFrame({"x": [42]})
result = filter_dataframe(df, "x", lambda x: x == 42)
assert len(result) == 1
def test_filter_single_row_no_match():
df = pd.DataFrame({"x": [42]})
result = filter_dataframe(df, "x", lambda x: x == 0)
assert len(result) == 0
# --- Error handling ---
def test_missing_column_raises_value_error(sample_df):
with pytest.raises(ValueError, match="Column 'missing' is not present"):
filter_dataframe(sample_df, "missing", lambda x: x > 0)
def test_missing_column_error_message_includes_column_name(sample_df):
with pytest.raises(ValueError, match="nonexistent"):
filter_dataframe(sample_df, "nonexistent", lambda x: True)
def test_func_exception_propagates(sample_df):
def bad_func(x):
raise RuntimeError("Intentional error")
with pytest.raises(RuntimeError, match="Intentional error"):
filter_dataframe(sample_df, "age", bad_func)