diff --git a/labs/dicts/morsecodepalindromes/README.md b/labs/dicts/morsecodepalindromes/README.md index 167f135..7f8c90e 100644 --- a/labs/dicts/morsecodepalindromes/README.md +++ b/labs/dicts/morsecodepalindromes/README.md @@ -8,8 +8,8 @@ Write a Python program to solve the Kattis problem Morse Code Palindrome: [https 1. Open your CS0Lab-... repo in VS Code 2. Create a lab folder **morsecodepalindromes** inside your CS0Lab-... repository -3. Inside the lab folder, create two files: main.py and test_main.py -4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points) +3. Inside the lab folder, create two files provided in the lab folder. +4. Type the partial code stub provided and fix all FIXMEs. (80 points) 5. Follow best programming practices by using proper white spaces, comments, etc. ```text @@ -22,15 +22,16 @@ Kattis is a computer program that provides specific input and expects exact outp 6. Unittest all the important functions using pytest. Install pytest if required. ```bash - $ pytest --version - $ pip install -U pytest - $ pytest test_main.py + $ pytest --version + $ pip install -U pytest + $ pytest test_main.py + $ python -m pytest test_main.py ``` 7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples. -8. Upload only the main.py script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. +8. Upload only the solution script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. 9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points) -10. Update your README file (10 points) as shown here: https://github.com/rambasnet/csci000-astudent +10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent) ## Submission @@ -47,4 +48,4 @@ $ git push $ git status ``` -- Check and make sure the files are actually pushed to your GitHub repo on github.com. +- Check and make sure the files are actually pushed to your GitHub repo. diff --git a/labs/dicts/morsecodepalindromes/main.py b/labs/dicts/morsecodepalindromes/morsecode.py similarity index 83% rename from labs/dicts/morsecodepalindromes/main.py rename to labs/dicts/morsecodepalindromes/morsecode.py index 516a3f8..867d256 100644 --- a/labs/dicts/morsecodepalindromes/main.py +++ b/labs/dicts/morsecodepalindromes/morsecode.py @@ -9,15 +9,14 @@ Given english text, the program finds if the corresponding morse code is a palindrome. Algorithm steps: - 1. Create a dictionary to map alphabets and numbers to morse code - 2. Read the input english string - 3. Convert the string into upper case english string - 4. Convert english string into Morse Code string using the dictionary - 5. Check if the Morse Code string is a palindrome - i. Print 1 if it's a palindrome - ii Otherwise, print 0 +1. Create a dictionary to map alphabets and numbers to morse code +2. Read the input english string +3. Convert the string into upper case english string +4. Convert english string into Morse Code string using the dictionary +5. Check if the Morse Code string is a palindrome + i. Print 1 if it's a palindrome + ii Otherwise, print 0 """ - import sys # create English to Morse Code dictionary @@ -88,14 +87,14 @@ def convert_to_morse(english: str) -> str: return morse_code -def solve(): +def solve() -> None: # read/input english text as a line english = input() # FIXME 4: convert english into uppercase upper_english = english print(upper_english, file=sys.stderr) morse_code = convert_to_morse(upper_english) - # FIXME 5 - call is_palindrome passing proper argument and print the result + # FIXME 5: call is_palindrome passing proper argument and print the result if __name__ == '__main__': diff --git a/labs/dicts/morsecodepalindromes/test_main.py b/labs/dicts/morsecodepalindromes/test_morsecode.py similarity index 67% rename from labs/dicts/morsecodepalindromes/test_main.py rename to labs/dicts/morsecodepalindromes/test_morsecode.py index 76e554d..e72fc1d 100644 --- a/labs/dicts/morsecodepalindromes/test_main.py +++ b/labs/dicts/morsecodepalindromes/test_morsecode.py @@ -1,11 +1,11 @@ -"""Module to test functions in main.py +"""Module to test functions in morsecode.py """ -import main +import morsecode def test_convert_to_palindrome1(): - actual_ans = main.convert_to_morse('AN') + actual_ans = morsecode.convert_to_morse('AN') expected_ans = '.--.' assert actual_ans == expected_ans @@ -13,7 +13,7 @@ def test_convert_to_palindrome1(): def test_ispalindrome1(): - ans = main.is_palindrome('.--.') + ans = morsecode.is_palindrome('.--.') expected = 1 assert ans == expected diff --git a/labs/lists/pet/README.md b/labs/lists/pet/README.md index 819d036..f307a6c 100644 --- a/labs/lists/pet/README.md +++ b/labs/lists/pet/README.md @@ -7,9 +7,9 @@ Write a Python program to solve the Kattis problem called pet: [https://open.kat ## Lab Instructions 1. Open your CS0Lab-... repo in VS Code -2. Create lab folder **pet** inside your CS0Lab-... repository -3. Inside the pet folder, create two files: main.py and test_main.py -4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points) +2. Create lab folder **lists** inside your CS0Lab-... repository +3. Inside the pet folder, create two files: pet.py and test_pet.py +4. Type the partial code stub provided in the lab folder and fix all FIXMEs. (80 points) 5. Follow best programming practices by using proper white spaces, comments, etc. ```text @@ -24,13 +24,14 @@ Kattis is a computer program that provides specific input and expects exact outp ```bash $ pytest --version $ pip install -U pytest - $ pytest test_main.py + $ pytest . + $ python -m pytest . ``` 7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples. -8. Upload only the .py scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. +8. Upload only the solution script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. 9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points) -10. Update your README file (10 points) as shown here: https://github.com/rambasnet/csci000-astudent +10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent) ## Submission @@ -46,5 +47,4 @@ $ git push $ git status ``` -- Check and make sure the files are actually pushed to your GitHub repo on github.com. -NOTE: Do not add and commit to this lab folder after the due date as it may be considered late submission! +- Check and make sure the files are actually pushed to your GitHub repo. diff --git a/labs/lists/pet/main.py b/labs/lists/pet/pet.py similarity index 68% rename from labs/lists/pet/main.py rename to labs/lists/pet/pet.py index ed2d8a9..2af2f4a 100644 --- a/labs/lists/pet/main.py +++ b/labs/lists/pet/pet.py @@ -7,23 +7,23 @@ Read and solve - Pet: https://open.kattis.com/problems/pet Algorithm steps: - 1. Create a list to store the total scores of each contestant - 2. Repeat 5 times: - 1. Read the input line - 2. Split the line into a list of numbers - 3. Convert the list of strings into a list of ints - 4. Sum the list of ints - 5. Append the sum to the list of scores + 1. Create a list to store the total scores of each contestant + 2. Repeat 5 times: + i. Read the input line + ii. Split the line into a list of numbers + iii. Convert the list of strings into a list of ints + iv. Sum the list of ints + v. Append the sum to the list of scores 3. Find the max score in the list of scores 4. Find the index of the max score in the list of scores 5. Print the index of the max score + 1 and the max score """ -import sys + from typing import List -def main(): +def main() -> None: """Main function that solves the problem """ # step 1. create a list to store the total scores of each contestant @@ -35,7 +35,7 @@ def main(): # FIXME 5 - print the final output calling answer function -def get_data(): +def get_data() -> List[int]: """Reads the data from std input and returns it as a list of ints Args: None @@ -43,12 +43,11 @@ def get_data(): List[int]: list of ints """ str_nums = input().split() # list of string numbers - # FIXME 6: convert str_nums int a list of ints and return it - pass + # FIXME 6: convert str_nums as list of ints and return it -def list_sum(numbers: List[int]): - """Finds and returns sum of the numbers in the list +def list_sum(numbers: List[int]) -> int: + """Finds and returns sum of the numbers in the list. Args: numbers: List[int]: # takes a list of numbers as a parameter @@ -60,16 +59,16 @@ def list_sum(numbers: List[int]): return ans -def answer(scores: List[int]): - """Returns the index of the max score + 1 and the max score as a string - +def answer(scores: List[int]) -> str: + """Find and return the answer as a string. Args: scores (List[int]): List of 5 contestants scores + Returns: + str: index of the max score + 1 and the max score as a string """ max_score = max(scores) index = scores.index(max_score) # FIXME 8: return the index+1 and the max number in the list as a string - pass if __name__ == "__main__": diff --git a/labs/lists/pet/test_main.py b/labs/lists/pet/test_main.py deleted file mode 100644 index a5db09d..0000000 --- a/labs/lists/pet/test_main.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Moduel to test important function in main.py -""" - -import sys -import main - -# test function must start with test_ prefix for pytest to recognize it - - -def test_answer(): - """Tests answer function - """ - ans = main.answer([10, 20, 11, 15, 13]) - expected = "2 20" - assert ans == expected, f"Expected: {expected}, but got: {ans}" - ans = main.answer([6, 10, 8, 4, 15]) - expected = "5 15" - assert ans == expected, f"Expected: {expected}, but got: {ans}" - # FIXME 10: add 2 more test cases - print("All test cases passed...", file=sys.stderr) - - -# test function must start with test_ prefix for pytest to recognize it -def test_list_sum(): - """Tests list_sum function - """ - ans = main.list_sum([6, 7, 8, 10]) - expected = 31 - assert ans == expected, f"Expected: {expected}, but got: {ans}" - ans = main.list_sum([2, 3, 4, 5]) - expected = 14 - assert ans == expected, f"Expected: {expected}, but got: {ans}" - # FIXME 9: add 2 more test cases - print("All test cases passed...", file=sys.stderr) diff --git a/labs/lists/pet/test_pet.py b/labs/lists/pet/test_pet.py new file mode 100644 index 0000000..347cba5 --- /dev/null +++ b/labs/lists/pet/test_pet.py @@ -0,0 +1,38 @@ +"""Moduel to test important function in pet.py. +""" + +import pet + + +def test_answer() -> None: + """Tests answer function.""" + ans = pet.answer([10, 20, 11, 15, 13]) + expected = "2 20" + assert ans == expected, f"Expected: {expected}, but got: {ans}" + + +def test_answer2() -> None: + """Tests answer function.""" + ans = pet.answer([6, 10, 8, 4, 15]) + expected = "5 15" + assert ans == expected, f"Expected: {expected}, but got: {ans}" + +# FIXME 1: add a test case function to test answer function +# FIXME 2: add a test case function to test answer function + + +def test_list_sum() -> None: + """Tests list_sum function.""" + ans = pet.list_sum([6, 7, 8, 10]) + expected = 31 + assert ans == expected, f"Expected: {expected}, but got: {ans}" + + +def test_list_sum2() -> None: + """Tests list_sum function.""" + ans = pet.list_sum([2, 3, 4, 5]) + expected = 14 + assert ans == expected, f"Expected: {expected}, but got: {ans}" + +# FIXME 3: add a test case function to test list_sum function +# FIXME 4: add a test case function to test list_sum function diff --git a/labs/loops/oddities/README.md b/labs/loops/oddities/README.md index 6e8ac4e..e4e4de9 100644 --- a/labs/loops/oddities/README.md +++ b/labs/loops/oddities/README.md @@ -8,8 +8,8 @@ Write a Python program to solve the Kattis problem - Oddities [https://open.katt 1. Open your CS0Lab-... repo in VS Code 2. Create lab folder **oddities** inside your CS0Lab-... repository -3. Inside the lab folder, create two files: main.py and test_main.py -4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points) +3. Inside the lab folder, create two files. +4. Type the partial code stub provided and fix all FIXMEs. (80 points) 5. Follow best programming practices by using proper white spaces, comments, etc. ```note @@ -24,12 +24,12 @@ Kattis is a computer program that provides specific input and expects exact outp ```bash $ pytest --version $ pip install -U pytest - $ pytest test_main.py - $ python -m pytest test_main.py + $ pytest . + $ python -m pytest . ``` 7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples. -8. Upload only the .py scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. +8. Upload only the solution script to Kattis. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. 9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points) 10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent) diff --git a/labs/loops/oddities/main.py b/labs/loops/oddities/oddities.py similarity index 100% rename from labs/loops/oddities/main.py rename to labs/loops/oddities/oddities.py diff --git a/labs/loops/oddities/test_main.py b/labs/loops/oddities/test_oddities.py similarity index 83% rename from labs/loops/oddities/test_main.py rename to labs/loops/oddities/test_oddities.py index 011f9b9..0e1d87d 100644 --- a/labs/loops/oddities/test_main.py +++ b/labs/loops/oddities/test_oddities.py @@ -1,29 +1,30 @@ -"""Test cases for main.py""" -import main +"""Test cases for oddities.py""" +import oddities def test_answer(): """Test answer function.""" - ans = main.answer(10) + ans = oddities.answer(10) expected = "10 is even" assert ans == expected, f"Expected: {expected}, but got: {ans}" def test_answer2(): """Test answer function for negavitve odd number.""" - ans = main.answer(-199) + ans = oddities.answer(-199) expected = "-199 is odd" assert ans == expected, f"Expected: {expected}, but got: {ans}" # FIXME 6: add a new test case function to test your answer function + # FIXME 7: add a new test case function to test your answer function def test_odd_even(): """Test odd_even function. """ - ans = main.odd_even(10) + ans = oddities.odd_even(10) expected = "even" assert ans == expected, f"Expected: {expected}, but got: {ans}" @@ -31,9 +32,11 @@ def test_odd_even(): def test_odd_even2(): """Test odd_even function for negavitve odd number """ - ans = main.odd_even(-199) + ans = oddities.odd_even(-199) expected = "odd" assert ans == expected, f"Expected: {expected}, but got: {ans}" + # FIXME 8: add a new test case function to test your answer function + # FIXME 9: add a new test case function to test your answer function diff --git a/labs/strings/simonsays/README.md b/labs/strings/simonsays/README.md index 49fd0fd..942acdb 100644 --- a/labs/strings/simonsays/README.md +++ b/labs/strings/simonsays/README.md @@ -7,9 +7,9 @@ Write a Python program to solve the Kattis problem - Simon Says [https://open.ka ## Lab Instructions 1. Open your CS0Lab-... repo in VS Code -2. Create a lab folder **simonsays** inside your CS0Lab-... repository -3. Inside the lab folder, create two files: main.py and test_main.py -4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points) +2. Create a lab folder **strings** inside your CS0Lab-... repository +3. Inside the lab folder, create two files: simonsays.py and test_simonsays.py +4. Type the partial code stub provided in the lab folder and fix all FIXMEs. (80 points) 5. Follow best programming practices by using proper white spaces, comments, etc. ```note @@ -19,16 +19,17 @@ Print as asked: nothing less; nothing more! Kattis is a computer program that provides specific input and expects exact output – to a space to give the correct verdict. ``` -6. Unittest all the important functions using pytest. Install pytest if required. +6. Run pytest on test module. Install pytest if required. ```bash - $ pytest --version - $ pip install -U pytest - $ pytest test_main.py + $ pytest --version + $ pip install -U pytest + $ pytest . + $ python -m pytest . ``` 7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples. -8. Upload only the .py scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. +8. Upload only the solution scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. 9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points) 10. Update your README file as shown here: https://github.com/rambasnet/csci000-astudent (10 points) @@ -47,4 +48,3 @@ $ git status ``` - Check and make sure the files are actually pushed to your GitHub repo on github.com. -NOTE: Do not add and commit to this lab folder after the due date as it may be considered late submission! diff --git a/labs/strings/simonsays/main.py b/labs/strings/simonsays/simonsays.py similarity index 67% rename from labs/strings/simonsays/main.py rename to labs/strings/simonsays/simonsays.py index e7cf0b4..06c40da 100644 --- a/labs/strings/simonsays/main.py +++ b/labs/strings/simonsays/simonsays.py @@ -7,18 +7,16 @@ Read and solve - Simon Says: https://open.kattis.com/problems/simonsays Algorithm: - 1. Read N - 2. Repeat N times: - 1. Read the input string - 2. Check if the string begins with 'Simon says' - 3. If it does, print the rest of the string after 'Simon says', otherwise ignore the string + 1. Read N + 2. Repeat N times: + 1. Read the input string + 2. Check if the string begins with 'Simon says' + 3. If it does, print the rest of the string after 'Simon says', otherwise ignore the string """ -import sys - def main(): - """Main function that solves the problem + """Main function that solves the problem. """ # step 1. read data N = int(input()) @@ -28,14 +26,14 @@ def main(): # FIXME 4 - print the answer if it returns one, otherwise ignore it -def valid_command(command: str): - """Checks if the string begins with 'Simon says' +def valid_command(command: str) -> bool: + """Checks if the string starts with 'Simon says'. Args: - command (str): string to check + command (str): string to check. Returns: - bool: True if the string begins with 'Simon says', False otherwise + bool: True if the string starts with 'Simon says', False otherwise. """ # FIXME 5: if the command begins with 'Simon says', return True # otherwise, return False @@ -43,8 +41,8 @@ def valid_command(command: str): return ans -def answer(command: str): - """Returns answer given the command or None if the command is not valid +def answer(command: str) -> str | None: + """Returns answer given the command or None if the command is not valid. Args: command (str): string to check diff --git a/labs/strings/simonsays/test_main.py b/labs/strings/simonsays/test_main.py deleted file mode 100644 index bf16877..0000000 --- a/labs/strings/simonsays/test_main.py +++ /dev/null @@ -1,29 +0,0 @@ -import sys -import main - -# test function must start with test_ prefix for pytest to recognize it - - -def test_valid_command(): - """Test valid_command function. - """ - ans = main.valid_command("Simon says do this") - expected = True - assert ans == expected, f"Expected: {expected}, but got: {ans}" - ans = main.valid_command("do this") - expected = False - assert ans == expected, f"Expected: {expected}, but got: {ans}" - # FIXME 7: add a new case to test valid_command function - # FIXME 8: add a new case to test valid_command function - print("All test cases passed...", file=sys.stderr) - - -def test_answer(): - """Test answer function. - """ - ans = main.answer("Simon says do this") - expected = " do this" - assert ans == expected, f"Expected: {expected}, but got: {ans}" - # FIXME 9: add a new case to test answer function - # FIXME 10: add a new case to test answer function - print("All test cases passed...", file=sys.stderr) diff --git a/labs/strings/simonsays/test_simonsays.py b/labs/strings/simonsays/test_simonsays.py new file mode 100644 index 0000000..3acf915 --- /dev/null +++ b/labs/strings/simonsays/test_simonsays.py @@ -0,0 +1,35 @@ +"""Test cases for simonsays.py +""" + +import simonsays + + +def test_valid_command(): + """Test valid_command function. + """ + ans = simonsays.valid_command("Simon says do this") + expected = True + assert ans == expected, f"Expected: {expected}, but got: {ans}" + + +def test_valid_command2(): + """Test valid_command function.""" + ans = simonsays.valid_command("do this") + expected = False + assert ans == expected, f"Expected: {expected}, but got: {ans}" + +# FIXME 7: add a new test case function to test valid_command function + +# FIXME 8: add a new test case function to test valid_command function + + +def test_answer(): + """Test answer function. + """ + ans = simonsays.answer("Simon says do this") + expected = " do this" + assert ans == expected, f"Expected: {expected}, but got: {ans}" + +# FIXME 9: add a new test case function to test answer function + +# FIXME 10: add a new test case function to test answer function