Skip to content
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
123 changes: 110 additions & 13 deletions refactoring.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
"$$"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -113,13 +122,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = (1, 1)\n",
"b = (4, 5)\n",
Expand Down Expand Up @@ -159,7 +179,12 @@
},
"outputs": [],
"source": [
"# YOUR CODE HERE"
"def manhattan(a, b):\n",
" d_x = b[0] - a[0]\n",
" d_y = b[1] - a[1]\n",
"\n",
" distance = d_x + d_y\n",
" return distance"
]
},
{
Expand All @@ -171,9 +196,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = (1, 1)\n",
"b = (4, 5)\n",
Expand Down Expand Up @@ -204,13 +240,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from utils.distances import manhattan\n",
"\n",
Expand All @@ -226,7 +273,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -244,9 +291,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform linux -- Python 3.12.9, pytest-8.3.4, pluggy-1.5.0 -- /home/bariscan/.pyenv/versions/3.12.9/envs/workintech/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /home/bariscan/code/Workintech/data-distances/tests\n",
"plugins: typeguard-4.4.2, dash-4.0.0, anyio-4.8.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 2 items\n",
"\n",
"test_manhattan_from_notebook.py::TestManhattanFromNotebook::test_manhattan \u001b[32mPASSED\u001b[0m\u001b[32m [ 50%]\u001b[0m\n",
"test_manhattan_from_notebook.py::TestManhattanFromNotebook::test_manhattan_reverse \u001b[32mPASSED\u001b[0m\u001b[32m [100%]\u001b[0m\n",
"\n",
"\u001b[32m============================== \u001b[32m\u001b[1m2 passed\u001b[0m\u001b[32m in 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\n",
"\n",
"\n",
"💯 You can commit your code:\n",
"\n",
"\u001b[1;32mgit\u001b[39m add tests/manhattan_from_notebook.pickle\n",
"\n",
"\u001b[32mgit\u001b[39m commit -m \u001b[33m'Completed manhattan_from_notebook step'\u001b[39m\n",
"\n",
"\u001b[32mgit\u001b[39m push origin master\n",
"\n"
]
}
],
"source": [
"print(result.check())"
]
Expand All @@ -266,9 +342,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Distance between a and b: 7\n",
"Distance between b and a: 7\n"
]
}
],
"source": [
"print(\"Distance between a and b:\", manhattan(a,b))\n",
"print(\"Distance between b and a:\", manhattan(b,a))"
Expand Down Expand Up @@ -778,9 +863,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "workintech",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down
Binary file added tests/manhattan_from_notebook.pickle
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/test_euclidean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from utils.distances import euclidean

def test_euclidean():
# Temel senaryolar
assert euclidean((0, 0), (0, 0)) == 0
assert euclidean((0, 0), (3, 4)) == 5 # 3-4-5 üçgeni
assert euclidean((0, 0), (1, 0)) == 1

# Negatif değer senaryoları
assert euclidean((0, 0), (-3, -4)) == 5
assert euclidean((3, 4), (0, 0)) == 5
4 changes: 0 additions & 4 deletions tests/test_manhattan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ def test_manhattan():
assert manhattan((0, 0), (0, 0)) == 0
assert manhattan((0, 0), (1, 1)) == 2
assert manhattan((0, 0), (1, 0)) == 1
assert manhattan((0, 0), (0, 1)) == 1
assert manhattan((0, 0), (-1, 0)) == 1
assert manhattan((0, 0), (0, -1)) == 1
assert manhattan((0, 0), (-1, -1)) == 2
assert manhattan((0, 0), (1, -1)) == 2
assert manhattan((0, 0), (-1, 1)) == 2
16 changes: 15 additions & 1 deletion utils/distances.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
pass # YOUR CODE HERE
def minkowski(a, b, p):
d_x = b[0] - a[0]
d_y = b[1] - a[1]

# Genel Minkowski formülü: (|dx|^p + |dy|^p)^(1/p)
distance = (abs(d_x)**p + abs(d_y)**p)**(1/p)
return distance

def manhattan(a, b):
# p=1 durumu
return minkowski(a, b, 1)

def euclidean(a, b):
# p=2 durumu
return minkowski(a, b, 2)