Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✏️ Workhop examples commit #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
9 changes: 8 additions & 1 deletion calculator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
from .calcurator import add, subtract, divide, multiply, square_root
from calculator.calcurator import (
add,
subtract,
divide,
multiply,
exponentiate,
square_root,
)
16 changes: 13 additions & 3 deletions calculator/calcurator.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import math


def add(x, y):
"""Returns the sum of x and y."""
return x + y


def multiply(x, y):
"""Returns the product of x and y."""
return x * y


def divide(x, y):
"""Returns the result of dividing x by y."""
if y != 0:
return x / y
else:
return "Error: Division by zero"


def subtract(x, y):
"""Returns the difference between x and y."""
return x - y


def exponentiate(x, y):
"""Returns x raised to the power of y."""
return x**y


def square_root(x):
"""Returns the square root of x."""
return x ** (1/2)


return math.sqrt(x)
15 changes: 12 additions & 3 deletions calculator/tests/unit_tests_calculator.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# test_calculator.py
from calculator import add, multiply, divide, subtract, exponentiate, square_root

from calculator import add, multiply, divide, subtract, square_root

def test_addition():
assert add(5, 3) == 8
assert add(0, 0) == 0
assert add(-5, 5) == 0


def test_multiplication():
assert multiply(4, 6) == 24
assert multiply(0, 10) == 0
assert multiply(-3, 7) == -21


def test_division():
assert divide(8, 2) == 4.0
assert divide(10, 5) == 2.0
assert divide(7, 0) == "Error: Division by zero"


def test_subtraction():
assert subtract(10, 7) == 3
assert subtract(5, 5) == 0
assert subtract(7, 10) == -3


def test_exponentiation():
assert exponentiate(2, 3) == 8
assert exponentiate(5, 0) == 1
assert exponentiate(3, -2) == 1 / 9


def test_square_root():
assert square_root(4) == 2
assert square_root(25) == 5
assert square_root(9) == 3
assert square_root(9) == 3