From e7582f7f6ab2b1b3c4a4debf2daa2ec46af74f31 Mon Sep 17 00:00:00 2001 From: Jade Wang Date: Thu, 19 Sep 2024 17:53:47 +0000 Subject: [PATCH 1/2] ENH make count_substring case insensitive --- bootcamp/core/student_14.py | 5 ++++- bootcamp/core/tests/test_student_14.py | 27 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/bootcamp/core/student_14.py b/bootcamp/core/student_14.py index b904827..90d396d 100644 --- a/bootcamp/core/student_14.py +++ b/bootcamp/core/student_14.py @@ -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 ------- @@ -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 diff --git a/bootcamp/core/tests/test_student_14.py b/bootcamp/core/tests/test_student_14.py index 552107f..8596ca1 100644 --- a/bootcamp/core/tests/test_student_14.py +++ b/bootcamp/core/tests/test_student_14.py @@ -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 From c14aba29a48ca262c7093fd2b5c5d61db9ac96c9 Mon Sep 17 00:00:00 2001 From: Jade Wang Date: Thu, 19 Sep 2024 18:17:59 +0000 Subject: [PATCH 2/2] New Feature added getAverageLength --- bootcamp/contrib/student_14.py | 19 +++++++++++++++ bootcamp/contrib/tests/test_student_14.py | 28 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bootcamp/contrib/student_14.py create mode 100644 bootcamp/contrib/tests/test_student_14.py diff --git a/bootcamp/contrib/student_14.py b/bootcamp/contrib/student_14.py new file mode 100644 index 0000000..09865df --- /dev/null +++ b/bootcamp/contrib/student_14.py @@ -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 diff --git a/bootcamp/contrib/tests/test_student_14.py b/bootcamp/contrib/tests/test_student_14.py new file mode 100644 index 0000000..95707e3 --- /dev/null +++ b/bootcamp/contrib/tests/test_student_14.py @@ -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