From 9bac352e05eb0e176aa959d4d49124dbb226442a Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 5 Jul 2023 17:42:48 +0200 Subject: [PATCH] renamed some internal variables --- linear_regression.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/linear_regression.py b/linear_regression.py index 356af39..2ff3a81 100644 --- a/linear_regression.py +++ b/linear_regression.py @@ -63,12 +63,23 @@ def test_linear_regression(example_data): def test_regression_predict(example_data): - result = linear_regression(example_data, x="A", y="B") + regression = linear_regression(example_data, x="A", y="B") - prediction = result.predict(10) + prediction = regression.predict(10) assert pytest.approx(30.7) == prediction - assert pytest.approx(10) == result.predict(y=prediction) + assert pytest.approx(10) == regression.predict(y=prediction) with pytest.raises(TypeError, match="expects 1 argument"): - result.predict() + regression.predict() + + +def test_regression_to_dict(example_data): + regression = linear_regression(example_data, x="A", y="B") + + result = regression.to_dict() + + assert sorted(result.keys()) == ["coefficient", "intercept", "score"] + assert pytest.approx(2.96) == result["coefficient"] + assert pytest.approx(1.1) == result["intercept"] + assert pytest.approx(0.9996349) == result["score"]