From a7b0010c2759255b07f10414e572dfcdfcc4a78e Mon Sep 17 00:00:00 2001 From: SiyuZhou Date: Fri, 17 Feb 2023 10:50:12 -0500 Subject: [PATCH 1/2] Added in_class_exercise_Feb3 --- in_class_exercise_Test_Driven_Development.py | 9 +++++++++ test_in_class_exercise_Test_Driven_Development.py | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 in_class_exercise_Test_Driven_Development.py create mode 100644 test_in_class_exercise_Test_Driven_Development.py diff --git a/in_class_exercise_Test_Driven_Development.py b/in_class_exercise_Test_Driven_Development.py new file mode 100644 index 0000000..433c39e --- /dev/null +++ b/in_class_exercise_Test_Driven_Development.py @@ -0,0 +1,9 @@ +def calculate_y_value(x: list): + x1, y1, x2, y2, x3 = x.split(",") + if x1 == x2: + return None + else: + k = (y2-y1)/(x2-x1) + b = y1-k*x1 + y3 = k*x3 + b + return y3 diff --git a/test_in_class_exercise_Test_Driven_Development.py b/test_in_class_exercise_Test_Driven_Development.py new file mode 100644 index 0000000..a92cd28 --- /dev/null +++ b/test_in_class_exercise_Test_Driven_Development.py @@ -0,0 +1,11 @@ +import pytest + +@pytest.mark.parametrize("x_input, expected", [ +([1, 1, 2, 2, 3], 3), +([1, 2, 2, 3, 3], 4), +] + ) +def test_calculate_y_value(x_input, expected): + from test_in_class_exercise_Test_Driven_Development import calculate_y_value + answer = calculate_y_value(x_input) + assert answer == expected \ No newline at end of file From e9f0518b9514ad5c6545da624acce409eff1b215 Mon Sep 17 00:00:00 2001 From: SiyuZhou Date: Fri, 17 Feb 2023 11:21:25 -0500 Subject: [PATCH 2/2] Changed files for PEP8 --- in_class_exercise_Test_Driven_Development.py | 6 +++++- test_in_class_exercise_Test_Driven_Development.py | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/in_class_exercise_Test_Driven_Development.py b/in_class_exercise_Test_Driven_Development.py index 433c39e..cbe03c1 100644 --- a/in_class_exercise_Test_Driven_Development.py +++ b/in_class_exercise_Test_Driven_Development.py @@ -1,5 +1,9 @@ def calculate_y_value(x: list): - x1, y1, x2, y2, x3 = x.split(",") + x1 = x[0] + y1 = x[1] + x2 = x[2] + y2 = x[3] + x3 = x[4] if x1 == x2: return None else: diff --git a/test_in_class_exercise_Test_Driven_Development.py b/test_in_class_exercise_Test_Driven_Development.py index a92cd28..520b4e3 100644 --- a/test_in_class_exercise_Test_Driven_Development.py +++ b/test_in_class_exercise_Test_Driven_Development.py @@ -1,11 +1,13 @@ import pytest + @pytest.mark.parametrize("x_input, expected", [ -([1, 1, 2, 2, 3], 3), -([1, 2, 2, 3, 3], 4), -] + ([1, 1, 2, 2, 3], 3), + ([1, 2, 2, 3, 3], 4), + ([1, 2, 1, 2, 3], None) +] ) def test_calculate_y_value(x_input, expected): - from test_in_class_exercise_Test_Driven_Development import calculate_y_value + from in_class_exercise_Test_Driven_Development import calculate_y_value answer = calculate_y_value(x_input) - assert answer == expected \ No newline at end of file + assert answer == expected