Skip to content

Commit fa2e842

Browse files
authored
Merge pull request #338 from cs50/feat/practice-todo-list-checks
Add checks for practice problem set
2 parents 5499855 + c3f4c3a commit fa2e842

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

tasks/.cs50.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
check50:
2+
files: &check50_files
3+
- !exclude "*"
4+
- !require tasks.py

tasks/__init__.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import check50
2+
from re import escape
3+
4+
@check50.check()
5+
def exists():
6+
"""tasks.py exists"""
7+
check50.exists("tasks.py")
8+
check50.include("testing.py", "monday.txt")
9+
10+
@check50.check(exists)
11+
def test_correct_input():
12+
"""tasks.py correctly accepts two command-line inputs"""
13+
check50.run("python3 tasks.py").exit(code=1)
14+
15+
@check50.check(exists)
16+
def test_simple_add():
17+
"""tasks.py correctly handles simple add case"""
18+
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Eat"
19+
check50.run("python3 tasks.py monday.txt").stdin("add Eat", prompt=True).stdout(regex(output), output).kill()
20+
21+
@check50.check(exists)
22+
def test_print_add():
23+
"""tasks.py correctly prints added task"""
24+
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David"
25+
check50.run("python3 tasks.py monday.txt").stdin("add Call David", prompt=True).stdout(regex(output), output).kill()
26+
27+
@check50.check(exists)
28+
def test_case_add():
29+
"""tasks.py correctly handles case-sensitive add"""
30+
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David"
31+
check50.run("python3 tasks.py monday.txt").stdin("aDd Call David", prompt=True).stdout(regex(output), output).kill()
32+
33+
@check50.check(exists)
34+
def test_print_remove():
35+
"""tasks.py correctly prints list after removal"""
36+
output = "1. Rip a Phonebook"
37+
check50.run("python3 tasks.py monday.txt").stdin("remove Attend Lecture", prompt=True).stdout(regex(output), output).kill()
38+
39+
@check50.check(exists)
40+
def test_case_remove():
41+
"""tasks.py correctly handles case-sensitive remove"""
42+
output = "1. Rip a Phonebook"
43+
check50.run("python3 tasks.py monday.txt").stdin("rEMoVe Attend Lecture", prompt=True).stdout(regex(output), output).kill()
44+
45+
@check50.check(exists)
46+
def test_invalid_remove():
47+
"""tasks.py correctly exits when no match to remove"""
48+
check50.run("python3 tasks.py monday.txt").stdin("remove Feed the Cat", prompt=True).exit(code=1)
49+
50+
@check50.check(exists)
51+
def test_just_command():
52+
"""tasks.py correctly exits when no task is given"""
53+
check50.run("python3 tasks.py monday.txt").stdin("add", prompt=True).exit(code=1)
54+
55+
@check50.check(exists)
56+
def test_invalid_command():
57+
"""tasks.py correctly exits when invalid operation"""
58+
check50.run("python3 tasks.py monday.txt").stdin("edit Rip a Phonebook", prompt=True).exit(code=1)
59+
60+
def regex(text):
61+
"""match case-sensitively with any characters on either side"""
62+
return rf"^.*{escape(text)}.*$"

tasks/monday.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Attend Lecture
2+
Rip a Phonebook

tasks/testing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from tasks import add_task, remove_task, txt_length, update_txt
2+
import sys
3+
4+
def main():
5+
6+
argument = sys.argv[1]
7+
tasks = ['Attend Lecture', 'Rip a Phonebook']
8+
description = sys.argv[3]
9+
filepath = sys.argv[1]
10+
11+
if argument == "add":
12+
tasks.add_task(tasks, description, filepath)
13+
print(tasks.txt_length(filepath))
14+
15+
if __name__ == "__main__":
16+
main()

0 commit comments

Comments
 (0)