diff --git a/tasks/.cs50.yml b/tasks/.cs50.yml new file mode 100644 index 0000000..c2de080 --- /dev/null +++ b/tasks/.cs50.yml @@ -0,0 +1,4 @@ +check50: + files: &check50_files + - !exclude "*" + - !require tasks.py diff --git a/tasks/__init__.py b/tasks/__init__.py new file mode 100644 index 0000000..d855bb4 --- /dev/null +++ b/tasks/__init__.py @@ -0,0 +1,62 @@ +import check50 +from re import escape + +@check50.check() +def exists(): + """tasks.py exists""" + check50.exists("tasks.py") + check50.include("testing.py", "monday.txt") + +@check50.check(exists) +def test_correct_input(): + """tasks.py correctly accepts two command-line inputs""" + check50.run("python3 tasks.py").exit(code=1) + +@check50.check(exists) +def test_simple_add(): + """tasks.py correctly handles simple add case""" + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Eat" + check50.run("python3 tasks.py monday.txt").stdin("add Eat", prompt=True).stdout(regex(output), output).kill() + +@check50.check(exists) +def test_print_add(): + """tasks.py correctly prints added task""" + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David" + check50.run("python3 tasks.py monday.txt").stdin("add Call David", prompt=True).stdout(regex(output), output).kill() + +@check50.check(exists) +def test_case_add(): + """tasks.py correctly handles case-sensitive add""" + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David" + check50.run("python3 tasks.py monday.txt").stdin("aDd Call David", prompt=True).stdout(regex(output), output).kill() + +@check50.check(exists) +def test_print_remove(): + """tasks.py correctly prints list after removal""" + output = "1. Rip a Phonebook" + check50.run("python3 tasks.py monday.txt").stdin("remove Attend Lecture", prompt=True).stdout(regex(output), output).kill() + +@check50.check(exists) +def test_case_remove(): + """tasks.py correctly handles case-sensitive remove""" + output = "1. Rip a Phonebook" + check50.run("python3 tasks.py monday.txt").stdin("rEMoVe Attend Lecture", prompt=True).stdout(regex(output), output).kill() + +@check50.check(exists) +def test_invalid_remove(): + """tasks.py correctly exits when no match to remove""" + check50.run("python3 tasks.py monday.txt").stdin("remove Feed the Cat", prompt=True).exit(code=1) + +@check50.check(exists) +def test_just_command(): + """tasks.py correctly exits when no task is given""" + check50.run("python3 tasks.py monday.txt").stdin("add", prompt=True).exit(code=1) + +@check50.check(exists) +def test_invalid_command(): + """tasks.py correctly exits when invalid operation""" + check50.run("python3 tasks.py monday.txt").stdin("edit Rip a Phonebook", prompt=True).exit(code=1) + +def regex(text): + """match case-sensitively with any characters on either side""" + return rf"^.*{escape(text)}.*$" diff --git a/tasks/monday.txt b/tasks/monday.txt new file mode 100644 index 0000000..30fe521 --- /dev/null +++ b/tasks/monday.txt @@ -0,0 +1,2 @@ +Attend Lecture +Rip a Phonebook \ No newline at end of file diff --git a/tasks/testing.py b/tasks/testing.py new file mode 100644 index 0000000..b7eebbd --- /dev/null +++ b/tasks/testing.py @@ -0,0 +1,16 @@ +from tasks import add_task, remove_task, txt_length, update_txt +import sys + +def main(): + + argument = sys.argv[1] + tasks = ['Attend Lecture', 'Rip a Phonebook'] + description = sys.argv[3] + filepath = sys.argv[1] + + if argument == "add": + tasks.add_task(tasks, description, filepath) + print(tasks.txt_length(filepath)) + +if __name__ == "__main__": + main()