diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml new file mode 100644 index 00000000..c45bcbfc --- /dev/null +++ b/.github/workflows/run_test.yml @@ -0,0 +1,32 @@ +name: simple_calculator unit test + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with Ruff + run: | + pip install ruff + ruff --format=github --target-version=py310 . + continue-on-error: true + - name: Test with pytest + run: | + coverage run -m pytest tests/tests_1b.py -v -s + - name: Generate Coverage Report + run: | + coverage report -m \ No newline at end of file diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..72a8f422 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,4 +1,5 @@ """ +This is to simulate a change made on a robot: robot_speed = 5 # m/s lab_1a.py The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 @@ -8,9 +9,9 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Eva" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") - + print("Hi, my name is Eva. I am a junior in highschool, and I enjoy learning about programming!") if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..83e1692a 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -37,6 +37,14 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") +def request_santized_number(prompt: str) -> float: + while True: + try: + number = float (input (prompt)) + return number + except ValueError: + print("Invalid input. Please enter a valid number.") + def main(): print(f"===== Simple Calculator =====") @@ -50,6 +58,5 @@ def main(): result = simple_calculator(operation, num1, num2) print(f"The result of {operation}ing {num1} and {num2} is: {result}") - if __name__ == "__main__": main() diff --git a/tests/tests_1b.py b/tests/tests_1b.py index be6b822d..8c6fa033 100644 --- a/tests/tests_1b.py +++ b/tests/tests_1b.py @@ -37,5 +37,13 @@ def test_invalid_operation(): with pytest.raises(ValueError, match="Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'."): simple_calculator("", 5, 3) # Test for empty operation +def test_large_numbers(): + assert simple_calculator("add", 1_000_000, 2_000_000) == 3_000_000 + assert simple_calculator("multiply", 10_000, 10_000) == 100_000_000 + +def test_negative_results(): + assert simple_calculator("subtract", 3, 5) == -2 + assert simple_calculator("divide", 1, -2) == -0.5 + if __name__ == "__main__": pytest.main() \ No newline at end of file