initial commit with 2024 materials
This commit is contained in:
commit
6fdfdbb8b7
66 changed files with 102457 additions and 0 deletions
19
tests/test_first.py
Normal file
19
tests/test_first.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
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
|
107
tests/test_local_maxima.py
Normal file
107
tests/test_local_maxima.py
Normal file
|
@ -0,0 +1,107 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue