Skip to content
Open

test #233

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions labs/lab_1/lab_1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10
with your name. Then, save the code, add it to the staging area, and commit it to the Git tree.
This is to simulate a change made on a robot: robot_speed = 3 # m/s
"""

def main():
print("Hello World!")

name = "" # TODO: Insert your name between the double quotes
name = "Shravan Aadithya" # TODO: Insert your name between the double quotes

print(f"{name}, Welcome to the CSS course!")

print("Hi all! I'm Shravan, and I'm a sophomore from Virginia! I am in TSA, and I have been in a height growth competition.")
if __name__ == "__main__":
main()
18 changes: 15 additions & 3 deletions labs/lab_1/lab_1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@ 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_sanitized_number(prompt: str) -> float:
while True:
try:
number = float(input(prompt))
return number
except ValueError:
print("Invalid input. Please enter a valid number.")

def clean_operation(operation: str):
while(operation != "add" and operation != "subtract" and operation != "multiply" and operation != "divide"):
operation = input("Enter a valid operation (add, subtract, multiply, divide): ").strip().lower()
return operation
def main():

print(f"===== Simple Calculator =====")

# Ask the user for sample input
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower()
num1 = request_sanitized_number("Enter the first number: ")
num2 = request_sanitized_number("Enter the second number: ")
operation = clean_operation(input("Enter the operation (add, subtract, multiply, divide): ").strip().lower())

# Perform the calculation and display the result
result = simple_calculator(operation, num1, num2)
Expand Down
1 change: 1 addition & 0 deletions tests/tests_1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_division():
assert simple_calculator("divide", 6, 3) == 2 # Test for positive numbers
assert simple_calculator("divide", -4, 2) == -2 # Test for negative and positive number
assert simple_calculator("divide", 5, 2) == 2.5 # Test for division resulting in float
assert simple_calculator("divide", 0 , 1) == 0 #Test for dividng 0 by num

def test_division_by_zero():
with pytest.raises(ValueError, match="Cannot divide by zero."):
Expand Down