Hejka, wysz艂o na tym, 偶e nie doko艅czyli艣my zadania z chapteru 4 i zamiast tego napisali艣my pierwsze testy ![]()
Wrzucam ko艅cowy kod:
import random
_100_throws = []
for i in range(100):
single_throw = random.choice(['t', 'h'])
_100_throws.append(single_throw)
# print(_100_throws)
def in_a_row(throws):
streak = 0
previous_throw = None
for throw in throws:
if previous_throw == throw:
streak += 1
else:
streak = 0
if streak == 5:
return True
previous_throw = throw
return False
# x = in_a_row(_100_throws)
# print(x)
def test_in_a_row_beginning():
mocked_throws = ['h', 'h', 'h', 'h', 'h', 'h', 't']
expected_result = True
actual_result = in_a_row(mocked_throws)
assert actual_result is expected_result
def test_in_a_row_ending():
x = 'ht' * 46 + 'h'
front_of_list = list(x)
mocked_throws = front_of_list + ['t', 'h', 'h', 'h', 'h', 'h', 'h']
assert len(mocked_throws) == 100
expected_result = True
actual_result = in_a_row(mocked_throws)
assert actual_result is expected_result
def test_in_a_row_returns_false():
x = 'ht' * 50
mocked_throws = list(x)
assert len(mocked_throws) == 100
expected_result = False
actual_result = in_a_row(mocked_throws)
assert actual_result is expected_result
test_in_a_row_beginning()
test_in_a_row_ending()
test_in_a_row_returns_false()
Reactions: pink_heart 脳2 (Asia_Lena, deleted_user_83454f0c50aa)