Preparing git repo for final project
This commit is contained in:
37
problems/pset7/um/test_um.py
Normal file
37
problems/pset7/um/test_um.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from um import count
|
||||
|
||||
def main():
|
||||
test_count_ums()
|
||||
test_words_containing_ums()
|
||||
test_punctuation()
|
||||
test_from_cs50p()
|
||||
|
||||
|
||||
def test_count_ums():
|
||||
assert count("Hello, um, world") == 1
|
||||
assert count("Hello um, um, world um") == 3
|
||||
assert count("Um Hello, um, world um") == 3
|
||||
|
||||
|
||||
def test_words_containing_ums():
|
||||
assert count("instrumentation") == 0
|
||||
assert count("umbrella") == 0
|
||||
assert count("momentum") == 0
|
||||
|
||||
|
||||
def test_punctuation():
|
||||
assert count("Hello um?") == 1
|
||||
assert count("Hello um!") == 1
|
||||
assert count("Hello um") == 1
|
||||
assert count("Hello um.") == 1
|
||||
|
||||
|
||||
def test_from_cs50p():
|
||||
assert count("um") == 1
|
||||
assert count("um?") == 1
|
||||
assert count("Um, thanks for the album.") == 1
|
||||
assert count("Um, thanks, um...") == 2
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
15
problems/pset7/um/um.py
Normal file
15
problems/pset7/um/um.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import re
|
||||
|
||||
um_regex = re.compile(r"\bum\b", re.IGNORECASE)
|
||||
|
||||
|
||||
def main():
|
||||
print(count(input("Text: ")))
|
||||
|
||||
|
||||
def count(s):
|
||||
return len(um_regex.findall(s))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user