Created
April 15, 2022 17:38
-
-
Save firemanxbr/eb1fdf9bb145aeaa4b02188af143e267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Splunk Interview Challenge | |
Description: | |
How many times does it happen in the input string that exactly | |
two 9s appeared after each other? | |
String: | |
"9234997799123" | |
""" | |
def string_match(match, input_string): | |
""" | |
Function to count how many times a string appears in an input string | |
:param match: the string that wants to count | |
:param input_string: input string to be used | |
:return: how many times was found the match into input_string | |
""" | |
count = 0 | |
for i in range(len(input_string)-len(match) + 1): | |
if input_string[i:i + len(match)] == match: | |
count+=1 | |
return count | |
def test_empty_string(): | |
""" | |
Test to validate an empty string | |
""" | |
assert string_match(match="99", input_string="") == 0 | |
def test_standard(): | |
""" | |
Standard string and expected return | |
""" | |
assert string_match(match="99", input_string="9234997799123") == 2 | |
def test_increase_string(): | |
""" | |
String increased to validate a string change | |
""" | |
assert string_match(match="99", input_string="923499779912993") == 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment