Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Student 14 branch #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bootcamp/contrib/student_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def getAverageLength(string, string2):
""" Get the average length of two strings

Parameters
----------
string : str
The first string to count
string2 : str
The second string to count

Returns
-------
float
Average of length
"""

avg = (len(string) + len(string2)) / 2

return avg
28 changes: 28 additions & 0 deletions bootcamp/contrib/tests/test_student_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from bootcamp.contrib.student_14 import getAverageLength # noqa


def test_getAverageLength_diff():
test_string = "AGTCTG"
test_string2 = "ATCGTCGGA"

expected_average = 7.5
observed_average = getAverageLength(test_string, test_string2)
assert expected_average == observed_average


def test_getAverageLength_same():
test_string = "ACT"
test_string2 = "ACT"

expected_average = 3
observed_average = getAverageLength(test_string, test_string2)
assert expected_average == observed_average


def test_getAverageLength_zero():
test_string = ""
test_string2 = ""

expected_average = 0.0
observed_average = getAverageLength(test_string, test_string2)
assert expected_average == observed_average
5 changes: 4 additions & 1 deletion bootcamp/core/student_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def count_substring(string, substring):
string : str
The string to count within
substring : str
The value to count in string
The value to count in string, case insensitive

Returns
-------
Expand All @@ -16,6 +16,9 @@ def count_substring(string, substring):
"""
count = 0

string = string.upper()
substring = substring.upper()

string_length = len(string)
substring_length = len(substring)
n_subsequences = string_length - substring_length + 1
Expand Down
27 changes: 27 additions & 0 deletions bootcamp/core/tests/test_student_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ def test_count_substring_none():
expected_count = 0
observed_count = count_substring(test_string, test_substring)
assert expected_count == observed_count


def test_count_substring_case_cap():
test_string = "CGCTAGCGT"
test_substring = "CGT"

expected_count = 1
observed_count = count_substring(test_string, test_substring)
assert expected_count == observed_count


def test_count_substring_case_lower():
test_string = "CGCTAGCGT"
test_substring = "cgt"

expected_count = 1
observed_count = count_substring(test_string, test_substring)
assert expected_count == observed_count


def test_count_substring_case_mix():
test_string = "CGCTAGCGT"
test_substring = "CgT"

expected_count = 1
observed_count = count_substring(test_string, test_substring)
assert expected_count == observed_count
Loading