From 952f8b97a585e2fb06de42f9124cc3f1bab4422b Mon Sep 17 00:00:00 2001 From: Pamela Hathway Date: Tue, 23 Sep 2025 13:19:04 +0300 Subject: [PATCH] updates lecture files --- hands_on/first/test_first.py | 17 +-- hands_on/first_teacher/first.py | 13 +-- hands_on/local_maxima/local_maxima.py | 5 + .../test_local_maxima.py | 3 - tests/test_first.py | 19 ---- tests/test_local_maxima.py | 107 ------------------ 6 files changed, 10 insertions(+), 154 deletions(-) delete mode 100644 tests/test_first.py delete mode 100644 tests/test_local_maxima.py diff --git a/hands_on/first/test_first.py b/hands_on/first/test_first.py index 64ea1a8..5ac7354 100644 --- a/hands_on/first/test_first.py +++ b/hands_on/first/test_first.py @@ -1,19 +1,6 @@ -from first import times_3 - - def test_times_3_integer(): - value = 7 - expected = 21 - - result = times_3(value) - - assert result == expected + pass def test_times_3_string(): - value = 'wow' - expected = 'wowwowwow' - - result = times_3(value) - - assert result == expected + pass diff --git a/hands_on/first_teacher/first.py b/hands_on/first_teacher/first.py index fd6c5e0..6d9e0ea 100644 --- a/hands_on/first_teacher/first.py +++ b/hands_on/first_teacher/first.py @@ -1,13 +1,6 @@ def times_3(x): - """ Multiply x by 3. - - Parameters - ---------- - x : The item to multiply by 3. - """ - return x * 3 + pass -if __name__ == '__main__': - print(times_3(2)) - print(times_3("a")) \ No newline at end of file +if __name__ == "__main__": + pass diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index db89ba3..cfd0a9e 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -8,3 +8,8 @@ def find_maxima(x): idx -- list of indices of the local maxima in x """ return [] + + +if __name__ == "__main__": + x = [1, 2, 3] + print(find_maxima(x)) diff --git a/hands_on/local_maxima_part3_debug/test_local_maxima.py b/hands_on/local_maxima_part3_debug/test_local_maxima.py index 008d9db..8e78af1 100644 --- a/hands_on/local_maxima_part3_debug/test_local_maxima.py +++ b/hands_on/local_maxima_part3_debug/test_local_maxima.py @@ -1,6 +1,3 @@ -import numpy as np -import pytest - from local_maxima import find_maxima diff --git a/tests/test_first.py b/tests/test_first.py deleted file mode 100644 index 64ea1a8..0000000 --- a/tests/test_first.py +++ /dev/null @@ -1,19 +0,0 @@ -from first import times_3 - - -def test_times_3_integer(): - value = 7 - expected = 21 - - result = times_3(value) - - assert result == expected - - -def test_times_3_string(): - value = 'wow' - expected = 'wowwowwow' - - result = times_3(value) - - assert result == expected diff --git a/tests/test_local_maxima.py b/tests/test_local_maxima.py deleted file mode 100644 index 008d9db..0000000 --- a/tests/test_local_maxima.py +++ /dev/null @@ -1,107 +0,0 @@ -import numpy as np -import pytest - -from local_maxima import find_maxima - - -def test_find_maxima(): - values = [1, 3, -2, 0, 2, 1] - expected = [1, 4] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_edges(): - values = [4, 2, 1, 0, 1, 5] - expected = [0, 5] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_empty(): - values = [] - expected = [] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_plateau(): - values = [1, 2, 2, 1] - expected = [1] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_not_a_plateau(): - values = [1, 2, 2, 3, 1] - expected = [3] - maxima = find_maxima(values) - assert maxima == expected - - -# the tests below here fail, can you get them to pass? - - -def test_find_maxima_correct_order(): - # TASK: get this test to pass - values = [2, 1, 5, 1, 9] - expected = [0, 2, 4] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_one_value(): - # TASK: get this test to pass - values = [1] - expected = [0] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_long_plateau(): - # TASK: Change the implementation for when there is a plateau - # for uneven plateau length, return the middle index, e.g. [1, 2, *2*, 2, 1] --> [2] - # for even plateau length, return the index left of the middle e.g. [1, 2, *2*, 2, 2, 1] --> [2] - values = [1, 2, 2, 2, 2, 2, 1, 8, 0] - expected = [3, 7] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_plateau_at_end(): - # TASK: make sure plateaus at the end are handled properly (see test above) - values = [1, 2, 2] - expected = [1] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_plateau_at_start(): - # TASK: make sure plateaus at the start are handled properly (see test above) - values = [1, 1, 0, 0] - expected = [0] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_all_same_values(): - # TASK: implement a check for lists where there is no local maximum - values = [1, 1] - expected = [0] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_letters(): - # stings can be evaluated with > and <, who knew! - # Find an easy solution so that both "t"s are recognised as local maxima - values = ["T", "e", "s", "t", "s", "!"] - expected = [0, 3] - maxima = find_maxima(values) - assert maxima == expected - - -def test_find_maxima_new_inputs_to_make_current_function_fail(): - # should you actually be done with all tests, then you can think of other cases where the current function fails - # and write tests for them and fix them - assert False